1 require 'integration_helper'
3 class UserSettingsMenuTest < ActionDispatch::IntegrationTest
8 # test user settings menu
9 def verify_user_settings_menu user
11 within('.navbar-fixed-top') do
12 page.find("#notifications-menu").click
13 within('.dropdown-menu') do
14 assert_selector 'a', text: 'Virtual machines'
15 assert_selector 'a', text: 'Repositories'
16 assert_selector 'a', text: 'Current token'
17 assert_selector 'a', text: 'SSH keys'
18 find('a', text: 'SSH keys').click
22 # now in SSH Keys page
23 assert page.has_text?('Add new SSH key'), 'No text - Add SSH key'
24 add_and_verify_ssh_key
26 within('.navbar-fixed-top') do
27 page.find("#notifications-menu").click
28 within('.dropdown-menu') do
29 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
35 def add_and_verify_ssh_key
36 click_link 'Add new SSH key'
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'
43 page.find_field('public_key').set 'first test with an incorrect ssh key value'
45 assert_text 'Public key does not appear to be a valid ssh-rsa or dsa public key'
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'
51 assert_text 'Public key already exists in the database, use a different key.'
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'
59 # key must be added. look for it in the refreshed page
60 assert_text 'added_in_test'
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 user settings menu for user #{token}" do
70 visit page_with_token(token)
71 verify_user_settings_menu user
75 test "pipeline notification shown even though public pipelines exist" do
76 skip "created_by doesn't work that way"
77 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
78 visit page_with_token 'job_reader'
79 click_link 'notifications-menu'
80 assert_selector 'a', text: 'Click here to learn how to run an Arvados Crunch pipeline'
84 ['job_reader', :ssh, :pipeline],
86 ].each do |user, *expect|
87 test "user settings menu for #{user} with notifications #{expect.inspect}" do
88 Rails.configuration.anonymous_user_token = false
89 visit page_with_token(user)
90 click_link 'notifications-menu'
91 if expect.include? :ssh
92 assert_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
93 click_link('Click here to set up an SSH public key for use with Arvados')
94 assert_selector('a', text: 'Add new SSH key')
96 add_and_verify_ssh_key
98 # No more SSH notification
99 click_link 'notifications-menu'
100 assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
102 assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
103 assert_no_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
106 if expect.include? :pipeline
107 assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
112 test "verify repositories for active user" do
113 visit page_with_token('active',"/repositories")
115 repos = [[api_fixture('repositories')['foo'], true],
116 [api_fixture('repositories')['repository3'], false],
117 [api_fixture('repositories')['repository4'], false],
118 [api_fixture('repositories')['arvados'], false]]
120 repos.each do |(repo, owned)|
121 within('tr', text: repo['name']+'.git') do
122 assert_text repo['name']
123 assert_selector 'a', text:'Show'
125 assert_not_nil first('.glyphicon-trash')
127 assert_nil first('.glyphicon-trash')
133 test "request shell access" do
134 ActionMailer::Base.deliveries = []
135 visit page_with_token('spectator', "/users/#{api_fixture('users')['spectator']['uuid']}/virtual_machines")
136 assert_text 'You do not have access to any virtual machines'
137 click_link 'Send request for shell access'
139 # Button text changes to "sending...", then back to normal. In the
140 # test suite we can't depend on confirming the "sending..." state
141 # before it goes back to normal, though.
142 ## assert_selector 'a', text: 'Sending request...'
143 assert_selector 'a', text: 'Send request for shell access'
144 assert_text 'A request for shell access was sent'
146 # verify that the email was sent
147 user = api_fixture('users')['spectator']
148 full_name = "#{user['first_name']} #{user['last_name']}"
149 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
151 ActionMailer::Base.deliveries.each do |email|
152 if email.subject.include?(expected)
156 assert_equal 1, found_email, "Expected email after requesting shell access"
158 # Revisit the page and verify the request sent message along with
159 # the request button.
160 within('.navbar-fixed-top') do
161 page.find("#notifications-menu").click
162 within('.dropdown-menu') do
163 find('a', text: 'Virtual machines').click
166 assert_text 'You do not have access to any virtual machines.'
167 assert_text 'A request for shell access was sent on '
168 assert_selector 'a', text: 'Send request for shell access'
171 test "create new repository" do
172 visit page_with_token("active_trustedclient")
173 within('.navbar-fixed-top') do
174 page.find("#notifications-menu").click
175 within('.dropdown-menu') do
176 assert_selector 'a', text: 'Repositories'
177 find('a', text: 'Repositories').click
180 click_on "Add new repository"
181 within ".modal-dialog" do
182 fill_in "Name", with: "workbenchtest"
185 assert_text ":active/workbenchtest.git"
186 assert_match /git@git.*:active\/workbenchtest.git/, page.text
187 assert_match /https:\/\/git.*\/active\/workbenchtest.git/, page.text
191 ['virtual_machines', nil, 'Host name', 'testvm2.shell'],
192 ['/repositories', 'Add new repository', 'It may take a minute or two before you can clone your new repository.', 'active/foo'],
193 ['/current_token', nil, 'HISTIGNORE=$HISTIGNORE', 'ARVADOS_API_TOKEN=3kg6k6lzmp9kj5'],
194 ['ssh_keys', 'Add new SSH key', 'Click here to learn about SSH keys in Arvados.', 'active'],
195 ].each do |page_name, button_name, look_for, content|
196 test "test user settings menu for page #{page_name}" do
197 if page_name == '/current_token' || page_name == '/repositories'
198 visit page_with_token('active', page_name)
200 visit page_with_token('active', "/users/#{api_fixture('users')['active']['uuid']}/#{page_name}")
203 assert page.has_text? content
205 assert_selector 'a', text: button_name
206 find('a', text: button_name).click
209 assert page.has_text? look_for
214 ['virtual_machines', 'You do not have access to any virtual machines.'],
215 ['/repositories', api_fixture('repositories')['arvados']['name']],
216 ['/current_token', 'HISTIGNORE=$HISTIGNORE'],
217 ['ssh_keys', 'You have not yet set up an SSH public key for use with Arvados.'],
218 ].each do |page_name, look_for|
219 test "test user settings menu for page #{page_name} when page is empty" do
220 if page_name == '/current_token' || page_name == '/repositories'
221 visit page_with_token('user1_with_load', page_name)
223 visit page_with_token('admin', "/users/#{api_fixture('users')['user1_with_load']['uuid']}/#{page_name}")
226 assert page.has_text? look_for
227 if page_name == '/repositories'
228 assert_equal 1, page.all('a[data-original-title="show repository"]').count