1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class ApplicationLayoutTest < ActionDispatch::IntegrationTest
7 headless = Headless.new
9 Capybara.current_driver = :selenium
11 @user_profile_form_fields = Rails.configuration.user_profile_form_fields
15 Rails.configuration.user_profile_form_fields = @user_profile_form_fields
18 def verify_homepage_with_profile user, invited, has_profile
19 profile_config = Rails.configuration.user_profile_form_fields
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.site_name}"), 'Not found text - log in to'
26 elsif profile_config && !has_profile && user['is_active']
28 elsif user['is_active']
29 assert page.has_text?('My projects'), 'Not found text - My projects'
30 assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
31 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
33 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 . . .'
34 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
36 assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
37 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
40 within('.navbar-fixed-top') do
42 assert page.has_link?('Log in'), 'Not found link - Log in'
45 assert page.has_link?("#{user['email']}"), 'Not found link - email'
46 find('a', text: "#{user['email']}").click
47 within('.dropdown-menu') do
49 assert page.has_no_link?('Not active'), 'Found link - Not active'
50 assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
52 assert page.has_link?('Manage account'), 'No link - Manage account'
55 assert page.has_link?('Manage profile'), 'No link - Manage profile'
57 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
60 assert page.has_link?('Log out'), 'No link - Log out'
68 within('.navbar-fixed-top') do
69 page.find("#arv-help").click
70 within('.dropdown-menu') do
71 assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
72 assert page.has_link?('API Reference'), 'No link - API Reference'
73 assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
74 assert page.has_link?('Show version / debugging info'), 'No link - Show version / debugging info'
75 assert page.has_link?('Report a problem'), 'No link - Report a problem'
77 # check show version info link
78 click_link 'Show version / debugging info'
82 within '.modal-content' do
83 assert page.has_text?('Version / debugging info'), 'No text - Version / debugging info'
84 assert page.has_no_text?('Report a problem'), 'Found text - Report a problem'
85 assert page.has_text?('Server version'), 'No text - Server version'
86 assert page.has_text?('Server restarted at'), 'No text - Server restarted at'
87 assert page.has_text?('Workbench version'), 'No text - Workbench version'
88 assert page.has_text?('Arvados base'), 'No text - Arvados base'
89 assert page.has_text?('Additional info'), 'No text - Additional info'
90 assert page.has_no_text?('Found a problem?'), 'Found text - Found a problem'
91 assert page.has_button?('Close'), 'No button - Close'
92 assert page.has_no_button?('Report issue'), 'Found button - Report issue'
96 # check report issue link
97 within('.navbar-fixed-top') do
98 page.find("#arv-help").click
99 within('.dropdown-menu') do
100 click_link 'Report a problem'
104 within '.modal-content' do
105 assert page.has_text?('Report a problem'), 'No text - Report a problem'
106 assert page.has_no_text?('Version / debugging info'), 'Found text - Version / debugging info'
107 assert page.has_text?('Server version'), 'No text - Server version'
108 assert page.has_text?('Server restarted at'), 'No text - Server restarted at'
109 assert page.has_text?('Workbench version'), 'No text - Workbench version'
110 assert page.has_text?('Arvados base'), 'No text - Arvados base'
111 assert page.has_text?('Additional info'), 'No text - Additional info'
112 assert page.has_text?('Found a problem?'), 'No text - Found a problem'
113 assert page.has_no_button?('Close'), 'Found button - Close'
114 assert page.has_button?('Report issue'), 'No button - Report issue'
115 assert page.has_button?('Cancel'), 'No button - Cancel'
117 # enter a report text and click on report
118 page.find_field('report_issue_text').set 'my test report text'
119 click_button 'Report issue'
121 # ajax success updated button texts and added footer message
122 assert page.has_no_button?('Report issue'), 'Found button - Report issue'
123 assert page.has_no_button?('Cancel'), 'Found button - Cancel'
124 assert page.has_text?('Report sent'), 'No text - Report sent'
125 assert page.has_button?('Close'), 'No text - Close'
126 assert page.has_text?('Thanks for reporting this issue'), 'No text - Thanks for reporting this issue'
132 def verify_system_menu user
133 if user && user['is_active']
134 look_for_add_new = nil
135 within('.navbar-fixed-top') do
136 page.find("#system-menu").click
138 within('.dropdown-menu') do
139 assert page.has_text?('Groups'), 'No text - Groups'
140 assert page.has_link?('Repositories'), 'No link - Repositories'
141 assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
142 assert page.has_link?('SSH keys'), 'No link - SSH keys'
143 assert page.has_link?('API tokens'), 'No link - API tokens'
144 find('a', text: 'Users').click
145 look_for_add_new = 'Add a new user'
148 within('.dropdown-menu') do
149 assert page.has_no_text?('Users'), 'Found text - Users'
150 assert page.has_no_link?('Repositories'), 'Found link - Repositories'
151 assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
152 assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
153 assert page.has_no_link?('API tokens'), 'Found link - API tokens'
155 find('a', text: 'Groups').click
156 look_for_add_new = 'Add a new group'
161 assert page.has_text? look_for_add_new
164 assert page.has_no_link?('#system-menu'), 'Found link - system menu'
168 # test manage_account page
169 def verify_manage_account user
170 if user && user['is_active']
171 within('.navbar-fixed-top') do
172 find('a', text: "#{user['email']}").click
173 within('.dropdown-menu') do
174 find('a', text: 'Manage account').click
178 # now in manage account page
179 assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
180 assert page.has_text?('Repositories'), 'No text - Repositories'
181 assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
182 assert page.has_text?('Current Token'), 'No text - Current Token'
184 assert page.has_text?('The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'), 'No text - Arvados API token'
186 click_link 'Add new SSH key'
188 within '.modal-content' do
189 assert page.has_text?('Public Key'), 'No text - Public Key'
190 assert page.has_button?('Cancel'), 'No button - Cancel'
191 assert page.has_button?('Submit'), 'No button - Submit'
193 page.find_field('public_key').set 'first test with an incorrect ssh key value'
194 click_button 'Submit'
195 assert page.has_text?('Public key does not appear to be a valid ssh-rsa or dsa public key'), 'No text - Public key does not appear to be a valid'
197 public_key_str = api_fixture('authorized_keys')['active']['public_key']
198 page.find_field('public_key').set public_key_str
199 page.find_field('name').set 'added_in_test'
200 click_button 'Submit'
201 assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
203 new_key = SSHKey.generate
204 page.find_field('public_key').set new_key.ssh_public_key
205 page.find_field('name').set 'added_in_test'
206 click_button 'Submit'
209 # key must be added. look for it in the refreshed page
210 assert page.has_text?('added_in_test'), 'No text - added_in_test'
214 # Check manage profile page and add missing profile to the user
216 assert page.has_no_text?('My projects'), 'Found text - My projects'
217 assert page.has_no_text?('Projects shared with me'), 'Found text - Projects shared with me'
219 assert page.has_text?('Profile'), 'No text - Profile'
220 assert page.has_text?('First name'), 'No text - First name'
221 assert page.has_text?('Last name'), 'No text - Last name'
222 assert page.has_text?('Identity URL'), 'No text - Identity URL'
223 assert page.has_text?('Email'), 'No text - Email'
224 assert page.has_text?(user['email']), 'No text - user email'
226 # Using the default profile which has message and one required field
228 # Save profile without filling in the required field. Expect to be back in this profile page again
229 click_button "Save profile"
230 assert page.has_text?('Profile'), 'No text - Profile'
231 assert page.has_text?('First name'), 'No text - First name'
232 assert page.has_text?('Last name'), 'No text - Last name'
233 assert page.has_text?('Save profile'), 'No text - Save profile'
235 # This time fill in required field and then save. Expect to go to requested page after that.
236 profile_message = Rails.configuration.user_profile_form_message
237 required_field_title = ''
238 required_field_key = ''
239 profile_config = Rails.configuration.user_profile_form_fields
240 profile_config.andand.each do |entry|
242 required_field_key = entry['key']
243 required_field_title = entry['form_field_title']
247 assert page.has_text?(profile_message[0,25]), 'No text - configured profile message'
248 assert page.has_text?(required_field_title), 'No text - configured required field title'
249 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
251 click_button "Save profile"
252 # profile saved and in profile page now with success
253 assert page.has_text?('Thank you for filling in your profile'), 'No text - Thank you for filling'
254 click_button 'Access Arvados Workbench'
256 # profile saved and in home page now
257 assert page.has_text?('My projects'), 'No text - My projects'
258 assert page.has_text?('Projects shared with me'), 'No text - Projects shared with me'
261 # test the search box
262 def verify_search_box user
263 if user && user['is_active']
264 # let's search for a valid uuid
265 within('.navbar-fixed-top') do
266 page.find_field('search').set user['uuid']
267 page.find('.glyphicon-search').click
270 # we should now be in the user's page as a result of search
271 assert page.has_text?(user['first_name']), 'No text - user first name'
273 # let's search again for an invalid valid uuid
274 within('.navbar-fixed-top') do
275 search_for = String.new user['uuid']
277 page.find_field('search').set search_for
278 page.find('.glyphicon-search').click
281 # we should see 'not found' error page
282 assert page.has_text?('Not Found'), 'No text - Not Found'
283 assert page.has_link?('Report problem'), 'No text - Report problem'
284 click_link 'Report problem'
285 within '.modal-content' do
286 assert page.has_text?('Report a problem'), 'No text - Report a problem'
287 assert page.has_no_text?('Version / debugging info'), 'No text - Version / debugging info'
288 assert page.has_text?('Server version'), 'No text - Server version'
289 assert page.has_text?('Server restarted at'), 'No text - Server restarted at'
290 assert page.has_text?('Found a problem?'), 'No text - Found a problem'
291 assert page.has_button?('Report issue'), 'No button - Report issue'
292 assert page.has_button?('Cancel'), 'No button - Cancel'
294 # enter a report text and click on report
295 page.find_field('report_issue_text').set 'my test report text'
296 click_button 'Report issue'
298 # ajax success updated button texts and added footer message
299 assert page.has_no_button?('Report issue'), 'Found button - Report issue'
300 assert page.has_no_button?('Cancel'), 'Found button - Cancel'
301 assert page.has_text?('Report sent'), 'No text - Report sent'
302 assert page.has_button?('Close'), 'No text - Close'
303 assert page.has_text?('Thanks for reporting this issue'), 'No text - Thanks for reporting this issue'
308 # let's search for the anonymously accessible project
309 publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
311 within('.navbar-fixed-top') do
312 # search again for the anonymously accessible project
313 page.find_field('search').set publicly_accessible_project['name'][0,10]
314 page.find('.glyphicon-search').click
317 within '.modal-content' do
318 assert page.has_text?('All projects'), 'No text - All projects'
319 assert page.has_text?('Search'), 'No text - Search'
320 assert page.has_text?('Cancel'), 'No text - Cancel'
321 assert_selector('div', text: publicly_accessible_project['name'])
322 find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
327 # seeing "Unrestricted public data" now
328 assert page.has_text?(publicly_accessible_project['name']), 'No text - publicly accessible project name'
329 assert page.has_text?(publicly_accessible_project['description']), 'No text - publicly accessible project description'
334 [nil, nil, false, false],
335 ['inactive', api_fixture('users')['inactive'], true, false],
336 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
337 ['active', api_fixture('users')['active'], true, true],
338 ['admin', api_fixture('users')['admin'], true, true],
339 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
340 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
341 ].each do |token, user, invited, has_profile|
343 test "visit home page when profile is configured for user #{token}" do
344 # Our test config enabled profile by default. So, no need to update config
348 visit page_with_token(token)
351 verify_homepage_with_profile user, invited, has_profile
354 test "visit home page when profile not configured for user #{token}" do
355 Rails.configuration.user_profile_form_fields = false
360 visit page_with_token(token)
363 verify_homepage_with_profile user, invited, has_profile
366 test "check help for user #{token}" do
370 visit page_with_token(token)
379 ['active', api_fixture('users')['active'], true, true],
380 ['admin', api_fixture('users')['admin'], true, true],
381 ].each do |token, user|
383 test "test system menu for user #{token}" do
384 visit page_with_token(token)
385 verify_system_menu user
388 test "test manage account for user #{token}" do
389 visit page_with_token(token)
390 verify_manage_account user
393 test "test search for user #{token}" do
394 visit page_with_token(token)
395 verify_search_box user