Fix the users test to get the created user id
[arvados.git] / apps / workbench / test / integration / users_test.rb
index 1576c0405c27dc066761803d06f99c9fe9e10830..22b92c02e1d23dbc55740f8c6209744a5a3a30df 100644 (file)
@@ -1,6 +1,6 @@
 require 'integration_helper'
-require "selenium-webdriver"
-#require 'headless'
+require 'selenium-webdriver'
+require 'headless'
 
 class UsersTest < ActionDispatch::IntegrationTest
 
@@ -41,76 +41,62 @@ class UsersTest < ActionDispatch::IntegrationTest
   end
 
   test "create a new user" do
-    Capybara.current_driver = Capybara.javascript_driver
-    visit page_with_token('admin_trustedclient')
-
-    click_link 'Users'
-
-    assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
+    headless = Headless.new
+    headless.start
 
-    click_link 'Add a new user'
-    
-    # for now just check that we are back in Users -> List page
-    assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
-  end
-
-  #@headless
-  test "unsetup active user" do
-    Capybara.current_driver = Capybara.javascript_driver
-    #Capybara.current_driver = :selenium
+    Capybara.current_driver = :selenium
 
     visit page_with_token('admin_trustedclient')
 
     click_link 'Users'
 
-    assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
+    assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
 
-    # click on active user
-    click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
+    click_link 'Add a new user'
 
-    # Verify that is_active is set
-    click_link 'Attributes'
-    assert page.has_text? 'modified_by_user_uuid'
-    page.within(:xpath, '//a[@data-name="is_active"]') do
-      assert_equal "true", text, "Expected user's is_active to be true"
+    sleep(0.1)
+    popup = page.driver.browser.window_handles.last
+    page.within_window popup do
+      assert has_text? 'Virtual Machine'
+      fill_in "email", :with => "foo@example.com"
+      fill_in "repo_name", :with => "test_repo"
+      click_button "Submit"
     end
 
-    # go to Admin tab
-    click_link 'Admin'
-    assert page.has_text? 'As an admin, you can deactivate and reset this user'
+    sleep(0.1)
 
-    # Click on Deactivate button
-    click_button 'Deactivate Active User'
+    # verify that the new user showed up in the users page
+    assert page.has_text? 'foo@example.com'
 
-    # Click Ok in the confirm dialog
-=begin
-#use with selenium
-    page.driver.browser.switch_to.alert.accept
-    sleep(0.1)
-    popup = page.driver.browser.window_handles.last
-    #popup = page.driver.browser.window_handle
-    page.within_window popup do
-      assert has_text? 'Are you sure you want to deactivate'
-      click_button "OK"
+    new_user_uuid = nil
+    all("tr").each do |elem|
+      if elem.text.include? 'foo@example.com'
+        new_user_uuid = elem.text.split[0]
+        break
+      end
     end
 
-# use with poltergeist driver
-popup = page.driver.window_handles.last
-page.within_window popup do
-  #fill_in "email", :with => "my_email"
-  assert has_text? 'Are you sure you want to deactivate'
-  click_button "OK"
-end
-=end
+    assert new_user_uuid, "Expected new user uuid not found"
+
+    # go to the new user's page
+    click_link new_user_uuid
 
-    # Should now be back in the Attributes tab for the user
     assert page.has_text? 'modified_by_user_uuid'
     page.within(:xpath, '//a[@data-name="is_active"]') do
-      assert_equal "false", text, "Expected user's is_active to be false after unsetup"
+      assert_equal "false", text, "Expected new user's is_active to be false"
     end
+
+    click_link 'Metadata'
+    assert page.has_text? '(Repository: test_repo)'
+    assert !(page.has_text? '(VirtualMachine:)')
+
+    headless.stop
   end
 
   test "setup the active user" do
+    headless = Headless.new
+    headless.start
+
     Capybara.current_driver = :selenium
     visit page_with_token('admin_trustedclient')
 
@@ -128,6 +114,7 @@ end
     click_link 'Setup Active User'
 
     sleep(0.1)
+
     popup = page.driver.browser.window_handles.last
     page.within_window popup do
       assert has_text? 'Virtual Machine'
@@ -161,13 +148,46 @@ end
     assert page.has_text? '(Repository: second_test_repo)'
     assert page.has_text? '(VirtualMachine: testvm.shell)'
 
+    headless.stop
+  end
+
+  test "unsetup active user" do
+    headless = Headless.new
+    headless.start
+
+    Capybara.current_driver = :selenium
+
+    visit page_with_token('admin_trustedclient')
+
+    click_link 'Users'
+
+    assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
+
+    # click on active user
+    click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
+
+    # Verify that is_active is set
+    click_link 'Attributes'
+    assert page.has_text? 'modified_by_user_uuid'
+    page.within(:xpath, '//a[@data-name="is_active"]') do
+      assert_equal "true", text, "Expected user's is_active to be true"
+    end
+
+    # go to Admin tab
+    click_link 'Admin'
+    assert page.has_text? 'As an admin, you can deactivate and reset this user'
+
     # unsetup user and verify all the above links are deleted
     click_link 'Admin'
     click_button 'Deactivate Active User'
-    page.driver.browser.switch_to.alert.accept
     sleep(0.1)
 
-#    popup = page.driver.browser.window_handles.last
+    # Should now be back in the Attributes tab for the user
+    page.driver.browser.switch_to.alert.accept
+    assert page.has_text? 'modified_by_user_uuid'
+    page.within(:xpath, '//a[@data-name="is_active"]') do
+      assert_equal "false", text, "Expected user's is_active to be false after unsetup"
+    end
 
     click_link 'Metadata'
     assert !(page.has_text? '(Repository: test_repo)')
@@ -192,6 +212,8 @@ end
     click_link 'Metadata'
     assert page.has_text? '(Repository: second_test_repo)'
     assert page.has_text? '(VirtualMachine: testvm.shell)'
+
+    headless.stop
   end
 
 end