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
186 profile_config = Rails.configuration.user_profile_form_fields
188 required_field_title = ''
189 required_field_key = ''
190 profile_config.andand.each do |entry|
192 profile_message = entry['message']
195 required_field_key = entry['key']
196 required_field_title = entry['form_field_title']
201 assert page.has_text? profile_message
202 assert page.has_text? required_field_title
203 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
205 click_button "Save profile"
207 # profile saved and in home page now
208 assert page.has_text? 'My projects'
209 assert page.has_text? 'Projects shared with me'
212 # test the search box
213 def check_search_box user
215 # let's search for the anonymously accessible project
216 publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
218 within('.navbar-fixed-top') do
219 page.find_field('search').set user['uuid']
220 page.find('.glyphicon-search').click
222 # we should now be in the user's page as a result of search
223 assert page.has_text? user['email']
225 # search again for the anonymously accessible project
226 page.find_field('search').set publicly_accessible_project['name'][0,10]
227 page.find('.glyphicon-search').click
230 within '.modal-content' do
231 assert page.has_text? 'All projects'
232 assert page.has_text? 'Search'
233 assert page.has_text? 'Cancel'
234 assert_selector('div', text: publicly_accessible_project['name'])
235 find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
240 # seeing "Unrestricted public data" now
241 assert page.has_text? publicly_accessible_project['name']
242 assert page.has_text? publicly_accessible_project['description']
247 [nil, nil, false, false],
248 ['inactive', api_fixture('users')['inactive'], true, false],
249 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
250 ['active', api_fixture('users')['active'], true, true],
251 ['admin', api_fixture('users')['admin'], true, true],
252 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
253 ].each do |token, user, invited, has_profile|
254 test "visit home page when profile is configured for user #{token}" do
255 # Our test config enabled profile by default. So, no need to update config
259 visit page_with_token(token)
262 verify_homepage_with_profile user, invited, has_profile
267 [nil, nil, false, false],
268 ['inactive', api_fixture('users')['inactive'], true, false],
269 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
270 ['active', api_fixture('users')['active'], true, true],
271 ['admin', api_fixture('users')['admin'], true, true],
272 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
273 ].each do |token, user, invited, has_profile|
274 test "visit home page when profile not configured for user #{token}" do
275 Rails.configuration.user_profile_form_fields = false
280 visit page_with_token(token)
283 verify_homepage_with_profile user, invited, has_profile