From 01f870b818bd159f8a6848cb00616b94a5008f3d Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 9 Jan 2022 18:11:12 +0000 Subject: [PATCH] Adds coverage on ship_address_same_as_billing option --- spec/support/split_checkout_helper.rb | 9 ++++ spec/system/consumer/split_checkout_spec.rb | 47 ++++++++++++++++----- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/spec/support/split_checkout_helper.rb b/spec/support/split_checkout_helper.rb index 1fb8a1fcec..965cd0d252 100644 --- a/spec/support/split_checkout_helper.rb +++ b/spec/support/split_checkout_helper.rb @@ -44,4 +44,13 @@ module SplitCheckoutHelper select "New South Wales", from: "State" end end + + def fill_out(notes) + fill_in 'Any comments or special instructions?', with: "#{notes}" + end + + def proceed_to_payment + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") + end end diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 252fc97c74..55024208c3 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -154,23 +154,50 @@ describe "As a consumer, I want to checkout my order", js: true do end it "redirects the user to the Payment Method step" do - fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" - click_button "Next - Payment method" - expect(page).to have_current_path("/checkout/payment") + fill_out("SpEcIaL NoTeS") + proceed_to_payment end end - describe "selecting a delivery shipping method and submiting the form" do + describe "selecting a delivery method" do before do choose shipping_with_fee.name - uncheck "ship_address_same_as_billing" end - it "redirects the user to the Payment Method step" do - fill_out_shipping_address - fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" - click_button "Next - Payment method" - expect(page).to have_current_path("/checkout/payment") + context "with same shipping and billing address" do + before do + check "ship_address_same_as_billing" + end + + it "does not display the shipping address form" do + within(:xpath, './/div[@class="checkout-substep"][3]') do + expect(page).not_to have_field "order_ship_address_attributes_address1" + end + end + + it "redirects the user to the Payment Method step, when submiting the form" do + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") + end + end + + context "with different shipping and billing address" do + before do + uncheck "ship_address_same_as_billing" + end + + it "displays the shipping address form" do + within(:xpath, './/div[@class="checkout-substep"][3]') do + expect(page).to have_field "order_ship_address_attributes_address1" + end + end + + it "fills in shipping details and redirects the user to the Payment Method step, + when submiting the form" do + fill_out_shipping_address + fill_out("SpEcIaL NoTeS") + proceed_to_payment + end end end end