Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[arvados.git] / apps / workbench / test / integration / user_manage_account_test.rb
1 require 'integration_helper'
2
3 class UserManageAccountTest < ActionDispatch::IntegrationTest
4   setup do
5     need_javascript
6   end
7
8   # test manage_account page
9   def verify_manage_account user
10     if user['is_active']
11       within('.navbar-fixed-top') do
12         find('a', text: "#{user['email']}").click
13         within('.dropdown-menu') do
14           find('a', text: 'Manage account').click
15         end
16       end
17
18       # now in manage account page
19       assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
20       assert page.has_text?('Repositories'), 'No text - Repositories'
21       assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
22       assert page.has_text?('Current Token'), 'No text - Current Token'
23       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'
24       add_and_verify_ssh_key
25     else  # inactive user
26       within('.navbar-fixed-top') do
27         find('a', text: "#{user['email']}").click
28         within('.dropdown-menu') do
29           assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
30         end
31       end
32     end
33   end
34
35   def add_and_verify_ssh_key
36       click_link 'Add new SSH key'
37
38       within '.modal-content' do
39         assert page.has_text?('Public Key'), 'No text - Public Key'
40         assert page.has_button?('Cancel'), 'No button - Cancel'
41         assert page.has_button?('Submit'), 'No button - Submit'
42
43         page.find_field('public_key').set 'first test with an incorrect ssh key value'
44         click_button 'Submit'
45         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'
46
47         public_key_str = api_fixture('authorized_keys')['active']['public_key']
48         page.find_field('public_key').set public_key_str
49         page.find_field('name').set 'added_in_test'
50         click_button 'Submit'
51         assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
52
53         new_key = SSHKey.generate
54         page.find_field('public_key').set new_key.ssh_public_key
55         page.find_field('name').set 'added_in_test'
56         click_button 'Submit'
57       end
58
59       # key must be added. look for it in the refreshed page
60       assert page.has_text?('added_in_test'), 'No text - added_in_test'
61   end
62
63   [
64     ['inactive', api_fixture('users')['inactive']],
65     ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],
66     ['active', api_fixture('users')['active']],
67     ['admin', api_fixture('users')['admin']],
68   ].each do |token, user|
69     test "test manage account for user #{token}" do
70       visit page_with_token(token)
71       verify_manage_account user
72     end
73   end
74
75   [
76     ['inactive_but_signed_user_agreement', true],
77     ['active', false],
78   ].each do |user, notifications|
79     test "test manage account for #{user} with notifications #{notifications}" do
80       visit page_with_token(user)
81       click_link 'notifications-menu'
82       if notifications
83         assert_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
84         assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
85         click_link('Click here to set up an SSH public key for use with Arvados')
86         assert_selector('a', text: 'Add new SSH key')
87
88         add_and_verify_ssh_key
89
90         # No more SSH notification
91         click_link 'notifications-menu'
92         assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
93         assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
94       else
95         assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
96         assert_no_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
97       end
98     end
99   end
100 end