Merge pull request #11451 from mkllnk/flaky-voucher-specs

De-flake voucher specs by checking success
This commit is contained in:
Maikel
2023-08-28 11:16:43 +10:00
committed by GitHub
4 changed files with 19 additions and 44 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

@@ -699,52 +699,32 @@ 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)
end
shared_examples "adding voucher to the order" do
before do
fill_in "Enter voucher code", with: "some_code"
click_button("Apply")
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
fill_in "Enter voucher code", with: "some_code"
click_button("Apply")
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
fill_in "Enter voucher code", with: "some_code"
click_button("Apply")
expect(page).to have_content "No payment required"
click_button "Next - Order summary"
@@ -785,9 +765,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)