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.
This commit is contained in:
Maikel Linke
2023-08-25 13:46:38 +10:00
parent 4be38ba8da
commit 233171a9ce
4 changed files with 15 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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