3021: Wait for shown.bs.modal before trying to click butttons in the modal.
authorTom Clegg <tom@curoverse.com>
Tue, 6 Jan 2015 22:48:42 +0000 (17:48 -0500)
committerTom Clegg <tom@curoverse.com>
Tue, 6 Jan 2015 22:48:42 +0000 (17:48 -0500)
Remove a stray Headless.new.start.

apps/workbench/test/integration/pipeline_instances_test.rb
apps/workbench/test/integration_helper.rb

index 52819e1263237547751ddc02d83616329e1b8dc8..bab40cc7dee463f5e16b6bf6b462d1a4ef871682 100644 (file)
@@ -299,7 +299,9 @@ class PipelineInstancesTest < ActionDispatch::IntegrationTest
 
       # Now re-run the pipeline
       if with_options
-        find('a,button', text: 'Re-run options').click
+        assert_triggers_dom_event 'shown.bs.modal' do
+          find('a,button', text: 'Re-run options').click
+        end
         within('.modal-dialog') do
           page.assert_selector 'a,button', text: 'Copy and edit inputs'
           page.assert_selector 'a,button', text: 'Run now'
@@ -313,11 +315,6 @@ class PipelineInstancesTest < ActionDispatch::IntegrationTest
         find('a,button', text: 'Re-run with latest').click
       end
 
-      # Wait for the dialog to close. (Otherwise, the next assertion
-      # could fail while we're still looking at the source instance
-      # page, even if the correct behavior is about to happen.)
-      assert_no_selector 'body.modal-open'
-
       # Verify that the newly created instance is created in the right
       # project. In case of project_viewer user, since the user cannot
       # write to the project, the pipeline should have been created in
index 4c1d505d3ffdd156cb3e4581fa3c59889417db1d..f430e842eb9c1a8068474b4da517baf3762235ec 100644 (file)
@@ -12,8 +12,6 @@ Capybara.register_driver :poltergeist do |app|
   }
 end
 
-Headless.new.start
-
 module WaitForAjax
   Capybara.default_wait_time = 5
   def wait_for_ajax
@@ -27,6 +25,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 = 'RXC0lObcVwEXwSvA'
+    page.evaluate_script <<eos
+      $('#{target}').one('#{events}', function() {
+        $('body').append('<div id="#{magic}"></div>');
+      });
+eos
+    yield
+    assert_selector "##{magic}"
+    page.evaluate_script "$('##{magic}').remove();";
+  end
+end
+
 module HeadlessHelper
   class HeadlessSingleton
     def self.get
@@ -72,6 +86,7 @@ class ActionDispatch::IntegrationTest
   include Capybara::DSL
   include ApiFixtureLoader
   include WaitForAjax
+  include AssertDomEvent
   include HeadlessHelper
 
   @@API_AUTHS = self.api_fixture('api_client_authorizations')