14717: Fixups since tests now use config.yml
[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.Workbench.UserProfileFormFields
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.Workbench.SiteName}"), '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.Workbench.SiteName.downcase
46         assert_no_selector 'a', text: Rails.configuration.Workbench.SiteName.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.Workbench.SiteName.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],
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.Services.Workbench2.ExternalURL = URI(wb2_url_config)
156       if !wb2_menu_appear and !wb2_url_config.empty?
157         assert_raises RuntimeError do
158           ConfigValidators.validate_wb2_url_config()
159         end
160         Rails.configuration.Services.Workbench2.ExternalURL = URI("")
161       end
162
163       visit page_with_token('active')
164       within('.navbar-fixed-top') do
165         page.find("#notifications-menu").click
166         within('.dropdown-menu') do
167           assert_equal wb2_menu_appear, page.has_text?('Go to Workbench 2')
168         end
169       end
170     end
171   end
172
173   [
174     ['active', true],
175     ['active_with_prefs_profile_no_getting_started_shown', false],
176   ].each do |token, getting_started_shown|
177     test "getting started help menu item #{getting_started_shown}" do
178       Rails.configuration.Workbench.EnableGettingStartedPopup = true
179
180       visit page_with_token(token)
181
182       if getting_started_shown
183         within '.navbar-fixed-top' do
184           find('.help-menu > a').click
185           find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
186         end
187       end
188
189       within '.modal-content' do
190         assert_text 'Getting Started'
191         assert_selector 'button:not([disabled])', text: 'Next'
192         assert_no_selector 'button:not([disabled])', text: 'Prev'
193
194         # Use Next button to enable Prev button
195         click_button 'Next'
196         assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
197         click_button 'Prev'
198         assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
199
200         # Click Next until last page is reached and verify that it is disabled
201         (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
202           click_button 'Next'
203           begin
204             find('button:not([disabled])', text: 'Next')
205           rescue => e
206             break
207           end
208         end
209         assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
210         assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
211         click_button 'Prev'
212         assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
213
214         first('button', text: 'x').click
215       end
216       assert_text 'Recent pipelines and processes' # seeing dashboard now
217     end
218   end
219
220   test "test arvados_public_data_doc_url config unset" do
221     Rails.configuration.Workbench.ArvadosPublicDataDocURL = ""
222
223     visit page_with_token('active')
224     within '.navbar-fixed-top' do
225       find('.help-menu > a').click
226
227       assert_no_selector 'a', text:'Public Pipelines and Data sets'
228       assert_no_selector 'a', text:'Getting Started ...'
229
230       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
231       assert page.has_link?('API Reference'), 'No link - API Reference'
232       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
233       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
234       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
235     end
236   end
237
238   test "no SSH public key notification when shell_in_a_box_url is configured" do
239     Rails.configuration.Services.WebShell.ExternalURL = URI('http://example.com')
240     visit page_with_token('job_reader')
241     click_link 'notifications-menu'
242     assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
243     assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
244   end
245
246    [
247     ['Repositories', nil, 'active/crunchdispatchtest'],
248     ['Virtual machines', nil, 'testvm.shell'],
249     ['SSH keys', nil, 'public_key'],
250     ['Links', nil, 'link_class'],
251     ['Groups', nil, 'All users'],
252     ['Compute nodes', nil, 'ping_secret'],
253     ['Keep services', nil, 'service_ssl_flag'],
254     ['Keep disks', nil, 'bytes_free'],
255   ].each do |page_name, add_button_text, look_for|
256     test "test system menu #{page_name} link" do
257       visit page_with_token('admin')
258       within('.navbar-fixed-top') do
259         page.find("#system-menu").click
260         within('.dropdown-menu') do
261           assert_selector 'a', text: page_name
262           find('a', text: page_name).click
263         end
264       end
265
266       # click the add button if it exists
267       if add_button_text
268         assert_selector 'button', text: "Add a new #{add_button_text}"
269         find('button', text: "Add a new #{add_button_text}").click
270       else
271         assert_no_selector 'button', text:"Add a new"
272       end
273
274       # look for unique property in the current page
275       assert_text look_for
276     end
277   end
278
279   [
280     ['active', false],
281     ['admin', true],
282   ].each do |token, is_admin|
283     test "visit dashboard as #{token}" do
284       visit page_with_token(token)
285
286       assert_text 'Recent pipelines and processes' # seeing dashboard now
287       within('.recent-processes-actions') do
288         assert page.has_link?('Run a process')
289         assert page.has_link?('All processes')
290       end
291
292       within('.recent-processes') do
293
294         within('.row-zzzzz-xvhdp-cr4runningcntnr') do
295           assert_text 'running'
296         end
297
298         assert_text 'zzzzz-d1hrv-twodonepipeline'
299         within('.row-zzzzz-d1hrv-twodonepipeline')do
300           assert_text 'No output'
301         end
302
303         assert_text 'completed container request'
304         within('.row-zzzzz-xvhdp-cr4completedctr')do
305           assert page.has_link? 'foo_file'
306         end
307       end
308
309       within('.compute-node-actions') do
310         if is_admin
311           assert page.has_link?('All nodes')
312         else
313           assert page.has_no_link?('All nodes')
314         end
315       end
316
317       within('.compute-node-summary-pane') do
318         click_link 'Details'
319         assert_text 'compute0'
320       end
321     end
322   end
323 end