From e47198f1e5e6d26e2b3008f33a7cd92aa3c662d4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 15 Feb 2022 14:58:36 +0100 Subject: [PATCH] Handle both types of redirection One is based on the order step itself, the other is based on the current step passed through the params --- app/controllers/split_checkout_controller.rb | 14 ++++++++++++-- spec/system/consumer/split_checkout_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 013e99a2fe..e04c4214f1 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -17,7 +17,7 @@ class SplitCheckoutController < ::BaseController helper OrderHelper def edit - redirect_to_step unless params[:step] + redirect_to_step_based_on_order unless params[:step] end def update @@ -116,7 +116,7 @@ class SplitCheckoutController < ::BaseController @order_params ||= Checkout::Params.new(@order, params, spree_current_user).call end - def redirect_to_step + def redirect_to_step_based_on_order case @order.state when "cart", "address", "delivery" redirect_to checkout_step_path(:details) @@ -128,4 +128,14 @@ class SplitCheckoutController < ::BaseController redirect_to order_path(@order) end end + + def redirect_to_step + case params[:step] + when "details" + return redirect_to checkout_step_path(:payment) + when "payment" + return redirect_to checkout_step_path(:summary) + end + redirect_to_step_based_on_order + end end diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 91a98d0e3f..e5d932f581 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -425,6 +425,26 @@ describe "As a consumer, I want to checkout my order", js: true do end end end + + context "handle the navigation when the order is ready for confirmation" do + it "redirect to summary step" do + visit "/checkout" + + expect(page).to have_current_path checkout_step_path(:summary) + end + + it "handle the navigation between each step by clicking on tab or button to submit the form" do + visit checkout_step_path(:summary) + + click_on "Your details" + + expect(page).to have_current_path checkout_step_path(:details) + + click_on "Next - Payment method" + + expect(page).to have_current_path checkout_step_path(:payment) + end + end end end