From 96d4ee3f4f8b4c82fa9aa2123e68d033e11b9193 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 17 Feb 2022 14:39:52 +0100 Subject: [PATCH 1/3] Extract to a method in the split checkout helper --- spec/support/split_checkout_helper.rb | 7 +++++++ spec/system/consumer/split_checkout_spec.rb | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/support/split_checkout_helper.rb b/spec/support/split_checkout_helper.rb index 7b6cafe8cf..24a80c50d6 100644 --- a/spec/support/split_checkout_helper.rb +++ b/spec/support/split_checkout_helper.rb @@ -46,4 +46,11 @@ module SplitCheckoutHelper click_button "Next - Payment method" expect(page).to have_button("Next - Order summary") end + + def expect_to_be_on_first_step + expect(page).to have_content("1 - Your details") + expect(page).to have_selector("div.checkout-tab.selected", text: "1 - Your details") + expect(page).to have_content("2 - Payment method") + expect(page).to have_content("3 - Order summary") + end end diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index bd9af52961..cd7e741d1c 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -103,10 +103,7 @@ describe "As a consumer, I want to checkout my order", js: true do it "should display the split checkout details page" do click_on "Checkout as guest" expect(page).to have_content distributor.name - expect(page).to have_content("1 - Your details") - expect(page).to have_selector("div.checkout-tab.selected", text: "1 - Your details") - expect(page).to have_content("2 - Payment method") - expect(page).to have_content("3 - Order summary") + expect_to_be_on_first_step end it "should display error when fields are empty" do From 3e857621431f778344a6a8ffd77dd014b16aa2df Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 17 Feb 2022 14:40:27 +0100 Subject: [PATCH 2/3] Create a test that test the redirection after the split checkout login Should be redirected on the first step --- spec/system/consumer/split_checkout_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index cd7e741d1c..774c753a0d 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -9,6 +9,7 @@ describe "As a consumer, I want to checkout my order", js: true do include StripeHelper include StripeStubs include PaypalHelper + include AuthenticationHelper let!(:zone) { create(:zone_with_member) } let(:supplier) { create(:supplier_enterprise) } @@ -93,6 +94,23 @@ describe "As a consumer, I want to checkout my order", js: true do visit checkout_path end + context "actually user has an account and wants to login", :debug do + let(:user) { create(:user) } + + it "should redirect to '/checkout/details' when user submit the login form" do + expect(page).to have_content("Ok, ready to checkout?") + + click_on "Login" + within ".login-modal" do + fill_in_and_submit_login_form(user) + end + + expect_logged_in + expect(page).not_to have_selector ".login-modal" + expect_to_be_on_first_step + end + end + it "should display the split checkout login/guest form" do expect(page).to have_content distributor.name expect(page).to have_content("Ok, ready to checkout?") From f47de4534648885b067e0725f97a5879b9b14bc8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 17 Feb 2022 14:41:12 +0100 Subject: [PATCH 3/3] Reference splitcheckout as a checkout redirect This stored in session value is used to redirect after login Update tests as well, thanks @filipefurtad0 ! :pray: --- app/controllers/application_controller.rb | 4 +++- app/controllers/split_checkout_controller.rb | 2 ++ spec/system/consumer/shopping/checkout_auth_spec.rb | 6 +----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b9a40dafe5..f0c8837017 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -62,7 +62,9 @@ class ApplicationController < ActionController::Base end def set_checkout_redirect - return unless URI(request.referer.to_s).path == main_app.checkout_path + referer_path = URI(request.referer.to_s).path + return unless referer_path == main_app.checkout_path || + referer_path == main_app.checkout_step_path(:details) session["spree_user_return_to"] = main_app.checkout_path end diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 013e99a2fe..f59e3672ff 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -16,6 +16,8 @@ class SplitCheckoutController < ::BaseController helper 'spree/orders' helper OrderHelper + before_action :set_checkout_redirect + def edit redirect_to_step unless params[:step] end diff --git a/spec/system/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index 79ecdae271..2cf34e76c6 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -66,12 +66,8 @@ describe "As a consumer I want to check out my cart", js: true do end context "and populating user details on (#{checkout_type})", if: checkout_type.eql?("split_checkout") do - it "currently redirects to the homepage" do - # currently redirects to the homepage due to bug #8894 - expect(page).to have_content("Logged in successfully") - end it "should allow proceeding to the next step" do - pending("bug fix for #8894") + expect(page).to have_content("Logged in successfully") click_button "Next - Payment method" expect(page).to have_button("Next - Order summary") end