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
This commit is contained in:
Jean-Baptiste Bellet
2022-02-15 14:58:36 +01:00
parent eeae67e2d0
commit e47198f1e5
2 changed files with 32 additions and 2 deletions

View File

@@ -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

View File

@@ -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