Skip to content

Commit

Permalink
Fix 'Ship Order': integrating non regression spec
Browse files Browse the repository at this point in the history
 - removes the pending
 - add the click to go to the 'Order Details' page
   to check for the 'shipped' status
 - from enqueued to have_been_enqueued so the spec
   is flaky-free
  • Loading branch information
cyrillefr committed Apr 21, 2024
1 parent 1719646 commit 320b551
Showing 1 changed file with 20 additions and 38 deletions.
58 changes: 20 additions & 38 deletions spec/system/admin/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,19 @@ def new_order_with_distribution(distributor, order_cycle)
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)
find_button("Confirm").click
end

find_button("Cancel").click # closes modal as it is not automatic
expect(page).to have_selector('.reveal-modal', visible: false)
click_link('Order Details') unless subpage == 'Order Details'

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",
{ args: [order.shipment.id, { delivery: true }] })
end

it "ships the order without sending email" do
Expand All @@ -986,50 +992,26 @@ def new_order_with_distribution(distributor, order_cycle)

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)
find_button("Confirm").click
end

find_button("Cancel").click # closes modal as it is not automatic
expect(page).to have_selector('.reveal-modal', visible: false)
click_link('Order Details') unless subpage == 'Order Details'
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
end
end

it_behaves_like "ship order from dropdown", "Order Details"
context "pending examples" do
before { pending("#12369") }
it_behaves_like "ship order from dropdown", "Customer Details"
it_behaves_like "ship order from dropdown", "Payments"
it_behaves_like "ship order from dropdown", "Adjustments"
it_behaves_like "ship order from dropdown", "Invoices"
it_behaves_like "ship order from dropdown", "Return Authorizations"
end

context 'when not on the Order Details sub section' do
before do
click_link 'Customer Details'
end
it 'can ship order too' do
find('.ofn-drop-down').click
click_link 'Ship Order'

within ".reveal-modal" do
expect(page).to have_checked_field('Send a shipment/pick up ' \
'notification email to the customer.')
# no test of enqueued job since it can cause failures
# if the remainder of the spec is too fasr
find_button('Confirm').click
end

# the best & easiest way to close the modal without calling all the JS
find_button("Cancel").click
expect(order.reload.shipped?).to be true
click_link('Order Details')
expect(page).to have_text 'SHIPPED'
end
end
it_behaves_like "ship order from dropdown", "Customer Details"
it_behaves_like "ship order from dropdown", "Payments"
it_behaves_like "ship order from dropdown", "Adjustments"
it_behaves_like "ship order from dropdown", "Invoices"
it_behaves_like "ship order from dropdown", "Return Authorizations"
end

context "when an included variant has been deleted" do
Expand Down

0 comments on commit 320b551

Please sign in to comment.