diff --git a/core/spec/support/refinery.rb b/core/spec/support/refinery.rb index 3506fa6497..913b7cb934 100644 --- a/core/spec/support/refinery.rb +++ b/core/spec/support/refinery.rb @@ -4,6 +4,7 @@ config.extend Refinery::Testing::ControllerMacros::Authentication, :type => :controller config.include Refinery::Testing::ControllerMacros::Routes, :type => :controller config.extend Refinery::Testing::FeatureMacros::Authentication, :type => :system + config.include Refinery::Testing::WaitForAjax, type: :system # set some config values so that image and resource factories don't fail to create config.before do diff --git a/images/spec/support/shared_examples/image_indexer.rb b/images/spec/support/shared_examples/image_indexer.rb index 0dc60b06e6..29f63f25bd 100644 --- a/images/spec/support/shared_examples/image_indexer.rb +++ b/images/spec/support/shared_examples/image_indexer.rb @@ -10,7 +10,9 @@ it 'shows all the images', js: true do if index_in_frame + sleep 0.1 page.within_frame(dialog_frame_id) do + sleep 0.1 expect(page).to have_selector(index_item_selector, count: image_count) end else diff --git a/images/spec/support/shared_examples/image_uploader.rb b/images/spec/support/shared_examples/image_uploader.rb index a55f6d4583..5bf6c7438b 100644 --- a/images/spec/support/shared_examples/image_uploader.rb +++ b/images/spec/support/shared_examples/image_uploader.rb @@ -6,28 +6,32 @@ end let(:uploading_an_image) { - ->{ - open_upload_dialog - page.within_frame(dialog_frame_id) do - select_upload - attach_file 'image_image', image_path - fill_in 'image_image_title', with: 'Image With Dashes' - fill_in 'image_image_alt', with: "Alt description for image" - click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') - end + ->{ + open_upload_dialog + page.within_frame(dialog_frame_id) do + sleep 0.2 + select_upload + sleep 0.2 + attach_file 'image_image', image_path + fill_in 'image_image_title', with: 'Image With Dashes' + fill_in 'image_image_alt', with: "Alt description for image" + click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') + end + + sleep 0.1 } } context 'when the image type is acceptable' do let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/image-with-dashes.jpg")} - it 'the image is uploaded', :js => true do + it 'the image is uploaded', js: true do expect(uploading_an_image).to change(Refinery::Image, :count).by(1) end end context 'when the image type is not acceptable' do let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")} - it 'the image is rejected', :js => true do + it 'the image is rejected', js: true do expect(uploading_an_image).to_not change(Refinery::Image, :count) page.within_frame(dialog_frame_id) do expect(page).to have_content(::I18n.t('incorrect_format', diff --git a/resources/spec/system/refinery/admin/resources_spec.rb b/resources/spec/system/refinery/admin/resources_spec.rb index 65bc50b01a..0f7f17d751 100644 --- a/resources/spec/system/refinery/admin/resources_spec.rb +++ b/resources/spec/system/refinery/admin/resources_spec.rb @@ -32,6 +32,8 @@ module Admin attach_file 'resource_file', file_path click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') end + + sleep 0.1 end end diff --git a/testing/lib/refinery/testing.rb b/testing/lib/refinery/testing.rb index f73bde1dd7..e4fcbd35c9 100644 --- a/testing/lib/refinery/testing.rb +++ b/testing/lib/refinery/testing.rb @@ -29,5 +29,6 @@ def load_factories autoload :ControllerMacros, 'refinery/testing/controller_macros' autoload :FeatureMacros, 'refinery/testing/feature_macros' + autoload :WaitForAjax, 'refinery/testing/wait_for_ajax' end end diff --git a/testing/lib/refinery/testing/wait_for_ajax.rb b/testing/lib/refinery/testing/wait_for_ajax.rb new file mode 100644 index 0000000000..7890927c25 --- /dev/null +++ b/testing/lib/refinery/testing/wait_for_ajax.rb @@ -0,0 +1,15 @@ +module Refinery + module Testing + module WaitForAjax + def wait_for_ajax + Timeout.timeout(Capybara.default_max_wait_time) do + loop until finished_all_ajax_requests? + end + end + + def finished_all_ajax_requests? + page.evaluate_script(‘jQuery.active’).zero? + end + end + end +end