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'
23 assert page.has_text? 'The "Log in" button below will show you a Google sign-in page'
24 assert page.has_no_text? 'My projects'
25 assert page.has_link? "Log in to #{Rails.configuration.site_name}"
26 elsif profile_config && !has_profile && user['is_active']
28 elsif user['is_active']
29 assert page.has_text? 'My projects'
30 assert page.has_text? 'Projects shared with me'
31 assert page.has_no_text? 'Save profile'
33 assert page.has_text? 'Please check the box below to indicate that you have read and accepted the user agreement'
34 assert page.has_no_text? 'Save profile'
36 assert page.has_text? 'Your account is inactive'
37 assert page.has_no_text? 'Save profile'
40 within('.navbar-fixed-top') do
42 assert page.has_link? 'Log in'
45 assert page.has_link? "#{user['email']}"
46 find('a', text: "#{user['email']}").click
47 within('.dropdown-menu') do
49 assert page.has_no_link? ('Not active')
50 assert page.has_no_link? ('Sign agreements')
52 assert page.has_link? ('Manage account')
55 assert page.has_link? ('Manage profile')
57 assert page.has_no_link? ('Manage profile')
60 assert page.has_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'
72 assert page.has_link? 'API Reference'
73 assert page.has_link? 'SDK Reference'
74 assert page.has_link? 'Show version / debugging info'
75 assert page.has_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'
84 assert page.has_no_text? 'Report a problem'
85 assert page.has_text? 'Server version'
86 assert page.has_text? 'Server restarted at'
87 assert page.has_text? 'Workbench version'
88 assert page.has_text? 'Arvados base'
89 assert page.has_text? 'Additional info'
90 assert page.has_no_text? 'Found a problem?'
91 assert page.has_button? 'Close'
92 assert page.has_no_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'
106 assert page.has_no_text? 'Version / debugging info'
107 assert page.has_text? 'Server version'
108 assert page.has_text? 'Server restarted at'
109 assert page.has_text? 'Workbench version'
110 assert page.has_text? 'Arvados base'
111 assert page.has_text? 'Additional info'
112 assert page.has_text? 'Found a problem?'
113 assert page.has_no_button? 'Close'
114 assert page.has_button? 'Report issue'
115 assert page.has_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'
122 assert page.has_no_text? 'Version / debugging info'
125 def verify_system_menu user
126 if user && user['is_active']
127 look_for_add_new = nil
128 within('.navbar-fixed-top') do
129 page.find("#system-menu").click
131 within('.dropdown-menu') do
132 assert page.has_text? 'Groups'
133 assert page.has_link? 'Repositories'
134 assert page.has_link? 'Virtual machines'
135 assert page.has_link? 'SSH keys'
136 assert page.has_link? 'API tokens'
137 find('a', text: 'Users').click
138 look_for_add_new = 'Add a new user'
141 within('.dropdown-menu') do
142 assert page.has_no_text? 'Users'
143 assert page.has_no_link? 'Repositories'
144 assert page.has_no_link? 'Virtual machines'
145 assert page.has_no_link? 'SSH keys'
146 assert page.has_no_link? 'API tokens'
148 find('a', text: 'Groups').click
149 look_for_add_new = 'Add a new group'
154 assert page.has_text? look_for_add_new
157 assert page.has_no_link? '#system-menu'
161 # test manage_account page
162 def verify_manage_account user
163 if user && user['is_active']
164 within('.navbar-fixed-top') do
165 find('a', text: "#{user['email']}").click
166 within('.dropdown-menu') do
167 find('a', text: 'Manage account').click
171 # now in manage account page
172 assert page.has_text? 'Virtual Machines'
173 assert page.has_text? 'Repositories'
174 assert page.has_text? 'SSH Keys'
175 assert page.has_text? 'Current Token'
177 assert page.has_text? 'The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'
179 click_link 'Add new SSH key'
181 within '.modal-content' do
182 assert page.has_text? 'Public Key'
183 assert page.has_button? 'Cancel'
184 assert page.has_button? 'Submit'
186 page.find_field('public_key').set 'first test with an incorrect ssh key value'
187 click_button 'Submit'
188 assert page.has_text? 'Public key does not appear to be a valid ssh-rsa or dsa public key'
190 public_key_str = api_fixture('authorized_keys')['active']['public_key']
191 page.find_field('public_key').set public_key_str
192 page.find_field('name').set 'added_in_test'
193 click_button 'Submit'
194 assert page.has_text? 'Public key already exists in the database, use a different key.'
196 new_key = SSHKey.generate
197 page.find_field('public_key').set new_key.ssh_public_key
198 page.find_field('name').set 'added_in_test'
199 click_button 'Submit'
202 # key must be added. look for it in the refreshed page
203 assert page.has_text? 'added_in_test'
207 # Check manage profile page and add missing profile to the user
209 assert page.has_no_text? 'My projects'
210 assert page.has_no_text? 'Projects shared with me'
212 assert page.has_text? 'Profile'
213 assert page.has_text? 'First name'
214 assert page.has_text? 'Last name'
215 assert page.has_text? 'Identity URL'
216 assert page.has_text? 'Email'
217 assert page.has_text? user['email']
219 # Using the default profile which has message and one required field
221 # Save profile without filling in the required field. Expect to be back in this profile page again
222 click_button "Save profile"
223 assert page.has_text? 'Profile'
224 assert page.has_text? 'First name'
225 assert page.has_text? 'Last name'
226 assert page.has_text? 'Save profile'
228 # This time fill in required field and then save. Expect to go to requested page after that.
229 profile_message = Rails.configuration.user_profile_form_message
230 required_field_title = ''
231 required_field_key = ''
232 profile_config = Rails.configuration.user_profile_form_fields
233 profile_config.andand.each do |entry|
235 required_field_key = entry['key']
236 required_field_title = entry['form_field_title']
240 assert page.has_text? profile_message[0,25]
241 assert page.has_text? required_field_title
242 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
244 click_button "Save profile"
245 # profile saved and in profile page now with success
246 assert page.has_text? 'Thank you for filling in your profile'
247 click_button 'Access Arvados Workbench'
249 # profile saved and in home page now
250 assert page.has_text? 'My projects'
251 assert page.has_text? 'Projects shared with me'
254 # test the search box
255 def verify_search_box user
256 if user && user['is_active']
257 # let's search for a valid uuid
258 within('.navbar-fixed-top') do
259 page.find_field('search').set user['uuid']
260 page.find('.glyphicon-search').click
263 # we should now be in the user's page as a result of search
264 assert page.has_text? user['first_name']
266 # let's search again for an invalid valid uuid
267 within('.navbar-fixed-top') do
268 search_for = String.new user['uuid']
270 page.find_field('search').set search_for
271 page.find('.glyphicon-search').click
274 # we should see 'not found' error page
275 assert page.has_text? 'Not Found'
276 assert page.has_link? 'Report problem'
277 click_link 'Report problem'
278 within '.modal-content' do
279 assert page.has_text? 'Report a problem'
280 assert page.has_no_text? 'Version / debugging info'
281 assert page.has_text? 'Server version'
282 assert page.has_text? 'Server restarted at'
283 assert page.has_text? 'Found a problem?'
284 assert page.has_button? 'Report issue'
285 assert page.has_button? 'Cancel'
287 # enter a report text and click on report
288 page.find_field('report_issue_text').set 'my test report text'
289 click_button 'Report issue'
292 # let's search for the anonymously accessible project
293 publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
295 within('.navbar-fixed-top') do
296 # search again for the anonymously accessible project
297 page.find_field('search').set publicly_accessible_project['name'][0,10]
298 page.find('.glyphicon-search').click
301 within '.modal-content' do
302 assert page.has_text? 'All projects'
303 assert page.has_text? 'Search'
304 assert page.has_text? 'Cancel'
305 assert_selector('div', text: publicly_accessible_project['name'])
306 find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
311 # seeing "Unrestricted public data" now
312 assert page.has_text? publicly_accessible_project['name']
313 assert page.has_text? publicly_accessible_project['description']
318 [nil, nil, false, false],
319 ['inactive', api_fixture('users')['inactive'], true, false],
320 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
321 ['active', api_fixture('users')['active'], true, true],
322 ['admin', api_fixture('users')['admin'], true, true],
323 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
324 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
325 ].each do |token, user, invited, has_profile|
327 test "visit home page when profile is configured for user #{token}" do
328 # Our test config enabled profile by default. So, no need to update config
332 visit page_with_token(token)
335 verify_homepage_with_profile user, invited, has_profile
338 test "visit home page when profile not configured for user #{token}" do
339 Rails.configuration.user_profile_form_fields = false
344 visit page_with_token(token)
347 verify_homepage_with_profile user, invited, has_profile
350 test "check help for user #{token}" do
354 visit page_with_token(token)
363 ['active', api_fixture('users')['active'], true, true],
364 ['admin', api_fixture('users')['admin'], true, true],
365 ].each do |token, user|
367 test "test system menu for user #{token}" do
368 visit page_with_token(token)
369 verify_system_menu user
372 test "test manage account for user #{token}" do
373 visit page_with_token(token)
374 verify_manage_account user
377 test "test search for user #{token}" do
378 visit page_with_token(token)
379 verify_search_box user