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'
78 def verify_system_menu user
79 if user && user['is_active']
80 look_for_add_new = nil
81 within('.navbar-fixed-top') do
82 page.find("#system-menu").click
84 within('.dropdown-menu') do
85 assert page.has_text? 'Groups'
86 assert page.has_link? 'Repositories'
87 assert page.has_link? 'Virtual machines'
88 assert page.has_link? 'SSH keys'
89 assert page.has_link? 'API tokens'
90 find('a', text: 'Users').click
91 look_for_add_new = 'Add a new user'
94 within('.dropdown-menu') do
95 assert page.has_no_text? 'Users'
96 assert page.has_no_link? 'Repositories'
97 assert page.has_no_link? 'Virtual machines'
98 assert page.has_no_link? 'SSH keys'
99 assert page.has_no_link? 'API tokens'
101 find('a', text: 'Groups').click
102 look_for_add_new = 'Add a new group'
107 assert page.has_text? look_for_add_new
110 assert page.has_no_link? '#system-menu'
114 # test manage_account page
115 def verify_manage_account user
116 if user && user['is_active']
117 within('.navbar-fixed-top') do
118 find('a', text: "#{user['email']}").click
119 within('.dropdown-menu') do
120 find('a', text: 'Manage account').click
124 # now in manage account page
125 assert page.has_text? 'Virtual Machines'
126 assert page.has_text? 'Repositories'
127 assert page.has_text? 'SSH Keys'
128 assert page.has_text? 'Current Token'
130 assert page.has_text? 'The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'
132 click_link 'Add new SSH key'
134 within '.modal-content' do
135 assert page.has_text? 'Public Key'
136 assert page.has_button? 'Cancel'
137 assert page.has_button? 'Submit'
139 page.find_field('public_key').set 'first test with an incorrect ssh key value'
140 click_button 'Submit'
141 assert page.has_text? 'Public key does not appear to be a valid ssh-rsa or dsa public key'
143 public_key_str = api_fixture('authorized_keys')['active']['public_key']
144 page.find_field('public_key').set public_key_str
145 page.find_field('name').set 'added_in_test'
146 click_button 'Submit'
147 assert page.has_text? 'Public key already exists in the database, use a different key.'
149 new_key = SSHKey.generate
150 page.find_field('public_key').set new_key.ssh_public_key
151 page.find_field('name').set 'added_in_test'
152 click_button 'Submit'
155 # key must be added. look for it in the refreshed page
156 assert page.has_text? 'added_in_test'
160 # Check manage profile page and add missing profile to the user
162 assert page.has_no_text? 'My projects'
163 assert page.has_no_text? 'Projects shared with me'
165 assert page.has_text? 'Profile'
166 assert page.has_text? 'First name'
167 assert page.has_text? 'Last name'
168 assert page.has_text? 'Identity URL'
169 assert page.has_text? 'Email'
170 assert page.has_text? user['email']
172 # Using the default profile which has message and one required field
174 # Save profile without filling in the required field. Expect to be back in this profile page again
175 click_button "Save profile"
176 assert page.has_text? 'Profile'
177 assert page.has_text? 'First name'
178 assert page.has_text? 'Last name'
179 assert page.has_text? 'Save profile'
181 # This time fill in required field and then save. Expect to go to requested page after that.
182 profile_message = Rails.configuration.user_profile_form_message
183 required_field_title = ''
184 required_field_key = ''
185 profile_config = Rails.configuration.user_profile_form_fields
186 profile_config.andand.each do |entry|
188 required_field_key = entry['key']
189 required_field_title = entry['form_field_title']
193 assert page.has_text? profile_message.gsub(/<.*?>/,'')
194 assert page.has_text? required_field_title
195 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
197 click_button "Save profile"
198 # profile saved and in profile page now with success
199 assert page.has_text? 'Thank you for filling in your profile'
200 click_link 'Back to work'
202 # profile saved and in home page now
203 assert page.has_text? 'My projects'
204 assert page.has_text? 'Projects shared with me'
207 # test the search box
208 def verify_search_box user
209 if user && user['is_active']
210 # let's search for a valid uuid
211 within('.navbar-fixed-top') do
212 page.find_field('search').set user['uuid']
213 page.find('.glyphicon-search').click
216 # we should now be in the user's home project as a result of search
217 assert_selector "#Data_collections[data-object-uuid='#{user['uuid']}']"
219 # let's search again for an invalid valid uuid
220 within('.navbar-fixed-top') do
221 search_for = String.new user['uuid']
223 page.find_field('search').set search_for
224 page.find('.glyphicon-search').click
227 # we should see 'not found' error page
228 assert page.has_text? 'Not Found'
230 # let's search for the anonymously accessible project
231 publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
233 within('.navbar-fixed-top') do
234 # search again for the anonymously accessible project
235 page.find_field('search').set publicly_accessible_project['name'][0,10]
236 page.find('.glyphicon-search').click
239 within '.modal-content' do
240 assert page.has_text? 'All projects'
241 assert page.has_text? 'Search'
242 assert page.has_text? 'Cancel'
243 assert_selector('div', text: publicly_accessible_project['name'])
244 find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
249 # seeing "Unrestricted public data" now
250 assert page.has_text? publicly_accessible_project['name']
251 assert page.has_text? publicly_accessible_project['description']
256 [nil, nil, false, false],
257 ['inactive', api_fixture('users')['inactive'], true, false],
258 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
259 ['active', api_fixture('users')['active'], true, true],
260 ['admin', api_fixture('users')['admin'], true, true],
261 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
262 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
263 ].each do |token, user, invited, has_profile|
264 test "visit home page when profile is configured for user #{token}" do
265 # Our test config enabled profile by default. So, no need to update config
269 visit page_with_token(token)
272 verify_homepage_with_profile user, invited, has_profile
275 test "visit home page when profile not configured for user #{token}" do
276 Rails.configuration.user_profile_form_fields = false
281 visit page_with_token(token)
284 verify_homepage_with_profile user, invited, has_profile
287 test "check help for user #{token}" do
291 visit page_with_token(token)
299 ['active', api_fixture('users')['active'], true, true],
300 ['admin', api_fixture('users')['admin'], true, true],
301 ].each do |token, user|
302 test "test system menu for user #{token}" do
303 visit page_with_token(token)
304 verify_system_menu user
307 test "test manage account for user #{token}" do
308 visit page_with_token(token)
309 verify_manage_account user
312 test "test search for user #{token}" do
313 visit page_with_token(token)
314 verify_search_box user