39374e7c700c7b5bcd0b1642c21ab9f3ab0d18f1
[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_on '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 = Capybara.javascript_driver
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     # go to Admin tab
125     click_link 'Admin'
126     assert page.has_text? 'As an admin, you can deactivate and reset this user'
127
128 =begin
129     # Click on Setup button
130     click_button 'Setup Active User'
131
132     # Click Ok in the confirm dialog
133     sleep(0.1)
134
135     popup = page.driver.window_handles.last
136     page.within_window popup do
137       assert has_text? 'Are you sure you want to deactivate Active User'
138       fill_in "email", :with => "test@example.com"
139       click_button "Ok"
140     end
141
142     # Should now be back in the Attributes tab for the user
143     assert page.has_text? 'modified_by_client_uuid'
144
145     puts "\n\n************* page now = \n#{page.body}"
146 =end
147   end
148
149 end