From 4be38ba8da20854257b3ca81a556ef39168bab7f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 25 Aug 2023 13:15:50 +1000 Subject: [PATCH 1/3] Remove redundant system spec System specs are expensive. And this spec just looked for the visibility of certain elements while other tests actually use them and therefore verify their function much more thoroughly. --- spec/system/consumer/split_checkout_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index d648476e20..658c641c4e 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -699,12 +699,6 @@ describe "As a consumer, I want to checkout my order" do create(:voucher_flat_rate, code: 'some_code', enterprise: distributor, amount: 15) end - it "shows voucher input" do - visit checkout_step_path(:payment) - expect(page).to have_field "Enter voucher code" - expect(page).to have_content "Apply voucher" - end - describe "adding voucher to the order" do before do visit checkout_step_path(:payment) From 233171a9cedc8b59dcc353a43e8af90a60d710b5 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 25 Aug 2023 13:46:38 +1000 Subject: [PATCH 2/3] De-flake voucher specs by checking success Vouchers are applied via a reflex and we need to check for success before trying to navigate further. The new helper does this in a consistent way. --- spec/support/split_checkout_helper.rb | 7 +++++++ spec/system/consumer/split_checkout_spec.rb | 13 ++++--------- .../system/consumer/split_checkout_tax_incl_spec.rb | 9 ++------- .../consumer/split_checkout_tax_not_incl_spec.rb | 9 ++------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/spec/support/split_checkout_helper.rb b/spec/support/split_checkout_helper.rb index d624178b6c..af4012c599 100644 --- a/spec/support/split_checkout_helper.rb +++ b/spec/support/split_checkout_helper.rb @@ -43,6 +43,13 @@ module SplitCheckoutHelper expect(page).to have_button("Next - Order summary") end + def apply_voucher(code) + expect(page).to have_content "Apply voucher" + fill_in "Enter voucher code", with: code + click_button "Apply" + expect(page).to have_link "Remove code" + 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") diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 658c641c4e..490ed63622 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -706,8 +706,7 @@ describe "As a consumer, I want to checkout my order" do shared_examples "adding voucher to the order" do before do - fill_in "Enter voucher code", with: "some_code" - click_button("Apply") + apply_voucher "some_code" end it "adds a voucher to the order" do @@ -727,8 +726,7 @@ describe "As a consumer, I want to checkout my order" do it_behaves_like "adding voucher to the order" it "shows a warning message" do - fill_in "Enter voucher code", with: "some_code" - click_button("Apply") + apply_voucher "some_code" expect(page).to have_content( "Note: if your order total is less than your voucher " \ @@ -737,8 +735,7 @@ describe "As a consumer, I want to checkout my order" do end it "proceeds without requiring payment" do - fill_in "Enter voucher code", with: "some_code" - click_button("Apply") + apply_voucher "some_code" expect(page).to have_content "No payment required" click_button "Next - Order summary" @@ -779,9 +776,7 @@ describe "As a consumer, I want to checkout my order" do end it "can re-enter a voucher" do - # Re-enter a voucher code - fill_in "Enter voucher code", with: "some_code" - click_button("Apply") + apply_voucher "some_code" expect(page).to have_content("$15.00 Voucher") expect(order.reload.voucher_adjustments.length).to eq(1) diff --git a/spec/system/consumer/split_checkout_tax_incl_spec.rb b/spec/system/consumer/split_checkout_tax_incl_spec.rb index f2aa3f281a..c1657070e1 100644 --- a/spec/system/consumer/split_checkout_tax_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_incl_spec.rb @@ -122,10 +122,7 @@ describe "As a consumer, I want to see adjustment breakdown" do click_button "Next - Payment method" - # add Voucher - fill_in "Enter voucher code", with: "some_code" - click_button("Apply") - expect(page).to have_link "Remove code" + apply_voucher "some_code" # Choose payment click_on "Next - Order summary" @@ -155,9 +152,7 @@ describe "As a consumer, I want to see adjustment breakdown" do visit checkout_step_path(:details) proceed_to_payment - # add Voucher - fill_in "Enter voucher code", with: "good_code" - click_button("Apply") + apply_voucher "good_code" proceed_to_summary diff --git a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb index 09bc8e48f4..d07dddfa41 100644 --- a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb @@ -128,10 +128,7 @@ describe "As a consumer, I want to see adjustment breakdown" do click_button "Next - Payment method" - # add Voucher - fill_in "Enter voucher code", with: "some_code" - click_button("Apply") - expect(page).to have_selector ".voucher-added" + apply_voucher "some_code" click_on "Next - Order summary" click_on "Complete order" @@ -163,9 +160,7 @@ describe "As a consumer, I want to see adjustment breakdown" do visit checkout_step_path(:details) proceed_to_payment - # add Voucher - fill_in "Enter voucher code", with: voucher.code - click_button("Apply") + apply_voucher voucher.code proceed_to_summary assert_db_voucher_adjustment(-2.00, -0.26) From 1a95476634df26fc233c34855990b0e15cfed81c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 25 Aug 2023 13:55:33 +1000 Subject: [PATCH 3/3] Combine some voucher system specs to save time It also simplifies the spec code a bit not having a shared example. --- spec/system/consumer/split_checkout_spec.rb | 23 ++++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 490ed63622..1ee0350fae 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -704,38 +704,27 @@ describe "As a consumer, I want to checkout my order" do visit checkout_step_path(:payment) end - shared_examples "adding voucher to the order" do - before do - apply_voucher "some_code" - end + it "adds a voucher to the order" do + apply_voucher "some_code" - it "adds a voucher to the order" do - expect(page).to have_content("$15.00 Voucher") - expect(order.reload.voucher_adjustments.length).to eq(1) - end + expect(page).to have_content "$15.00 Voucher" + expect(order.reload.voucher_adjustments.length).to eq(1) end - it_behaves_like "adding voucher to the order" - context "when voucher covers more then the order total" do before do order.total = 6 order.save! end - it_behaves_like "adding voucher to the order" - - it "shows a warning message" do + it "shows a warning message and doesn't require payment" do apply_voucher "some_code" + expect(page).to have_content "$15.00 Voucher" expect(page).to have_content( "Note: if your order total is less than your voucher " \ "you may not be able to spend the remaining value." ) - end - - it "proceeds without requiring payment" do - apply_voucher "some_code" expect(page).to have_content "No payment required" click_button "Next - Order summary"