From c975a2c8c4f5c5a3d855da24f174890f905d8069 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 22 Jan 2025 15:34:09 +1100 Subject: [PATCH] Fix flaky spec of order shipment I found that a delay in the reflex handling the request could fail the spec. Added a sleep in the reflex to reproduce the fail. The I added expectations for the page content to wait until the page was updated and that fixed the specs. --- spec/system/admin/order_spec.rb | 49 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 643c73d585..0ab9cbf13c 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -956,36 +956,37 @@ RSpec.describe ' end it "ships the order and shipment email is sent" do - expect(order.reload.shipped?).to be false + expect(page).to have_content "ready" + expect(page).not_to have_content "shipped" click_button 'Ship' - within ".reveal-modal" do - expect(page).to have_checked_field('Send a shipment/pick up ' \ - 'notification email to the customer.') - expect { - find_button("Confirm").click - }.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:once) - end - - expect(order.reload.shipped?).to be true - expect(page).to have_text 'SHIPPED' + expect { + within ".reveal-modal" do + expect(page).to have_checked_field( + 'Send a shipment/pick up notification email to the customer.' + ) + click_button "Confirm" + end + expect(page).to have_content "shipped" + }.to enqueue_mail + .and change { order.reload.shipped? }.to true end it "ships the order without sending email" do - expect(order.reload.shipped?).to be false + expect(page).to have_content "ready" + expect(page).not_to have_content "shipped" click_button 'Ship' - within ".reveal-modal" do - uncheck 'Send a shipment/pick up notification email to the customer.' - expect { - find_button("Confirm").click - }.not_to enqueue_job(ActionMailer::MailDeliveryJob) - end - - expect(order.reload.shipped?).to be true - expect(page).to have_text 'SHIPPED' + expect { + within ".reveal-modal" do + uncheck 'Send a shipment/pick up notification email to the customer.' + click_button "Confirm" + end + expect(page).to have_content "shipped" + }.to enqueue_mail.exactly(0).times + .and change { order.reload.shipped? }.to true end shared_examples "ship order from dropdown" do |subpage| @@ -1004,11 +1005,10 @@ RSpec.describe ' end expect(page).to have_selector('.reveal-modal', visible: false) + expect(page).to have_content "SHIPPED" click_link('Order Details') unless subpage == 'Order Details' - sleep(0.5) # avoid flakyness expect(order.reload.shipped?).to be true - expect(page).to have_text 'SHIPPED' expect(ActionMailer::MailDeliveryJob).to have_been_enqueued .exactly(:once) .with("Spree::ShipmentMailer", "shipped_email", "deliver_now", @@ -1030,9 +1030,8 @@ RSpec.describe ' expect(page).to have_selector('.reveal-modal', visible: false) click_link('Order Details') unless subpage == 'Order Details' - sleep(0.5) # avoir flakyness + expect(page).to have_content "SHIPPED" expect(order.reload.shipped?).to be true - expect(page).to have_text 'SHIPPED' expect(ActionMailer::MailDeliveryJob).not_to have_been_enqueued .with(array_including("Spree::ShipmentMailer")) end