Merge branch '5207-expires-at-time' closes #5207
[arvados.git] / apps / workbench / test / integration_helper.rb
index 4c1d505d3ffdd156cb3e4581fa3c59889417db1d..39fdf4b260abd68be05f252158f29629aa199199 100644 (file)
@@ -4,15 +4,20 @@ require 'capybara/poltergeist'
 require 'uri'
 require 'yaml'
 
+POLTERGEIST_OPTS = {
+  window_size: [1200, 800],
+  phantomjs_options: ['--ignore-ssl-errors=true'],
+  inspector: true,
+}
+
 Capybara.register_driver :poltergeist do |app|
-  Capybara::Poltergeist::Driver.new app, {
-    window_size: [1200, 800],
-    phantomjs_options: ['--ignore-ssl-errors=true'],
-    inspector: true,
-  }
+  Capybara::Poltergeist::Driver.new app, POLTERGEIST_OPTS
 end
 
-Headless.new.start
+Capybara.register_driver :poltergeist_without_file_api do |app|
+  js = File.expand_path '../support/remove_file_api.js', __FILE__
+  Capybara::Poltergeist::Driver.new app, POLTERGEIST_OPTS.merge(extensions: [js])
+end
 
 module WaitForAjax
   Capybara.default_wait_time = 5
@@ -27,6 +32,22 @@ module WaitForAjax
   end
 end
 
+module AssertDomEvent
+  # Yield the supplied block, then wait for an event to arrive at a
+  # DOM element.
+  def assert_triggers_dom_event events, target='body'
+    magic = 'received-dom-event-' + rand(2**30).to_s(36)
+    page.evaluate_script <<eos
+      $('#{target}').one('#{events}', function() {
+        $('body').addClass('#{magic}');
+      });
+eos
+    yield
+    assert_selector "body.#{magic}"
+    page.evaluate_script "$('body').removeClass('#{magic}');";
+  end
+end
+
 module HeadlessHelper
   class HeadlessSingleton
     def self.get
@@ -72,6 +93,7 @@ class ActionDispatch::IntegrationTest
   include Capybara::DSL
   include ApiFixtureLoader
   include WaitForAjax
+  include AssertDomEvent
   include HeadlessHelper
 
   @@API_AUTHS = self.api_fixture('api_client_authorizations')
@@ -83,9 +105,11 @@ class ActionDispatch::IntegrationTest
     # fixture, or passed as a raw string.
     api_token = ((@@API_AUTHS.include? token) ?
                  @@API_AUTHS[token]['api_token'] : token)
-    sep = (path.include? '?') ? '&' : '?'
+    path_parts = path.partition("#")
+    sep = (path_parts.first.include? '?') ? '&' : '?'
     q_string = URI.encode_www_form('api_token' => api_token)
-    "#{path}#{sep}#{q_string}"
+    path_parts.insert(1, "#{sep}#{q_string}")
+    path_parts.join("")
   end
 
   # Find a page element, but return false instead of raising an