14287: Add GOPATH/bin to PATH.
[arvados.git] / apps / workbench / test / integration / application_layout_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'integration_helper'
6 require 'config_validators'
7
8 class ApplicationLayoutTest < ActionDispatch::IntegrationTest
9   # These tests don't do state-changing API calls. Save some time by
10   # skipping the database reset.
11   reset_api_fixtures :after_each_test, false
12   reset_api_fixtures :after_suite, true
13
14   setup do
15     need_javascript
16   end
17
18   def verify_homepage user, invited, has_profile
19     profile_config = Rails.configuration.user_profile_form_fields
20
21     if !user
22       assert page.has_text?('Please log in'), 'Not found text - Please log in'
23       assert page.has_text?('The "Log in" button below will show you a Google sign-in page'), 'Not found text - google sign in page'
24       assert page.has_no_text?('My projects'), 'Found text - My projects'
25       assert page.has_link?("Log in to #{Rails.configuration.site_name}"), 'Not found text - log in to'
26     elsif user['is_active']
27       if profile_config && !has_profile
28         assert page.has_text?('Save profile'), 'No text - Save profile'
29       else
30         assert page.has_link?("Projects"), 'Not found link - Projects'
31         page.find("#projects-menu").click
32         assert_selector 'a', text: 'Search all projects'
33         assert_no_selector 'a', text: 'Browse public projects'
34         assert_selector 'a', text: 'Add a new project'
35         assert_selector 'li[class="dropdown-header"]', text: 'My projects'
36       end
37     elsif invited
38       assert page.has_text?('Please check the box below to indicate that you have read and accepted the user agreement'), 'Not found text - Please check the box below . . .'
39     else
40       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
41     end
42
43     within('.navbar-fixed-top') do
44       if !user
45         assert_text Rails.configuration.site_name.downcase
46         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
47         assert page.has_link?('Log in'), 'Not found link - Log in'
48       else
49         # my account menu
50         assert_selector 'a', text: Rails.configuration.site_name.downcase
51         assert(page.has_link?("notifications-menu"), 'no user menu')
52         page.find("#notifications-menu").click
53         within('.dropdown-menu') do
54           if user['is_active']
55             assert page.has_no_link?('Not active'), 'Found link - Not active'
56             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
57
58             assert_selector "a[href=\"/projects/#{user['uuid']}\"]", text: 'Home project'
59             assert_selector "a[href=\"/users/#{user['uuid']}/virtual_machines\"]", text: 'Virtual machines'
60             assert_selector "a[href=\"/repositories\"]", text: 'Repositories'
61             assert_selector "a[href=\"/current_token\"]", text: 'Current token'
62             assert_selector "a[href=\"/users/#{user['uuid']}/ssh_keys\"]", text: 'SSH keys'
63
64             if profile_config
65               assert_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
66             else
67               assert_no_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
68             end
69           else
70             assert_no_selector 'a', text: 'Home project'
71             assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
72             assert page.has_no_link?('Repositories'), 'Found link - Repositories'
73             assert page.has_no_link?('Current token'), 'Found link - Current token'
74             assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
75             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
76           end
77           assert page.has_link?('Log out'), 'No link - Log out'
78         end
79       end
80     end
81   end
82
83   # test the help menu
84   def check_help_menu
85     within('.navbar-fixed-top') do
86       page.find("#arv-help").click
87       within('.dropdown-menu') do
88         assert_no_selector 'a', text:'Getting Started ...'
89         assert_selector 'a', text:'Public Pipelines and Data sets'
90         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
91         assert page.has_link?('API Reference'), 'No link - API Reference'
92         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
93         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
94         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
95         # Version info and Report a problem are tested in "report_issue_test.rb"
96       end
97     end
98   end
99
100   def verify_system_menu user
101     if user && user['is_admin']
102       assert page.has_link?('system-menu'), 'No link - system menu'
103       within('.navbar-fixed-top') do
104         page.find("#system-menu").click
105         within('.dropdown-menu') do
106           assert page.has_text?('Groups'), 'No text - Groups'
107           assert page.has_link?('Repositories'), 'No link - Repositories'
108           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
109           assert page.has_link?('SSH keys'), 'No link - SSH keys'
110           assert page.has_link?('API tokens'), 'No link - API tokens'
111           find('a', text: 'Users').click
112         end
113       end
114       assert page.has_text? 'Add a new user'
115     else
116       assert page.has_no_link?('system-menu'), 'Found link - system menu'
117     end
118   end
119
120   [
121     [nil, nil, false, false],
122     ['inactive', api_fixture('users')['inactive'], true, false],
123     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
124     ['active', api_fixture('users')['active'], true, true],
125     ['admin', api_fixture('users')['admin'], true, true],
126     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
127     ['active_no_prefs_profile_no_getting_started_shown',
128         api_fixture('users')['active_no_prefs_profile_no_getting_started_shown'], true, false],
129   ].each do |token, user, invited, has_profile|
130
131     test "visit home page for user #{token}" do
132       if !token
133         visit ('/')
134       else
135         visit page_with_token(token)
136       end
137
138       check_help_menu
139       verify_homepage user, invited, has_profile
140       verify_system_menu user
141     end
142   end
143
144   [
145     [false, false],
146     ['http://wb2.example.org//', false],
147     ['ftp://wb2.example.org', false],
148     ['wb2.example.org', false],
149     ['http://wb2.example.org', true],
150     ['https://wb2.example.org', true],
151     ['http://wb2.example.org/', true],
152     ['https://wb2.example.org/', true],
153   ].each do |wb2_url_config, wb2_menu_appear|
154     test "workbench2_url=#{wb2_url_config} should#{wb2_menu_appear ? '' : ' not'} show WB2 menu" do
155       Rails.configuration.workbench2_url = wb2_url_config
156       assert_equal wb2_menu_appear, ConfigValidators::validate_wb2_url_config()
157
158       visit page_with_token('active')
159       within('.navbar-fixed-top') do
160         page.find("#notifications-menu").click
161         within('.dropdown-menu') do
162           assert_equal wb2_menu_appear, page.has_text?('Go to Workbench 2')
163         end
164       end
165     end
166   end
167
168   [
169     ['active', true],
170     ['active_with_prefs_profile_no_getting_started_shown', false],
171   ].each do |token, getting_started_shown|
172     test "getting started help menu item #{getting_started_shown}" do
173       Rails.configuration.enable_getting_started_popup = true
174
175       visit page_with_token(token)
176
177       if getting_started_shown
178         within '.navbar-fixed-top' do
179           find('.help-menu > a').click
180           find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
181         end
182       end
183
184       within '.modal-content' do
185         assert_text 'Getting Started'
186         assert_selector 'button:not([disabled])', text: 'Next'
187         assert_no_selector 'button:not([disabled])', text: 'Prev'
188
189         # Use Next button to enable Prev button
190         click_button 'Next'
191         assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
192         click_button 'Prev'
193         assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
194
195         # Click Next until last page is reached and verify that it is disabled
196         (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
197           click_button 'Next'
198           begin
199             find('button:not([disabled])', text: 'Next')
200           rescue => e
201             break
202           end
203         end
204         assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
205         assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
206         click_button 'Prev'
207         assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
208
209         first('button', text: 'x').click
210       end
211       assert_text 'Recent pipelines and processes' # seeing dashboard now
212     end
213   end
214
215   test "test arvados_public_data_doc_url config unset" do
216     Rails.configuration.arvados_public_data_doc_url = false
217
218     visit page_with_token('active')
219     within '.navbar-fixed-top' do
220       find('.help-menu > a').click
221
222       assert_no_selector 'a', text:'Public Pipelines and Data sets'
223       assert_no_selector 'a', text:'Getting Started ...'
224
225       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
226       assert page.has_link?('API Reference'), 'No link - API Reference'
227       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
228       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
229       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
230     end
231   end
232
233   test "no SSH public key notification when shell_in_a_box_url is configured" do
234     Rails.configuration.shell_in_a_box_url = 'example.com'
235     visit page_with_token('job_reader')
236     click_link 'notifications-menu'
237     assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
238     assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
239   end
240
241    [
242     ['Repositories', nil, 'active/crunchdispatchtest'],
243     ['Virtual machines', nil, 'testvm.shell'],
244     ['SSH keys', nil, 'public_key'],
245     ['Links', nil, 'link_class'],
246     ['Groups', nil, 'All users'],
247     ['Compute nodes', nil, 'ping_secret'],
248     ['Keep services', nil, 'service_ssl_flag'],
249     ['Keep disks', nil, 'bytes_free'],
250   ].each do |page_name, add_button_text, look_for|
251     test "test system menu #{page_name} link" do
252       visit page_with_token('admin')
253       within('.navbar-fixed-top') do
254         page.find("#system-menu").click
255         within('.dropdown-menu') do
256           assert_selector 'a', text: page_name
257           find('a', text: page_name).click
258         end
259       end
260
261       # click the add button if it exists
262       if add_button_text
263         assert_selector 'button', text: "Add a new #{add_button_text}"
264         find('button', text: "Add a new #{add_button_text}").click
265       else
266         assert_no_selector 'button', text:"Add a new"
267       end
268
269       # look for unique property in the current page
270       assert_text look_for
271     end
272   end
273
274   [
275     ['active', false],
276     ['admin', true],
277   ].each do |token, is_admin|
278     test "visit dashboard as #{token}" do
279       visit page_with_token(token)
280
281       assert_text 'Recent pipelines and processes' # seeing dashboard now
282       within('.recent-processes-actions') do
283         assert page.has_link?('Run a process')
284         assert page.has_link?('All processes')
285       end
286
287       within('.recent-processes') do
288
289         within('.row-zzzzz-xvhdp-cr4runningcntnr') do
290           assert_text 'running'
291         end
292
293         assert_text 'zzzzz-d1hrv-twodonepipeline'
294         within('.row-zzzzz-d1hrv-twodonepipeline')do
295           assert_text 'No output'
296         end
297
298         assert_text 'completed container request'
299         within('.row-zzzzz-xvhdp-cr4completedctr')do
300           assert page.has_link? 'foo_file'
301         end
302       end
303
304       within('.compute-node-actions') do
305         if is_admin
306           assert page.has_link?('All nodes')
307         else
308           assert page.has_no_link?('All nodes')
309         end
310       end
311
312       within('.compute-node-summary-pane') do
313         click_link 'Details'
314         assert_text 'compute0'
315       end
316     end
317   end
318 end