Integration test for setup user
[arvados.git] / apps / workbench / test / integration / users_test.rb
1 require 'integration_helper'
2 require "selenium-webdriver"
3 #require 'headless'
4
5 class UsersTest < ActionDispatch::IntegrationTest
6
7   test "login as active user but not admin" do
8     Capybara.current_driver = Capybara.javascript_driver
9     visit page_with_token('active_trustedclient')
10
11     assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
12   end
13
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')
17
18     # go to Users list page
19     click_link 'Users'
20
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'
24     end
25
26     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
27     assert page.has_text? 'Attributes'
28     assert page.has_text? 'Metadata'
29     assert page.has_text? 'Admin'
30
31     # go to the Attributes tab
32     click_link 'Attributes'
33     assert page.has_text? 'modified_by_user_uuid'
34     page.within(:xpath, '//a[@data-name="is_active"]') do
35       assert_equal "true", text, "Expected user's is_active to be true"
36     end
37     page.within(:xpath, '//a[@data-name="is_admin"]') do
38       assert_equal "false", text, "Expected user's is_admin to be false"
39     end
40
41   end
42
43   test "create a new user" do
44     Capybara.current_driver = Capybara.javascript_driver
45     visit page_with_token('admin_trustedclient')
46
47     click_link 'Users'
48
49     assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
50
51     click_link 'Add a new user'
52     
53     # for now just check that we are back in Users -> List page
54     assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
55   end
56
57   #@headless
58   test "unsetup active user" do
59     Capybara.current_driver = Capybara.javascript_driver
60     #Capybara.current_driver = :selenium
61
62     visit page_with_token('admin_trustedclient')
63
64     click_link 'Users'
65
66     assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
67
68     # click on active user
69     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
70
71     # Verify that is_active is set
72     click_link 'Attributes'
73     assert page.has_text? 'modified_by_user_uuid'
74     page.within(:xpath, '//a[@data-name="is_active"]') do
75       assert_equal "true", text, "Expected user's is_active to be true"
76     end
77
78     # go to Admin tab
79     click_link 'Admin'
80     assert page.has_text? 'As an admin, you can deactivate and reset this user'
81
82     # Click on Deactivate button
83     click_button 'Deactivate Active User'
84
85     # Click Ok in the confirm dialog
86 =begin
87 #use with selenium
88     page.driver.browser.switch_to.alert.accept
89     sleep(0.1)
90     popup = page.driver.browser.window_handles.last
91     #popup = page.driver.browser.window_handle
92     page.within_window popup do
93       assert has_text? 'Are you sure you want to deactivate'
94       click_button "OK"
95     end
96
97 # use with poltergeist driver
98 popup = page.driver.window_handles.last
99 page.within_window popup do
100   #fill_in "email", :with => "my_email"
101   assert has_text? 'Are you sure you want to deactivate'
102   click_button "OK"
103 end
104 =end
105
106     # Should now be back in the Attributes tab for the user
107     assert page.has_text? 'modified_by_user_uuid'
108     page.within(:xpath, '//a[@data-name="is_active"]') do
109       assert_equal "false", text, "Expected user's is_active to be false after unsetup"
110     end
111   end
112
113   test "setup the active user" do
114     Capybara.current_driver = :selenium
115     visit page_with_token('admin_trustedclient')
116
117     click_link 'Users'
118
119     assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
120
121     # click on active user
122     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
123
124     # Setup user
125     click_link 'Admin'
126     assert page.has_text? 'As an admin, you can setup'
127
128     click_link 'Setup Active User'
129
130     sleep(0.1)
131     popup = page.driver.browser.window_handles.last
132     page.within_window popup do
133       assert has_text? 'Virtual Machine'
134       fill_in "repo_name", :with => "test_repo"
135       click_button "Submit"
136     end
137
138     sleep(0.1)
139     assert page.has_text? 'modified_by_client_uuid'
140
141     click_link 'Metadata'
142     assert page.has_text? '(Repository: test_repo)'
143     assert !(page.has_text? '(VirtualMachine:)')
144
145     # Click on Setup button again and this time also choose a VM
146     click_link 'Admin'
147     click_link 'Setup Active User'
148
149     sleep(0.1)
150     popup = page.driver.browser.window_handles.last
151     page.within_window popup do
152       fill_in "repo_name", :with => "second_test_repo"
153       select("testvm.shell", :from => 'vm_uuid')
154       click_button "Submit"
155     end
156
157     sleep(0.1)
158     assert page.has_text? 'modified_by_client_uuid'
159
160     click_link 'Metadata'
161     assert page.has_text? '(Repository: second_test_repo)'
162     assert page.has_text? '(VirtualMachine: testvm.shell)'
163
164     # unsetup user and verify all the above links are deleted
165     click_link 'Admin'
166     click_button 'Deactivate Active User'
167     page.driver.browser.switch_to.alert.accept
168     sleep(0.1)
169
170 #    popup = page.driver.browser.window_handles.last
171
172     click_link 'Metadata'
173     assert !(page.has_text? '(Repository: test_repo)')
174     assert !(page.has_text? '(Repository: second_test_repo)')
175     assert !(page.has_text? '(VirtualMachine: testvm.shell)')
176
177     # setup user again and verify links present
178     click_link 'Admin'
179     click_link 'Setup Active User'
180
181     sleep(0.1)
182     popup = page.driver.browser.window_handles.last
183     page.within_window popup do
184       fill_in "repo_name", :with => "second_test_repo"
185       select("testvm.shell", :from => 'vm_uuid')
186       click_button "Submit"
187     end
188
189     sleep(0.1)
190     assert page.has_text? 'modified_by_client_uuid'
191
192     click_link 'Metadata'
193     assert page.has_text? '(Repository: second_test_repo)'
194     assert page.has_text? '(VirtualMachine: testvm.shell)'
195   end
196
197 end