Merge branch 'master' into 3714-report-issue-issues
[arvados.git] / apps / workbench / test / integration / user_manage_account_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class UserManageAccountTest < ActionDispatch::IntegrationTest
6   setup do
7     headless = Headless.new
8     headless.start
9     Capybara.current_driver = :selenium
10   end
11
12   # test manage_account page
13   def verify_manage_account user
14     if user['is_active']
15       within('.navbar-fixed-top') do
16         find('a', text: "#{user['email']}").click
17         within('.dropdown-menu') do
18           find('a', text: 'Manage account').click
19         end
20       end
21
22       # now in manage account page
23       assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
24       assert page.has_text?('Repositories'), 'No text - Repositories'
25       assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
26       assert page.has_text?('Current Token'), 'No text - Current Token'
27
28       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'
29
30       click_link 'Add new SSH key'
31
32       within '.modal-content' do
33         assert page.has_text?('Public Key'), 'No text - Public Key'
34         assert page.has_button?('Cancel'), 'No button - Cancel'
35         assert page.has_button?('Submit'), 'No button - Submit'
36
37         page.find_field('public_key').set 'first test with an incorrect ssh key value'
38         click_button 'Submit'
39         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'
40
41         public_key_str = api_fixture('authorized_keys')['active']['public_key']
42         page.find_field('public_key').set public_key_str
43         page.find_field('name').set 'added_in_test'
44         click_button 'Submit'
45         assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
46
47         new_key = SSHKey.generate
48         page.find_field('public_key').set new_key.ssh_public_key
49         page.find_field('name').set 'added_in_test'
50         click_button 'Submit'
51       end
52
53       # key must be added. look for it in the refreshed page
54       assert page.has_text?('added_in_test'), 'No text - added_in_test'
55     else  # inactive user
56       within('.navbar-fixed-top') do
57         find('a', text: "#{user['email']}").click
58         within('.dropdown-menu') do
59           assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
60         end
61       end
62     end
63   end
64
65   [
66     ['inactive', api_fixture('users')['inactive']],
67     ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],
68     ['active', api_fixture('users')['active']],
69     ['admin', api_fixture('users')['admin']],
70   ].each do |token, user|
71     test "test manage account for user #{token}" do
72       visit page_with_token(token)
73       verify_manage_account user
74     end
75   end
76 end