Merge branch '4836-first-tab-load-wip'
[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       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'
28       add_and_verify_ssh_key
29     else  # inactive user
30       within('.navbar-fixed-top') do
31         find('a', text: "#{user['email']}").click
32         within('.dropdown-menu') do
33           assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
34         end
35       end
36     end
37   end
38
39   def add_and_verify_ssh_key
40       click_link 'Add new SSH key'
41
42       within '.modal-content' do
43         assert page.has_text?('Public Key'), 'No text - Public Key'
44         assert page.has_button?('Cancel'), 'No button - Cancel'
45         assert page.has_button?('Submit'), 'No button - Submit'
46
47         page.find_field('public_key').set 'first test with an incorrect ssh key value'
48         click_button 'Submit'
49         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'
50
51         public_key_str = api_fixture('authorized_keys')['active']['public_key']
52         page.find_field('public_key').set public_key_str
53         page.find_field('name').set 'added_in_test'
54         click_button 'Submit'
55         assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
56
57         new_key = SSHKey.generate
58         page.find_field('public_key').set new_key.ssh_public_key
59         page.find_field('name').set 'added_in_test'
60         click_button 'Submit'
61       end
62
63       # key must be added. look for it in the refreshed page
64       assert page.has_text?('added_in_test'), 'No text - added_in_test'
65   end
66
67   [
68     ['inactive', api_fixture('users')['inactive']],
69     ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],
70     ['active', api_fixture('users')['active']],
71     ['admin', api_fixture('users')['admin']],
72   ].each do |token, user|
73     test "test manage account for user #{token}" do
74       visit page_with_token(token)
75       verify_manage_account user
76     end
77   end
78
79   [
80     ['inactive_but_signed_user_agreement', true],
81     ['active', false],
82   ].each do |user, notifications|
83     test "test manage account for #{user} with notifications #{notifications}" do
84       visit page_with_token(user)
85       click_link 'notifications-menu'
86       if notifications
87         assert_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
88         assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
89         click_link('Click here to set up an SSH public key for use with Arvados')
90         assert_selector('a', text: 'Add new SSH key')
91
92         add_and_verify_ssh_key
93
94         # No more SSH notification
95         click_link 'notifications-menu'
96         assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
97         assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
98       else
99         assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
100         assert_no_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
101       end
102     end
103   end
104 end