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