Fix 2.4.2 upgrade notes formatting refs #19330
[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?('If you have never used Arvados Workbench before'), 'Not found text - If you have never'
24       assert page.has_no_text?('My projects'), 'Found text - My projects'
25       assert page.has_link?("Log in"), 'Not found text - Log in'
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       Rails.configuration.Users.AnonymousUserToken = ""
133       if !token
134         visit ('/')
135       else
136         visit page_with_token(token)
137       end
138
139       check_help_menu
140       verify_homepage user, invited, has_profile
141       verify_system_menu user
142     end
143   end
144
145   [
146     ["", false],
147     ['http://wb2.example.org//', false],
148     ['ftp://wb2.example.org', false],
149     ['wb2.example.org', false],
150     ['http://wb2.example.org', true],
151     ['https://wb2.example.org', true],
152     ['http://wb2.example.org/', true],
153     ['https://wb2.example.org/', true],
154   ].each do |wb2_url_config, wb2_menu_appear|
155     test "workbench2_url=#{wb2_url_config} should#{wb2_menu_appear ? '' : ' not'} show WB2 menu" do
156       Rails.configuration.Services.Workbench2.ExternalURL = URI(wb2_url_config)
157       if !wb2_menu_appear and !wb2_url_config.empty?
158         assert_raises RuntimeError do
159           ConfigValidators.validate_wb2_url_config()
160         end
161         Rails.configuration.Services.Workbench2.ExternalURL = URI("")
162       end
163
164       visit page_with_token('active')
165       within('.navbar-fixed-top') do
166         page.find("#notifications-menu").click
167         within('.dropdown-menu') do
168           assert_equal wb2_menu_appear, page.has_text?('Go to Workbench 2')
169         end
170       end
171     end
172   end
173
174   [
175     ['active', true],
176     ['active_with_prefs_profile_no_getting_started_shown', false],
177   ].each do |token, getting_started_shown|
178     test "getting started help menu item #{getting_started_shown}" do
179       Rails.configuration.Workbench.EnableGettingStartedPopup = true
180
181       visit page_with_token(token)
182
183       if getting_started_shown
184         within '.navbar-fixed-top' do
185           find('.help-menu > a').click
186           find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
187         end
188       end
189
190       within '.modal-content' do
191         assert_text 'Getting Started'
192         assert_selector 'button:not([disabled])', text: 'Next'
193         assert_no_selector 'button:not([disabled])', text: 'Prev'
194
195         # Use Next button to enable Prev button
196         click_button 'Next'
197         assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
198         click_button 'Prev'
199         assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
200
201         # Click Next until last page is reached and verify that it is disabled
202         (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
203           click_button 'Next'
204           begin
205             find('button:not([disabled])', text: 'Next')
206           rescue => e
207             break
208           end
209         end
210         assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
211         assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
212         click_button 'Prev'
213         assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
214
215         first('button', text: 'x').click
216       end
217       assert_text 'Recent processes' # seeing dashboard now
218     end
219   end
220
221   test "test arvados_public_data_doc_url config unset" do
222     Rails.configuration.Workbench.ArvadosPublicDataDocURL = ""
223
224     visit page_with_token('active')
225     within '.navbar-fixed-top' do
226       find('.help-menu > a').click
227
228       assert_no_selector 'a', text:'Public Pipelines and Data sets'
229       assert_no_selector 'a', text:'Getting Started ...'
230
231       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
232       assert page.has_link?('API Reference'), 'No link - API Reference'
233       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
234       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
235       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
236     end
237   end
238
239   test "no SSH public key notification when shell_in_a_box_url is configured" do
240     Rails.configuration.Services.WebShell.ExternalURL = URI('http://example.com')
241     Rails.configuration.Users.AnonymousUserToken = ""
242     visit page_with_token('job_reader')
243     click_link 'notifications-menu'
244     assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
245     assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
246   end
247
248    [
249     ['Repositories', nil, 'active/crunchdispatchtest'],
250     ['Virtual machines', nil, 'testvm.shell'],
251     ['SSH keys', nil, 'public_key'],
252     ['Links', nil, 'link_class'],
253     ['Groups', nil, 'All users'],
254     ['Keep services', nil, 'service_ssl_flag'],
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 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     end
309   end
310 end