From 29ef444f36f72d7a246e24c97a603d05c81ad8ff Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 8 Dec 2023 09:44:44 +1100 Subject: [PATCH] Consolidate system specs for efficiency And test for literal strings. It's more readable and robust. --- spec/system/consumer/checkout/details_spec.rb | 10 ++++------ spec/system/consumer/checkout/payment_spec.rb | 18 +++++------------- spec/system/consumer/checkout/summary_spec.rb | 13 ++++--------- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/spec/system/consumer/checkout/details_spec.rb b/spec/system/consumer/checkout/details_spec.rb index eb7a4fe423..d44b0cc2ad 100644 --- a/spec/system/consumer/checkout/details_spec.rb +++ b/spec/system/consumer/checkout/details_spec.rb @@ -389,6 +389,10 @@ describe "As a consumer, I want to checkout my order" do end it "pre-fills address details" do + # Check for the right title first. This is a random place here but + # we don't have a standard success checkout flow case to add this to. + expect(page).to have_title "Checkout Details - Open Food Network" + visit checkout_path expect(page).to have_select( "order_bill_address_attributes_state_id", selected: "Testville" @@ -396,12 +400,6 @@ describe "As a consumer, I want to checkout my order" do expect(page).to have_field "order_bill_address_attributes_zipcode", with: "TST01" end end - - describe "show page title as Checkout Details - Open Food Network" do - it "should display title as Checkout Details - Open Food Network" do - expect(page).to have_title "Checkout Details - Open Food Network" - end - end end end end diff --git a/spec/system/consumer/checkout/payment_spec.rb b/spec/system/consumer/checkout/payment_spec.rb index 4cf612a4ff..65f18d271b 100644 --- a/spec/system/consumer/checkout/payment_spec.rb +++ b/spec/system/consumer/checkout/payment_spec.rb @@ -62,14 +62,12 @@ describe "As a consumer, I want to checkout my order" do let(:order) { create(:order_ready_for_payment, distributor:) } context "with one payment method, with a fee" do - before do - visit checkout_step_path(:payment) - end it "preselect the payment method if only one is available" do - expect(page).to have_checked_field "payment_method_#{payment_with_fee.id}" - end - it "displays the transaction fee" do - expect(page).to have_content("#{payment_with_fee.name} " + with_currency(1.23).to_s) + visit checkout_step_path(:payment) + + expect(page).to have_title "Checkout Payment - Open Food Network" + expect(page).to have_checked_field "Payment with Fee" + expect(page).to have_content "Payment with Fee $1.23" end end @@ -331,12 +329,6 @@ describe "As a consumer, I want to checkout my order" do end end end - - describe "show page title as Checkout Payment - Open Food Network" do - it "should display title as Checkout Payment - Open Food Network" do - expect(page).to have_title "Checkout Payment - Open Food Network" - end - end end end diff --git a/spec/system/consumer/checkout/summary_spec.rb b/spec/system/consumer/checkout/summary_spec.rb index e4d231fd0b..2f2767d7dd 100644 --- a/spec/system/consumer/checkout/summary_spec.rb +++ b/spec/system/consumer/checkout/summary_spec.rb @@ -66,15 +66,16 @@ describe "As a consumer, I want to checkout my order" do visit checkout_step_path(:summary) end - it "displays the ship address" do + it "displays title and ship address" do + expect(page).to have_title "Checkout Summary - Open Food Network" + expect(page).to have_content "Delivery address" expect(page).to have_content order.ship_address.address1 expect(page).to have_content order.ship_address.city expect(page).to have_content order.ship_address.zipcode expect(page).to have_content order.ship_address.phone - end - it "and not the billing address" do + # but not the billing address expect(page).not_to have_content order.bill_address.address1 expect(page).not_to have_content order.bill_address.city expect(page).not_to have_content order.bill_address.zipcode @@ -404,12 +405,6 @@ describe "As a consumer, I want to checkout my order" do end end end - - describe "show page title as Checkout Summary - Open Food Network" do - it "should display title as Checkout Summary - Open Food Network" do - expect(page).to have_title "Checkout Summary - Open Food Network" - end - end end def add_voucher_to_order(voucher, order)