diff --git a/app/views/split_checkout/_details.html.haml b/app/views/split_checkout/_details.html.haml index 60d6bc626f..cc70ef4181 100644 --- a/app/views/split_checkout/_details.html.haml +++ b/app/views/split_checkout/_details.html.haml @@ -74,6 +74,7 @@ - display_ship_address = false - ship_method_description = nil + - selected_shipping_method ||= @shipping_methods[0].id if @shipping_methods.length == 1 - @shipping_methods.each do |shipping_method| %div.checkout-input.checkout-input-radio = fields_for shipping_method do |shipping_method_form| diff --git a/app/views/split_checkout/_payment.html.haml b/app/views/split_checkout/_payment.html.haml index b85f1d468e..b9f6160e48 100644 --- a/app/views/split_checkout/_payment.html.haml +++ b/app/views/split_checkout/_payment.html.haml @@ -4,6 +4,7 @@ = t("split_checkout.step2.payment_method.title") - selected_payment_method = @order.payments&.with_state(:checkout)&.first&.payment_method_id + - selected_payment_method ||= available_payment_methods[0].id if available_payment_methods.length == 1 - available_payment_methods.each do |payment_method| %div.checkout-input.checkout-input-radio = f.radio_button :payment_method_id, payment_method.id, diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 74699e2dac..91a98d0e3f 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -201,6 +201,25 @@ describe "As a consumer, I want to checkout my order", js: true do end end end + + describe "pre-selecting a shipping method" do + it "preselect a shipping method if only one is available" do + order.distributor.update! shipping_methods: [free_shipping] + + visit checkout_step_path(:details) + + expect(page).to have_checked_field "shipping_method_#{free_shipping.id}" + end + + it "don't preselect a shipping method if more than one is available" do + order.distributor.update! shipping_methods: [free_shipping, shipping_with_fee] + + visit checkout_step_path(:details) + + expect(page).to have_field "shipping_method_#{free_shipping.id}", checked: false + expect(page).to have_field "shipping_method_#{shipping_with_fee.id}", checked: false + end + end end describe "not filling out delivery details" do @@ -242,6 +261,27 @@ describe "As a consumer, I want to checkout my order", js: true do end end + context "payment method step" do + let(:order) { create(:order_ready_for_payment, distributor: distributor) } + + it "preselect the payment method if only one is available" do + visit checkout_step_path(:payment) + + expect(page).to have_checked_field "payment_method_#{payment_method.id}" + end + + context "with more than one payment method" do + let!(:payment_method2) { create(:payment_method, distributors: [distributor]) } + + it "don't preselect the payment method if more than one is available" do + visit checkout_step_path(:payment) + + expect(page).to have_field "payment_method_#{payment_method.id}", checked: false + expect(page).to have_field "payment_method_#{payment_method2.id}", checked: false + end + end + end + context "summary step" do let(:order) { create(:order_ready_for_confirmation, distributor: distributor) }