Skip to content

Commit

Permalink
Merge pull request #3365 from projectblacklight/avoid-sleep
Browse files Browse the repository at this point in the history
Avoid unnecessarily using sleep in Capybara specs
  • Loading branch information
taylor-steve authored Dec 17, 2024
2 parents 37221b9 + fbd2fe3 commit 9550f54
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 30 deletions.
10 changes: 4 additions & 6 deletions spec/features/autocomplete_typeahead_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Autocomplete typeahead', js: true, type: :feature do
RSpec.describe 'Autocomplete typeahead', js: true, type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:admin) { FactoryBot.create(:exhibit_admin, exhibit:) }

Expand All @@ -21,7 +21,7 @@
expect(page).to have_css('.leaflet-container', visible: true)

click_button 'Save changes'
sleep 2 # Test fails without this after move to Propshaft.
expect(page).to have_content 'The exhibit was successfully updated.'

featured_image = Spotlight::FeaturedImage.last

Expand All @@ -40,9 +40,7 @@
check 'Show background image in masthead'

fill_in_typeahead_field(with: 'xd327cm9378', type: 'featured-image')
sleep 2 # HACK: that seems to mysteriously work.

expect(page).to have_css('[data-panel-image-pagination]', text: /Image 1 of 2/, visible: true)
expect(page).to have_css('[data-panel-image-pagination]', text: /Image 1 of 2/)

# Open the multi-image selector and choose the last one
click_link('Change')
Expand All @@ -53,7 +51,7 @@

expect(page).to have_content('The exhibit was successfully updated.')

expect(page).to have_css('[data-panel-image-pagination]', text: /Image 2 of 2/, visible: true)
expect(page).to have_css('[data-panel-image-pagination]', text: /Image 2 of 2/)
end

it 'removes the multi-image selector when a non multi-image item is selected' do
Expand Down
11 changes: 5 additions & 6 deletions spec/features/browse_category_admin_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Browse Category Administration', type: :feature do
RSpec.describe 'Browse Category Administration', type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:curator) { FactoryBot.create(:exhibit_curator, exhibit:) }
let!(:search) { FactoryBot.create(:search, exhibit:, query_params: { f: { 'genre_ssim' => ['Value'] } }) }
Expand All @@ -21,10 +21,9 @@
expect(page).to have_css('#save-modal')
fill_in 'search_title', with: 'Some search'
expect do
find('input[name="commit"]').click
sleep 1 # Test fails without this after move to Propshaft.
click_on 'Save'
expect(page).to have_content('The browse category was created.')
exhibit.searches.reload
sleep 1 # Test fails without this after move to Propshaft.
end.to change { exhibit.searches.count }.by 1
expect(exhibit.searches.last.query_params).to eq 'q' => 'xyz'
end
Expand All @@ -34,8 +33,8 @@
click_button 'Save this search'
expect(page).to have_css('#save-modal')
select search.title, from: 'id'
find('input[name="commit"]').click
sleep 1 # Test fails without this after move to Propshaft.
click_on 'Save'
expect(page).to have_content('The browse category was created.')
expect(search.reload.query_params).to eq 'q' => 'xyz'
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/features/exhibits/administration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Exhibit Administration', type: :feature do
RSpec.describe 'Exhibit Administration', type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:admin) { FactoryBot.create(:exhibit_admin, exhibit:) }
let(:hidden_input_id_0) { 'exhibit_contact_emails_attributes_0_id' }
Expand Down Expand Up @@ -108,9 +108,9 @@
visit spotlight.edit_exhibit_path(exhibit)
fill_in email_id_0, with: email_address_0
click_button 'Save changes'
sleep 1 # Test fails without this after move to Propshaft.
expect(page).to have_content('The exhibit was successfully updated.')

find_by_id('another-email').click
click_button 'Add new recipient'
expect(find_field(email_id_0).value).to eq email_address_0
expect(find_field(email_id_1).value).to eq ''

Expand All @@ -130,7 +130,7 @@
find_by_id('another-email').click
fill_in email_id_1, with: email_address_1
click_button 'Save changes'
sleep 1 # Test fails without this after move to Propshaft.
expect(page).to have_content('The exhibit was successfully updated.')

Spotlight::ContactEmail.all.first.destroy
page.accept_confirm do
Expand Down
3 changes: 1 addition & 2 deletions spec/features/feature_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Feature page', type: :feature, versioning: true do
RSpec.describe 'Feature page', type: :feature, versioning: true do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:exhibit_curator) { FactoryBot.create(:exhibit_curator, exhibit:) }

Expand Down Expand Up @@ -141,7 +141,6 @@
visit spotlight.edit_exhibit_feature_page_path(feature_page.exhibit, feature_page)

click_on 'Cancel'
sleep 2

# and then open the edit page again
visit spotlight.edit_exhibit_feature_page_path(feature_page.exhibit, feature_page)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Solr Documents Embed Block', js: true, type: :feature do
RSpec.describe 'Solr Documents Embed Block', js: true, type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:exhibit_curator) { FactoryBot.create(:exhibit_curator, exhibit:) }

Expand All @@ -18,8 +18,6 @@

save_page_changes

sleep 2 # Test is flappy without this after move to Propshaft?

expect(page).to have_css('.openseadragon-container')
expect(page).to have_css('picture')
within('picture') do
Expand Down
8 changes: 3 additions & 5 deletions spec/features/javascript/search_config_admin_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Search Configuration Administration', js: true do
RSpec.describe 'Search Configuration Administration', js: true do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:user) { FactoryBot.create(:exhibit_admin, exhibit:) }

Expand Down Expand Up @@ -61,11 +61,9 @@
fill_in(input_id, with: 'Topic')

click_button 'Save changes'
sleep 1 # Test fails without this after move to Propshaft.
click_link 'Facets'

expect(page).to have_css('.alert', text: 'The exhibit was successfully updated.', visible: true)
expect(page).to have_content 'The exhibit was successfully updated.'

click_link 'Facets'
expect(page).to have_no_content('Genre')
expect(page).to have_content('Topic')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/features/report_a_problem_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Report a Problem', type: :feature do
RSpec.describe 'Report a Problem', type: :feature do
let!(:exhibit) { FactoryBot.create(:exhibit) }
let(:honeypot_field_name) { Spotlight::Engine.config.spambot_honeypot_email_field }

Expand Down Expand Up @@ -42,7 +42,7 @@

expect do
click_on 'Send'
sleep 1 # Test fails without this after move to Propshaft.
expect(page).to have_content('Thanks. Your feedback has been sent.')
end.to change { ActionMailer::Base.deliveries.count }.by(1)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/features/site_users_management_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Site users management', js: true do
RSpec.describe 'Site users management', js: true do
let(:user) { FactoryBot.create(:site_admin) }
let!(:existing_user) { FactoryBot.create(:exhibit_visitor) }
let!(:exhibit_admin) { FactoryBot.create(:exhibit_admin) }
Expand Down Expand Up @@ -60,7 +60,7 @@

expect do
click_button 'Add role'
sleep 1 # Test fails without this after move to Propshaft.
expect(page).to have_content('Added user as an adminstrator')
end.to change { Devise::Mailer.deliveries.count }.by(1)
expect(User.where(email: 'a-user-that-did-not-exist@example.com').first.invitation_sent_at).to be_present
end
Expand Down

0 comments on commit 9550f54

Please sign in to comment.