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'
76 # Version info and Report a problem are tested in "report_issue_test.rb"
81 def verify_system_menu user
82 if user && user['is_active']
83 look_for_add_new = nil
84 within('.navbar-fixed-top') do
85 page.find("#system-menu").click
87 within('.dropdown-menu') do
88 assert page.has_text?('Groups'), 'No text - Groups'
89 assert page.has_link?('Repositories'), 'No link - Repositories'
90 assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
91 assert page.has_link?('SSH keys'), 'No link - SSH keys'
92 assert page.has_link?('API tokens'), 'No link - API tokens'
93 find('a', text: 'Users').click
94 look_for_add_new = 'Add a new user'
97 within('.dropdown-menu') do
98 assert page.has_no_text?('Users'), 'Found text - Users'
99 assert page.has_no_link?('Repositories'), 'Found link - Repositories'
100 assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
101 assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
102 assert page.has_no_link?('API tokens'), 'Found link - API tokens'
104 find('a', text: 'Groups').click
105 look_for_add_new = 'Add a new group'
110 assert page.has_text? look_for_add_new
113 assert page.has_no_link?('#system-menu'), 'Found link - system menu'
117 # test manage_account page
118 def verify_manage_account user
119 if user && user['is_active']
120 within('.navbar-fixed-top') do
121 find('a', text: "#{user['email']}").click
122 within('.dropdown-menu') do
123 find('a', text: 'Manage account').click
127 # now in manage account page
128 assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
129 assert page.has_text?('Repositories'), 'No text - Repositories'
130 assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
131 assert page.has_text?('Current Token'), 'No text - Current Token'
133 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'
135 click_link 'Add new SSH key'
137 within '.modal-content' do
138 assert page.has_text?('Public Key'), 'No text - Public Key'
139 assert page.has_button?('Cancel'), 'No button - Cancel'
140 assert page.has_button?('Submit'), 'No button - Submit'
142 page.find_field('public_key').set 'first test with an incorrect ssh key value'
143 click_button 'Submit'
144 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'
146 public_key_str = api_fixture('authorized_keys')['active']['public_key']
147 page.find_field('public_key').set public_key_str
148 page.find_field('name').set 'added_in_test'
149 click_button 'Submit'
150 assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
152 new_key = SSHKey.generate
153 page.find_field('public_key').set new_key.ssh_public_key
154 page.find_field('name').set 'added_in_test'
155 click_button 'Submit'
158 # key must be added. look for it in the refreshed page
159 assert page.has_text?('added_in_test'), 'No text - added_in_test'
163 # Check manage profile page and add missing profile to the user
165 assert page.has_no_text?('My projects'), 'Found text - My projects'
166 assert page.has_no_text?('Projects shared with me'), 'Found text - Projects shared with me'
168 assert page.has_text?('Profile'), 'No text - Profile'
169 assert page.has_text?('First name'), 'No text - First name'
170 assert page.has_text?('Last name'), 'No text - Last name'
171 assert page.has_text?('Identity URL'), 'No text - Identity URL'
172 assert page.has_text?('Email'), 'No text - Email'
173 assert page.has_text?(user['email']), 'No text - user email'
175 # Using the default profile which has message and one required field
177 # Save profile without filling in the required field. Expect to be back in this profile page again
178 click_button "Save profile"
179 assert page.has_text?('Profile'), 'No text - Profile'
180 assert page.has_text?('First name'), 'No text - First name'
181 assert page.has_text?('Last name'), 'No text - Last name'
182 assert page.has_text?('Save profile'), 'No text - Save profile'
184 # This time fill in required field and then save. Expect to go to requested page after that.
185 profile_message = Rails.configuration.user_profile_form_message
186 required_field_title = ''
187 required_field_key = ''
188 profile_config = Rails.configuration.user_profile_form_fields
189 profile_config.andand.each do |entry|
191 required_field_key = entry['key']
192 required_field_title = entry['form_field_title']
196 assert page.has_text? profile_message.gsub(/<.*?>/,'')
197 assert page.has_text?(required_field_title), 'No text - configured required field title'
199 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
201 click_button "Save profile"
202 # profile saved and in profile page now with success
203 assert page.has_text?('Thank you for filling in your profile'), 'No text - Thank you for filling'
204 click_link 'Back to work!'
206 # profile saved and in home page now
207 assert page.has_text?('My projects'), 'No text - My projects'
208 assert page.has_text?('Projects shared with me'), 'No text - Projects shared with me'
212 [nil, nil, false, false],
213 ['inactive', api_fixture('users')['inactive'], true, false],
214 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
215 ['active', api_fixture('users')['active'], true, true],
216 ['admin', api_fixture('users')['admin'], true, true],
217 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
218 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
219 ].each do |token, user, invited, has_profile|
221 test "visit home page when profile is configured for user #{token}" do
222 # Our test config enabled profile by default. So, no need to update config
226 visit page_with_token(token)
229 verify_homepage_with_profile user, invited, has_profile
232 test "visit home page when profile not configured for user #{token}" do
233 Rails.configuration.user_profile_form_fields = false
238 visit page_with_token(token)
241 verify_homepage_with_profile user, invited, has_profile
244 test "check help for user #{token}" do
248 visit page_with_token(token)
256 ['active', api_fixture('users')['active']],
257 ['admin', api_fixture('users')['admin']],
258 ].each do |token, user|
260 test "test system menu for user #{token}" do
261 visit page_with_token(token)
262 verify_system_menu user
265 test "test manage account for user #{token}" do
266 visit page_with_token(token)
267 verify_manage_account user