1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class ApplicationLayoutTest < ActionDispatch::IntegrationTest
7 headless = Headless.new
9 Capybara.current_driver = :selenium
12 def verify_homepage user, invited, has_profile
13 profile_config = Rails.configuration.user_profile_form_fields
16 assert page.has_text?('Please log in'), 'Not found text - Please log in'
17 assert page.has_text?('The "Log in" button below will show you a Google sign-in page'), 'Not found text - google sign in page'
18 assert page.has_no_text?('My projects'), 'Found text - My projects'
19 assert page.has_link?("Log in to #{Rails.configuration.site_name}"), 'Not found text - log in to'
20 elsif user['is_active']
21 if profile_config && !has_profile
22 assert page.has_text?('Save profile'), 'No text - Save profile'
24 assert page.has_text?('My projects'), 'Not found text - My projects'
25 assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
28 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 . . .'
30 assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
33 within('.navbar-fixed-top') do
35 assert page.has_link?('Log in'), 'Not found link - Log in'
38 assert page.has_link?("#{user['email']}"), 'Not found link - email'
39 find('a', text: "#{user['email']}").click
40 within('.dropdown-menu') do
42 assert page.has_no_link?('Not active'), 'Found link - Not active'
43 assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
45 assert page.has_link?('Manage account'), 'No link - Manage account'
48 assert page.has_link?('Manage profile'), 'No link - Manage profile'
50 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
53 assert page.has_no_link?('Manage account'), 'Found link - Manage account'
54 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
56 assert page.has_link?('Log out'), 'No link - Log out'
64 within('.navbar-fixed-top') do
65 page.find("#arv-help").click
66 within('.dropdown-menu') do
67 assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
68 assert page.has_link?('API Reference'), 'No link - API Reference'
69 assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
70 assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
71 assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
72 # Version info and Report a problem are tested in "report_issue_test.rb"
77 def verify_system_menu user
78 if user && user['is_active']
79 look_for_add_new = nil
80 within('.navbar-fixed-top') do
81 page.find("#system-menu").click
83 within('.dropdown-menu') do
84 assert page.has_text?('Groups'), 'No text - Groups'
85 assert page.has_link?('Repositories'), 'No link - Repositories'
86 assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
87 assert page.has_link?('SSH keys'), 'No link - SSH keys'
88 assert page.has_link?('API tokens'), 'No link - API tokens'
89 find('a', text: 'Users').click
90 look_for_add_new = 'Add a new user'
93 within('.dropdown-menu') do
94 assert page.has_no_text?('Users'), 'Found text - Users'
95 assert page.has_no_link?('Repositories'), 'Found link - Repositories'
96 assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
97 assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
98 assert page.has_no_link?('API tokens'), 'Found link - API tokens'
100 find('a', text: 'Groups').click
101 look_for_add_new = 'Add a new group'
106 assert page.has_text? look_for_add_new
109 assert page.has_no_link?('#system-menu'), 'Found link - system menu'
113 # test manage_account page
114 def verify_manage_account user
115 if user && user['is_active']
116 within('.navbar-fixed-top') do
117 find('a', text: "#{user['email']}").click
118 within('.dropdown-menu') do
119 find('a', text: 'Manage account').click
123 # now in manage account page
124 assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
125 assert page.has_text?('Repositories'), 'No text - Repositories'
126 assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
127 assert page.has_text?('Current Token'), 'No text - Current Token'
129 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'
131 click_link 'Add new SSH key'
133 within '.modal-content' do
134 assert page.has_text?('Public Key'), 'No text - Public Key'
135 assert page.has_button?('Cancel'), 'No button - Cancel'
136 assert page.has_button?('Submit'), 'No button - Submit'
138 page.find_field('public_key').set 'first test with an incorrect ssh key value'
139 click_button 'Submit'
140 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'
142 public_key_str = api_fixture('authorized_keys')['active']['public_key']
143 page.find_field('public_key').set public_key_str
144 page.find_field('name').set 'added_in_test'
145 click_button 'Submit'
146 assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
148 new_key = SSHKey.generate
149 page.find_field('public_key').set new_key.ssh_public_key
150 page.find_field('name').set 'added_in_test'
151 click_button 'Submit'
154 # key must be added. look for it in the refreshed page
155 assert page.has_text?('added_in_test'), 'No text - added_in_test'
160 [nil, nil, false, false],
161 ['inactive', api_fixture('users')['inactive'], true, false],
162 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
163 ['active', api_fixture('users')['active'], true, true],
164 ['admin', api_fixture('users')['admin'], true, true],
165 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
166 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
167 ].each do |token, user, invited, has_profile|
169 test "visit home page for user #{token}" do
173 visit page_with_token(token)
176 verify_homepage user, invited, has_profile
179 test "check help for user #{token}" do
183 visit page_with_token(token)
191 ['active', api_fixture('users')['active']],
192 ['admin', api_fixture('users')['admin']],
193 ].each do |token, user|
195 test "test system menu for user #{token}" do
196 visit page_with_token(token)
197 verify_system_menu user
200 test "test manage account for user #{token}" do
201 visit page_with_token(token)
202 verify_manage_account user