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 click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
27 assert page.has_text? 'Attributes'
28 assert page.has_text? 'Metadata'
29 assert page.has_text? 'Admin'
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"
37 page.within(:xpath, '//a[@data-name="is_admin"]') do
38 assert_equal "false", text, "Expected user's is_admin to be false"
43 test "create a new user" do
44 Capybara.current_driver = Capybara.javascript_driver
45 visit page_with_token('admin_trustedclient')
49 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
51 click_on 'Add a new user'
53 # for now just check that we are back in Users -> List page
54 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
58 test "unsetup active user" do
59 Capybara.current_driver = Capybara.javascript_driver
60 #Capybara.current_driver = :selenium
62 visit page_with_token('admin_trustedclient')
66 assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
68 # click on active user
69 click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
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"
80 assert page.has_text? 'As an admin, you can deactivate and reset this user'
82 # Click on Deactivate button
83 click_button 'Deactivate Active User'
85 # Click Ok in the confirm dialog
88 page.driver.browser.switch_to.alert.accept
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'
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'
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"
113 test "setup the active user" do
114 Capybara.current_driver = Capybara.javascript_driver
115 visit page_with_token('admin_trustedclient')
119 assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
121 # click on active user
122 click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
126 assert page.has_text? 'As an admin, you can deactivate and reset this user'
129 # Click on Setup button
130 click_button 'Setup Active User'
132 # Click Ok in the confirm dialog
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"
142 # Should now be back in the Attributes tab for the user
143 assert page.has_text? 'modified_by_client_uuid'
145 puts "\n\n************* page now = \n#{page.body}"