1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
6 require 'config_validators'
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
18 def verify_homepage user, invited, has_profile
19 profile_config = Rails.configuration.Workbench.UserProfileFormFields
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'
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'
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 . . .'
40 assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
43 within('.navbar-fixed-top') do
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'
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
55 assert page.has_no_link?('Not active'), 'Found link - Not active'
56 assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
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'
65 assert_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
67 assert_no_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
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'
77 assert page.has_link?('Log out'), 'No link - Log out'
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"
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
114 assert page.has_text? 'Add a new user'
116 assert page.has_no_link?('system-menu'), 'Found link - system menu'
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|
131 test "visit home page for user #{token}" do
132 Rails.configuration.Users.AnonymousUserToken = ""
136 visit page_with_token(token)
140 verify_homepage user, invited, has_profile
141 verify_system_menu user
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()
161 Rails.configuration.Services.Workbench2.ExternalURL = URI("")
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')
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
181 visit page_with_token(token)
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
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'
195 # Use Next button to enable Prev button
197 assert_selector 'button:not([disabled])', text: 'Prev' # Prev button is now enabled
199 assert_no_selector 'button:not([disabled])', text: 'Prev' # Prev button is again disabled
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
205 find('button:not([disabled])', text: 'Next')
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
213 assert_selector 'button:not([disabled])', text: 'Next' # Next button is now enabled
215 first('button', text: 'x').click
217 assert_text 'Recent processes' # seeing dashboard now
221 test "test arvados_public_data_doc_url config unset" do
222 Rails.configuration.Workbench.ArvadosPublicDataDocURL = ""
224 visit page_with_token('active')
225 within '.navbar-fixed-top' do
226 find('.help-menu > a').click
228 assert_no_selector 'a', text:'Public Pipelines and Data sets'
229 assert_no_selector 'a', text:'Getting Started ...'
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'
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'
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 ['Compute nodes', nil, 'ping_secret'],
255 ['Keep services', nil, 'service_ssl_flag'],
256 ['Keep disks', nil, 'bytes_free'],
257 ].each do |page_name, add_button_text, look_for|
258 test "test system menu #{page_name} link" do
259 visit page_with_token('admin')
260 within('.navbar-fixed-top') do
261 page.find("#system-menu").click
262 within('.dropdown-menu') do
263 assert_selector 'a', text: page_name
264 find('a', text: page_name).click
268 # click the add button if it exists
270 assert_selector 'button', text: "Add a new #{add_button_text}"
271 find('button', text: "Add a new #{add_button_text}").click
273 assert_no_selector 'button', text:"Add a new"
276 # look for unique property in the current page
284 ].each do |token, is_admin|
285 test "visit dashboard as #{token}" do
286 visit page_with_token(token)
288 assert_text 'Recent processes' # seeing dashboard now
289 within('.recent-processes-actions') do
290 assert page.has_link?('Run a process')
291 assert page.has_link?('All processes')
294 within('.recent-processes') do
296 within('.row-zzzzz-xvhdp-cr4runningcntnr') do
297 assert_text 'running'
300 assert_text 'zzzzz-d1hrv-twodonepipeline'
301 within('.row-zzzzz-d1hrv-twodonepipeline')do
302 assert_text 'No output'
305 assert_text 'completed container request'
306 within('.row-zzzzz-xvhdp-cr4completedctr')do
307 assert page.has_link? 'foo_file'