From 78946f908a39a113989e9be35318747b248c7171 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 15 Feb 2022 23:23:31 +0000 Subject: [PATCH 1/2] Adds shared examples; sets conditional filters on test cases --- .../consumer/shopping/checkout_auth_spec.rb | 87 +++++++++++++------ 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/spec/system/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index f5e59dc738..26fa54c8bb 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -9,7 +9,7 @@ describe "As a consumer I want to check out my cart", js: true do include CheckoutRequestsHelper include UIComponentHelper - describe "using the checkout" do + describe "checking out" do let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } let(:supplier) { create(:supplier_enterprise) } let!(:order_cycle) { @@ -28,37 +28,70 @@ describe "As a consumer I want to check out my cart", js: true do add_product_to_cart order, product end - it "does not render the login form when logged in" do - login_as user - visit checkout_path - within "section[role='main']" do - expect(page).to have_no_content "Login" - expect(page).to have_checkout_details + shared_examples "with different checkout types" do |checkout_type| + context "on #{checkout_type}" do + it "does not render the login form when logged in" do + login_as user + visit checkout_path + within "section[role='main']" do + expect(page).to have_no_content "Login" + expect(page).to have_checkout_details + end + end + + it "renders the login buttons when logged out" do + visit checkout_path + within "section[role='main']" do + expect(page).to have_content "Login" + click_button "Login" + end + expect(page).to have_login_modal + end + + describe "logging in" do + before do + visit checkout_path + within("section[role='main']") { click_button "Login" } + expect(page).to have_login_modal + fill_in "Email", with: user.email + fill_in "Password", with: user.password + within(".login-modal") { click_button 'Login' } + end + + context "and populating user details on (#{checkout_type})", if: checkout_type.eql?("legacy_checkout") do + it "toggles the Details section" do + expect(page).to have_content "Your details" + page.find(:css, "i.ofn-i_052-point-down").click + end + 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") + click_button "Next - Payment method" + expect(page).to have_button("Next - Order summary") + end + end + end end end - it "renders the login buttons when logged out" do - visit checkout_path - within "section[role='main']" do - expect(page).to have_content "Login" - click_button "Login" + describe "shared examples" do + context "legacy checkout" do + it_behaves_like "with different checkout types", "legacy_checkout" end - expect(page).to have_login_modal - end - it "populates user details once logged in" do - visit checkout_path - within("section[role='main']") { click_button "Login" } - expect(page).to have_login_modal - fill_in "Email", with: user.email - fill_in "Password", with: user.password - within(".login-modal") { click_button 'Login' } - - expect(page).to have_content "Your details" - page.find(:css, "i.ofn-i_052-point-down").click - - expect(page).to have_field 'First Name', with: 'Foo' - expect(page).to have_field 'Last Name', with: 'Bar' + context "split checkout" do + before do + allow(Flipper).to receive(:enabled?).with(:split_checkout) { true } + allow(Flipper).to receive(:enabled?).with(:split_checkout, anything) { true } + end + include_examples "with different checkout types", "split_checkout" + end end context "using the guest checkout" do From 33969de371fc08da5daa9112a82389721fc0713e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 16 Feb 2022 11:41:00 +1100 Subject: [PATCH 2/2] Allow shared_examples to have more than 25 lines --- .rubocop_styleguide.yml | 3 ++- spec/system/consumer/shopping/checkout_auth_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.rubocop_styleguide.yml b/.rubocop_styleguide.yml index 411fae7022..0840c14fc5 100644 --- a/.rubocop_styleguide.yml +++ b/.rubocop_styleguide.yml @@ -202,7 +202,8 @@ Metrics/BlockLength: "namespace", "resource", "resources", - "scenario" + "scenario", + "shared_examples", ] Metrics/BlockNesting: diff --git a/spec/system/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index 26fa54c8bb..79ecdae271 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -57,14 +57,14 @@ describe "As a consumer I want to check out my cart", js: true do fill_in "Password", with: user.password within(".login-modal") { click_button 'Login' } end - + context "and populating user details on (#{checkout_type})", if: checkout_type.eql?("legacy_checkout") do it "toggles the Details section" do expect(page).to have_content "Your details" page.find(:css, "i.ofn-i_052-point-down").click end 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