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
135 visit page_with_token(token)
139 verify_homepage user, invited, has_profile
140 verify_system_menu user
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()
160 Rails.configuration.Services.Workbench2.ExternalURL = URI("")
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')
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
180 visit page_with_token(token)
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
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'
194 # Use Next button to enable Prev button
196 assert_selector 'button:not([disabled])', text: 'Prev' # Prev button is now enabled
198 assert_no_selector 'button:not([disabled])', text: 'Prev' # Prev button is again disabled
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
204 find('button:not([disabled])', text: 'Next')
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
212 assert_selector 'button:not([disabled])', text: 'Next' # Next button is now enabled
214 first('button', text: 'x').click
216 assert_text 'Recent pipelines and processes' # seeing dashboard now
220 test "test arvados_public_data_doc_url config unset" do
221 Rails.configuration.Workbench.ArvadosPublicDataDocURL = ""
223 visit page_with_token('active')
224 within '.navbar-fixed-top' do
225 find('.help-menu > a').click
227 assert_no_selector 'a', text:'Public Pipelines and Data sets'
228 assert_no_selector 'a', text:'Getting Started ...'
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'
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'
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
266 # click the add button if it exists
268 assert_selector 'button', text: "Add a new #{add_button_text}"
269 find('button', text: "Add a new #{add_button_text}").click
271 assert_no_selector 'button', text:"Add a new"
274 # look for unique property in the current page
282 ].each do |token, is_admin|
283 test "visit dashboard as #{token}" do
284 visit page_with_token(token)
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')
292 within('.recent-processes') do
294 within('.row-zzzzz-xvhdp-cr4runningcntnr') do
295 assert_text 'running'
298 assert_text 'zzzzz-d1hrv-twodonepipeline'
299 within('.row-zzzzz-d1hrv-twodonepipeline')do
300 assert_text 'No output'
303 assert_text 'completed container request'
304 within('.row-zzzzz-xvhdp-cr4completedctr')do
305 assert page.has_link? 'foo_file'
309 within('.compute-node-actions') do
311 assert page.has_link?('All nodes')
313 assert page.has_no_link?('All nodes')
317 within('.compute-node-summary-pane') do
319 assert_text 'compute0'