1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class UsersTest < ActionDispatch::IntegrationTest
7 test "login as active user but not admin" do
8 Capybara.current_driver = Capybara.javascript_driver
9 visit page_with_token('active_trustedclient')
11 assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
14 test "login as admin user and verify active user data" do
15 Capybara.current_driver = Capybara.javascript_driver
16 visit page_with_token('admin_trustedclient')
18 # go to Users list page
21 # check active user attributes in the list page
22 page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
23 assert (text.include? 'true false'), 'Expected is_active'
26 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
27 find('a,button', text: 'Show').
29 assert page.has_text? 'Attributes'
30 assert page.has_text? 'Metadata'
31 assert page.has_text? 'Admin'
33 # go to the Attributes tab
34 click_link 'Attributes'
35 assert page.has_text? 'modified_by_user_uuid'
36 page.within(:xpath, '//span[@data-name="is_active"]') do
37 assert_equal "true", text, "Expected user's is_active to be true"
39 page.within(:xpath, '//span[@data-name="is_admin"]') do
40 assert_equal "false", text, "Expected user's is_admin to be false"
45 test "create a new user" do
46 headless = Headless.new
49 Capybara.current_driver = :selenium
51 visit page_with_token('admin_trustedclient')
55 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
57 click_link 'Add a new user'
60 popup = page.driver.browser.window_handles.last
61 page.within_window popup do
62 assert has_text? 'Virtual Machine'
63 fill_in "email", :with => "foo@example.com"
64 fill_in "repo_name", :with => "test_repo"
71 # verify that the new user showed up in the users page and find
74 find('tr[data-object-uuid]', text: 'foo@example.com').
75 find('td', text: '-tpzed-').
77 assert new_user_uuid, "Expected new user uuid not found"
79 # go to the new user's page
80 find('tr', text: new_user_uuid).
81 find('a,button', text: 'Show').
84 assert page.has_text? 'modified_by_user_uuid'
85 page.within(:xpath, '//span[@data-name="is_active"]') do
86 assert_equal "false", text, "Expected new user's is_active to be false"
90 assert page.has_text? '(Repository: test_repo)'
91 assert !(page.has_text? '(VirtualMachine:)')
96 test "setup the active user" do
97 headless = Headless.new
100 Capybara.current_driver = :selenium
101 visit page_with_token('admin_trustedclient')
105 # click on active user
106 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
107 find('a,button', text: 'Show').
112 assert page.has_text? 'As an admin, you can setup'
114 click_link 'Setup Active User'
118 popup = page.driver.browser.window_handles.last
119 page.within_window popup do
120 assert has_text? 'Virtual Machine'
121 fill_in "repo_name", :with => "test_repo"
122 click_button "Submit"
126 assert page.has_text? 'modified_by_client_uuid'
128 click_link 'Metadata'
129 assert page.has_text? '(Repository: test_repo)'
130 assert !(page.has_text? '(VirtualMachine:)')
132 # Click on Setup button again and this time also choose a VM
134 click_link 'Setup Active User'
137 popup = page.driver.browser.window_handles.last
138 page.within_window popup do
139 fill_in "repo_name", :with => "second_test_repo"
140 select("testvm.shell", :from => 'vm_uuid')
141 click_button "Submit"
145 assert page.has_text? 'modified_by_client_uuid'
147 click_link 'Metadata'
148 assert page.has_text? '(Repository: second_test_repo)'
149 assert page.has_text? '(VirtualMachine: testvm.shell)'
154 test "unsetup active user" do
155 headless = Headless.new
158 Capybara.current_driver = :selenium
160 visit page_with_token('admin_trustedclient')
164 # click on active user
165 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
166 find('a,button', text: 'Show').
169 # Verify that is_active is set
170 find('a,button', text: 'Attributes').click
171 assert page.has_text? 'modified_by_user_uuid'
172 page.within(:xpath, '//span[@data-name="is_active"]') do
173 assert_equal "true", text, "Expected user's is_active to be true"
178 assert page.has_text? 'As an admin, you can deactivate and reset this user'
180 # unsetup user and verify all the above links are deleted
182 click_button 'Deactivate Active User'
185 # Should now be back in the Attributes tab for the user
186 page.driver.browser.switch_to.alert.accept
187 assert page.has_text? 'modified_by_user_uuid'
188 page.within(:xpath, '//span[@data-name="is_active"]') do
189 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
192 click_link 'Metadata'
193 assert !(page.has_text? '(Repository: test_repo)')
194 assert !(page.has_text? '(Repository: second_test_repo)')
195 assert !(page.has_text? '(VirtualMachine: testvm.shell)')
197 # setup user again and verify links present
199 click_link 'Setup Active User'
202 popup = page.driver.browser.window_handles.last
203 page.within_window popup do
204 fill_in "repo_name", :with => "second_test_repo"
205 select("testvm.shell", :from => 'vm_uuid')
206 click_button "Submit"
210 assert page.has_text? 'modified_by_client_uuid'
212 click_link 'Metadata'
213 assert page.has_text? '(Repository: second_test_repo)'
214 assert page.has_text? '(VirtualMachine: testvm.shell)'