Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/wait for ajax #3463

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/spec/support/refinery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions images/spec/support/shared_examples/image_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions images/spec/support/shared_examples/image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions resources/spec/system/refinery/admin/resources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions testing/lib/refinery/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions testing/lib/refinery/testing/wait_for_ajax.rb
Original file line number Diff line number Diff line change
@@ -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