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 page.has_no_link? ('Not active')
51 page.has_no_link? ('Sign agreements')
52 page.has_link? ('Manage account')
55 page.has_link? ('Manage profile')
57 page.has_no_link? ('Manage profile')
60 page.has_link? ('Log out')
68 if user && user['is_active']
70 check_system_menu user
72 # test manage account page
73 check_manage_account_page user
82 within('.navbar-fixed-top') do
83 page.find("#arv-help").click
84 within('.dropdown-menu') do
85 assert page.has_link? 'Tutorials and User guide'
86 assert page.has_link? 'API Reference'
87 assert page.has_link? 'SDK Reference'
92 # test the system menu
93 def check_system_menu user
94 if user && user['is_active']
95 look_for_add_new = nil
96 within('.navbar-fixed-top') do
97 page.find("#system-menu").click
99 within('.dropdown-menu') do
100 assert page.has_text? 'Groups'
101 assert page.has_link? 'Repositories'
102 assert page.has_link? 'Virtual machines'
103 assert page.has_link? 'SSH keys'
104 assert page.has_link? 'API tokens'
105 find('a', text: 'Users').click
106 look_for_add_new = 'Add a new user'
109 within('.dropdown-menu') do
110 assert page.has_no_text? 'Users'
111 assert page.has_no_link? 'Repositories'
112 assert page.has_no_link? 'Virtual machines'
113 assert page.has_no_link? 'SSH keys'
114 assert page.has_no_link? 'API tokens'
116 find('a', text: 'Groups').click
117 look_for_add_new = 'Add a new group'
122 assert page.has_text? look_for_add_new
125 assert page.has_no_link? '#system-menu'
129 # test manage_account page
130 def check_manage_account_page user
131 within('.navbar-fixed-top') do
132 find('a', text: "#{user['email']}").click
133 within('.dropdown-menu') do
134 find('a', text: 'Manage account').click
138 # now in manage account page
139 assert page.has_link? 'Virtual Machines'
140 assert page.has_link? 'Repositories'
141 assert page.has_link? 'SSH Keys'
142 assert page.has_link? 'Current Token'
144 assert page.has_text? 'The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'
146 click_link 'Add new SSH key'
148 within '.modal-content' do
149 assert page.has_text? 'Public Key'
150 assert page.has_button? 'Cancel'
151 assert page.has_button? 'Submit'
153 page.find_field('public_key').set 'first test with an incorrect ssh key value'
154 click_button 'Submit'
155 assert page.has_text? 'Public key does not appear to be a valid ssh-rsa or dsa public key'
157 public_key_str = api_fixture('authorized_keys')['active']['public_key']
158 page.find_field('public_key').set public_key_str
159 page.find_field('name').set 'added_in_test'
160 click_button 'Submit'
161 assert page.has_text? 'Public key already exists in the database, use a different key.'
163 new_key = SSHKey.generate
164 page.find_field('public_key').set new_key.ssh_public_key
165 page.find_field('name').set 'added_in_test'
166 click_button 'Submit'
169 # key must be added. look for it in the refreshed page
170 assert page.has_text? 'added_in_test'
173 # Check manage profile page and add missing profile to the user
175 assert page.has_no_text? 'My projects'
176 assert page.has_no_text? 'Projects shared with me'
178 assert page.has_text? 'Profile'
179 assert page.has_text? 'First name'
180 assert page.has_text? 'Last name'
181 assert page.has_text? 'Identity URL'
182 assert page.has_text? 'Email'
183 assert page.has_text? user['email']
185 # Using the default profile which has message and one required field
187 # Save profile without filling in the required field. Expect to be back in this profile page again
188 click_button "Save profile"
189 assert page.has_text? 'Profile'
190 assert page.has_text? 'First name'
191 assert page.has_text? 'Last name'
192 assert page.has_text? 'Save profile'
194 # This time fill in required field and then save. Expect to go to requested page after that.
195 profile_config = Rails.configuration.user_profile_form_fields
197 required_field_title = ''
198 required_field_key = ''
199 profile_config.andand.each do |entry|
201 profile_message = entry['message']
204 required_field_key = entry['key']
205 required_field_title = entry['form_field_title']
210 assert page.has_text? profile_message
211 assert page.has_text? required_field_title
212 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
214 click_button "Save profile"
216 # profile saved and in home page now
217 assert page.has_text? 'My projects'
218 assert page.has_text? 'Projects shared with me'
221 # test the search box
222 def check_search_box user
224 # let's search for a valid uuid
225 within('.navbar-fixed-top') do
226 page.find_field('search').set user['uuid']
227 page.find('.glyphicon-search').click
230 # we should now be in the user's page as a result of search
231 assert page.has_text? user['first_name']
233 # let's search again for an invalid valid uuid
234 within('.navbar-fixed-top') do
235 search_for = user['uuid']
237 page.find_field('search').set search_for
238 page.find('.glyphicon-search').click
241 # we should see 'not found' error page
242 assert page.has_text? 'Not Found'
244 # let's search for the anonymously accessible project
245 publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
247 within('.navbar-fixed-top') do
248 # search again for the anonymously accessible project
249 page.find_field('search').set publicly_accessible_project['name'][0,10]
250 page.find('.glyphicon-search').click
253 within '.modal-content' do
254 assert page.has_text? 'All projects'
255 assert page.has_text? 'Search'
256 assert page.has_text? 'Cancel'
257 assert_selector('div', text: publicly_accessible_project['name'])
258 find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
263 # seeing "Unrestricted public data" now
264 assert page.has_text? publicly_accessible_project['name']
265 assert page.has_text? publicly_accessible_project['description']
270 [nil, nil, false, false],
271 ['inactive', api_fixture('users')['inactive'], true, false],
272 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
273 ['active', api_fixture('users')['active'], true, true],
274 ['admin', api_fixture('users')['admin'], true, true],
275 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
276 ].each do |token, user, invited, has_profile|
277 test "visit home page when profile is configured for user #{token}" do
278 # Our test config enabled profile by default. So, no need to update config
282 visit page_with_token(token)
285 verify_homepage_with_profile user, invited, has_profile
290 [nil, nil, false, false],
291 ['inactive', api_fixture('users')['inactive'], true, false],
292 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
293 ['active', api_fixture('users')['active'], true, true],
294 ['admin', api_fixture('users')['admin'], true, true],
295 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
296 ].each do |token, user, invited, has_profile|
297 test "visit home page when profile not configured for user #{token}" do
298 Rails.configuration.user_profile_form_fields = false
303 visit page_with_token(token)
306 verify_homepage_with_profile user, invited, has_profile