From 999440da0ad0fa7ed8cfe6b0066e47a077698a4f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 26 Jan 2023 11:05:55 +0100 Subject: [PATCH 1/2] Fix errors count when user submit the form Since https://github.com/openfoodfoundation/openfoodnetwork/pull/10317 we are displaying the error message also in the flash message. For unknown reason, build didn't fail for that PR, but, as the PR adds some error message, we need to change the spec to reflect that change. This PR separates error in checkout page itself, and errors in flash message banner. --- spec/system/consumer/split_checkout_spec.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index cf0e405847..4cf6d4f917 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -489,7 +489,12 @@ describe "As a consumer, I want to checkout my order" do expect(page).to have_field("Address", with: "") expect(page).to have_field("City", with: "") expect(page).to have_field("Postcode", with: "") - expect(page).to have_content("can't be blank", count: 3) + within "checkout" do + expect(page).to have_content("can't be blank", count: 3) + end + within ".flash[type='error']" do + expect(page).to have_content("can't be blank", count: 3) + end end it "fills in shipping details and redirects the user to the Payment Method step, @@ -541,7 +546,13 @@ describe "As a consumer, I want to checkout my order" do expect(page).to have_field("Address", with: "") expect(page).to have_field("City", with: "") expect(page).to have_field("Postcode", with: "") - expect(page).to have_content("can't be blank", count: 7) + within "checkout" do + expect(page).to have_content("can't be blank", count: 7) + end + within ".flash[type='error']" do + expect(page).to have_content("can't be blank", count: 13) + expect(page).to have_content("is invalid", count: 1) + end expect(page).to have_content("Select a shipping method") end end From e48ba1b5fac90f4f4b70f00b59289cf52a1c7552 Mon Sep 17 00:00:00 2001 From: jibees Date: Thu, 26 Jan 2023 14:54:23 +0100 Subject: [PATCH 2/2] Specify assertions by grouping them into page section Co-Authored-By: Filipe <49817236+filipefurtad0@users.noreply.github.com> --- spec/system/consumer/split_checkout_spec.rb | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 4cf6d4f917..e40cae8a5d 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -485,14 +485,14 @@ describe "As a consumer, I want to checkout my order" do it "displays error messages when submitting incomplete billing address" do click_button "Next - Payment method" - expect(page).to have_content "Saving failed, please update the highlighted fields." - expect(page).to have_field("Address", with: "") - expect(page).to have_field("City", with: "") - expect(page).to have_field("Postcode", with: "") within "checkout" do + expect(page).to have_field("Address", with: "") + expect(page).to have_field("City", with: "") + expect(page).to have_field("Postcode", with: "") expect(page).to have_content("can't be blank", count: 3) end within ".flash[type='error']" do + expect(page).to have_content "Saving failed, please update the highlighted fields." expect(page).to have_content("can't be blank", count: 3) end end @@ -537,23 +537,23 @@ describe "As a consumer, I want to checkout my order" do end it "should display error when fields are empty" do click_button "Next - Payment method" - expect(page).to have_content("Saving failed, please update the highlighted fields") - expect(page).to have_field("First Name", with: "") - expect(page).to have_field("Last Name", with: "") - expect(page).to have_field("Email", with: "") - expect(page).to have_content("is invalid") - expect(page).to have_field("Phone number", with: "") - expect(page).to have_field("Address", with: "") - expect(page).to have_field("City", with: "") - expect(page).to have_field("Postcode", with: "") within "checkout" do + expect(page).to have_field("First Name", with: "") + expect(page).to have_field("Last Name", with: "") + expect(page).to have_field("Email", with: "") + expect(page).to have_content("is invalid") + expect(page).to have_field("Phone number", with: "") + expect(page).to have_field("Address", with: "") + expect(page).to have_field("City", with: "") + expect(page).to have_field("Postcode", with: "") expect(page).to have_content("can't be blank", count: 7) + expect(page).to have_content("Select a shipping method") end within ".flash[type='error']" do + expect(page).to have_content("Saving failed, please update the highlighted fields") expect(page).to have_content("can't be blank", count: 13) expect(page).to have_content("is invalid", count: 1) end - expect(page).to have_content("Select a shipping method") end end