diff --git a/app/views/split_checkout/_details.html.haml b/app/views/split_checkout/_details.html.haml index cc70ef4181..d7c7cdbda5 100644 --- a/app/views/split_checkout/_details.html.haml +++ b/app/views/split_checkout/_details.html.haml @@ -89,7 +89,7 @@ = shipping_method_form.label shipping_method.id, shipping_method.name, {for: "shipping_method_" + shipping_method.id.to_s } %em.light = payment_or_shipping_price(shipping_method, @order) - - display_ship_address = (shipping_method.id == selected_shipping_method.to_i && shipping_method.require_ship_address) + - display_ship_address = display_ship_address || (shipping_method.id == selected_shipping_method.to_i && shipping_method.require_ship_address) - if shipping_method.id == selected_shipping_method.to_i - ship_method_description = shipping_method.description diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index eb7283bb9b..26844d7eb4 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -32,6 +32,9 @@ describe "As a consumer, I want to checkout my order", js: true do let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) } let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) } + let(:free_shipping_with_required_address) { + create(:shipping_method, require_ship_address: true, name: "A Free Shipping with required address") + } let(:free_shipping) { create(:shipping_method, require_ship_address: false, name: "Free Shipping", description: "yellow", calculator: Calculator::FlatRate.new(preferred_amount: 0.00)) @@ -43,6 +46,9 @@ describe "As a consumer, I want to checkout my order", js: true do name: "Shipping with Fee", description: "blue", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) } + let(:free_shipping_without_required_address) { + create(:shipping_method, require_ship_address: false, name: "Z Free Shipping without required address") + } let!(:payment_with_fee) { create(:payment_method, distributors: [distributor], name: "Payment with Fee", description: "Payment with fee", @@ -56,8 +62,7 @@ describe "As a consumer, I want to checkout my order", js: true do add_enterprise_fee enterprise_fee set_order order - distributor.shipping_methods << free_shipping - distributor.shipping_methods << shipping_with_fee + distributor.shipping_methods = [free_shipping_with_required_address, free_shipping, shipping_with_fee, free_shipping_without_required_address] end context "guest checkout when distributor doesn't allow guest orders" do @@ -186,6 +191,19 @@ describe "As a consumer, I want to checkout my order", js: true do end context "details step" do + context "when form is submitted but invalid" do + it "display the checkbox about shipping address same as billing address when selecting a shipping method that requires ship address" do + choose free_shipping_with_required_address.name + check "Shipping address same as billing address?" + + click_button "Next - Payment method" + + expect(page).to have_content "Saving failed, please update the highlighted fields." + expect(page).to have_content "Shipping address same as billing address?" + expect(page).to have_checked_field "Shipping address same as billing address?" + end + end + describe "filling out delivery details" do before do fill_out_details