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

Fix flaky spec of order shipment #13091

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
49 changes: 24 additions & 25 deletions spec/system/admin/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -956,36 +956,37 @@ def new_order_with_distribution(distributor, order_cycle)
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|
Expand All @@ -1004,11 +1005,10 @@ def new_order_with_distribution(distributor, order_cycle)
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",
Expand All @@ -1030,9 +1030,8 @@ def new_order_with_distribution(distributor, order_cycle)
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
Expand Down
Loading