From f195eb4d4dd6735a4f3b27ba0fc989805e316453 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Mon, 16 Dec 2024 13:50:58 -0600 Subject: [PATCH] Avoid unnecessarily using sleep in Capybara specs --- spec/features/autocomplete_typeahead_spec.rb | 10 ++++------ spec/features/browse_category_admin_spec.rb | 11 +++++------ spec/features/exhibits/administration_spec.rb | 8 +++----- spec/features/feature_page_spec.rb | 3 +-- .../blocks/solr_documents_embed_block_spec.rb | 4 +--- spec/features/javascript/search_config_admin_spec.rb | 8 +++----- spec/features/report_a_problem_spec.rb | 4 ++-- spec/features/site_users_management_spec.rb | 4 ++-- 8 files changed, 21 insertions(+), 31 deletions(-) diff --git a/spec/features/autocomplete_typeahead_spec.rb b/spec/features/autocomplete_typeahead_spec.rb index 3c090c418..70c5ba07d 100644 --- a/spec/features/autocomplete_typeahead_spec.rb +++ b/spec/features/autocomplete_typeahead_spec.rb @@ -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:) } @@ -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 @@ -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') @@ -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 diff --git a/spec/features/browse_category_admin_spec.rb b/spec/features/browse_category_admin_spec.rb index 73f4de0e9..f631adb5f 100644 --- a/spec/features/browse_category_admin_spec.rb +++ b/spec/features/browse_category_admin_spec.rb @@ -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'] } }) } @@ -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 @@ -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 diff --git a/spec/features/exhibits/administration_spec.rb b/spec/features/exhibits/administration_spec.rb index 669a3f77f..4a4de3e7a 100644 --- a/spec/features/exhibits/administration_spec.rb +++ b/spec/features/exhibits/administration_spec.rb @@ -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' } @@ -108,9 +108,7 @@ 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. - - 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 '' @@ -130,7 +128,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 diff --git a/spec/features/feature_page_spec.rb b/spec/features/feature_page_spec.rb index 0bb2c1dfc..6c10deb66 100644 --- a/spec/features/feature_page_spec.rb +++ b/spec/features/feature_page_spec.rb @@ -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:) } @@ -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) diff --git a/spec/features/javascript/blocks/solr_documents_embed_block_spec.rb b/spec/features/javascript/blocks/solr_documents_embed_block_spec.rb index eb28869be..70c73fef8 100644 --- a/spec/features/javascript/blocks/solr_documents_embed_block_spec.rb +++ b/spec/features/javascript/blocks/solr_documents_embed_block_spec.rb @@ -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:) } @@ -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 diff --git a/spec/features/javascript/search_config_admin_spec.rb b/spec/features/javascript/search_config_admin_spec.rb index a9fc611db..aa9734127 100644 --- a/spec/features/javascript/search_config_admin_spec.rb +++ b/spec/features/javascript/search_config_admin_spec.rb @@ -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:) } @@ -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 diff --git a/spec/features/report_a_problem_spec.rb b/spec/features/report_a_problem_spec.rb index 9bb56a8d8..339fc761f 100644 --- a/spec/features/report_a_problem_spec.rb +++ b/spec/features/report_a_problem_spec.rb @@ -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 } @@ -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 diff --git a/spec/features/site_users_management_spec.rb b/spec/features/site_users_management_spec.rb index e18b72d71..ae9a3be39 100644 --- a/spec/features/site_users_management_spec.rb +++ b/spec/features/site_users_management_spec.rb @@ -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) } @@ -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