From cafa17ec13e6efee37f0c26d09860c3101f37ba9 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 29 Sep 2022 16:38:34 +0100 Subject: [PATCH 1/6] Splits test into two assertions --- .../system/consumer/shopping/shopping_spec.rb | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index 823018143b..591562b992 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -166,28 +166,37 @@ describe "As a consumer I want to shop with a distributor", js: true do end end - describe "two order cycles and more than 20 products for each" do + describe "two order cycles" do before do - 20.times do - product = create(:simple_product, supplier: supplier) - add_variant_to_order_cycle(exchange1, product.variants.first) - add_variant_to_order_cycle(exchange2, product.variants.first) + visit shop_path + end + context "one having 20 products" do + before do + 20.times do + product = create(:simple_product, supplier: supplier) + add_variant_to_order_cycle(exchange1, product.variants.first) + end + end + it "displays 20 products, 10 per page" do + select "frogs", from: "order_cycle_id" + expect(page).to have_selector("product.animate-repeat", count: 10) + scroll_to(page.find(".product-listing"), align: :bottom) + expect(page).to have_selector("product.animate-repeat", count: 20) end end - it "show the whole products list for each OC" do - visit shop_path - select "turtles", from: "order_cycle_id" - select "frogs", from: "order_cycle_id" - expect(page).to have_selector("product.animate-repeat", count: 10) - scroll_to(page.find(".product-listing"), align: :bottom) - expect(page).to have_selector("product.animate-repeat", count: 20) + context "another having 5 products" do + before do + 5.times do + product = create(:simple_product, supplier: supplier) + add_variant_to_order_cycle(exchange2, product.variants.first) + end + end - scroll_to(page.find("distributor")) - select "turtles", from: "order_cycle_id" - expect(page).to have_selector("product.animate-repeat", count: 10) - scroll_to(page.find(".product-listing"), align: :bottom) - expect(page).to have_selector("product.animate-repeat", count: 20) + it "displays 5 products, on one page" do + select "turtles", from: "order_cycle_id" + expect(page).to have_selector("product.animate-repeat", count: 5) + end end end end From fa05327342ff904c6f0afef7c64e3bbfdf917c64 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 29 Sep 2022 17:26:58 +0100 Subject: [PATCH 2/6] Adds assertions on clearing searches Asserts on page contents --- spec/system/consumer/shopping/shopping_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index 591562b992..a3d47f3ddd 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -31,7 +31,6 @@ describe "As a consumer I want to shop with a distributor", js: true do it "shows a distributor with images" do # Given the distributor has a logo distributor.update!(logo: white_logo_file) - # Then we should see the distributor and its logo visit shop_path expect(page).to have_text distributor.name @@ -239,15 +238,19 @@ describe "As a consumer I want to shop with a distributor", js: true do expect(page).to have_price with_currency(43.00) end - it "filters search results properly" do + it "filters search results properly and clears searches" do visit shop_path fill_in "search", with: "74576345634XXXXXX" expect(page).to have_content "Sorry, no results found" expect(page).not_to have_content product2.name + click_on "Clear search" # clears search by clicking text + expect(page).to have_content("Add", count: 4) - fill_in "search", with: "Meer" # For product named "Meercats" + fill_in "search", with: "Meer" # For product named "Meercats" expect(page).to have_content product2.name expect(page).not_to have_content product.name + find("a.clear").click # clears search by clicking the X button + expect(page).to have_content("Add", count: 4) end context "when supplier uses property" do @@ -276,7 +279,7 @@ describe "As a consumer I want to shop with a distributor", js: true do it "returns search results for products where the search term matches one of the product's variant names" do visit shop_path - fill_in "search", with: "Badg" # For variant with display_name "Badgers" + fill_in "search", with: "Badg" # For variant with display_name "Badgers" within('div.pad-top') do expect(page).not_to have_content product2.name From 8e6f828f66f39a8bcd214985da56dca61f18f0a1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 3 Oct 2022 19:29:30 +0100 Subject: [PATCH 3/6] Splits it cases into respective contexts --- .../system/consumer/shopping/shopping_spec.rb | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index a3d47f3ddd..4c7fc25d00 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -219,38 +219,44 @@ describe "As a consumer I want to shop with a distributor", js: true do order.order_cycle = oc1 end - it "uses the adjusted price" do - enterprise_fee1 = create(:enterprise_fee, amount: 20) - enterprise_fee2 = create(:enterprise_fee, amount: 3) - exchange.enterprise_fees = [enterprise_fee1, enterprise_fee2] - exchange.save - visit shop_path + context "adjusting the price" do + before do + enterprise_fee1 = create(:enterprise_fee, amount: 20) + enterprise_fee2 = create(:enterprise_fee, amount: 3) + exchange.enterprise_fees = [enterprise_fee1, enterprise_fee2] + exchange.save + visit shop_path + end + it "displays the correct price" do + # Page should not have product.price (with or without fee) + expect(page).not_to have_price with_currency(10.00) + expect(page).not_to have_price with_currency(33.00) - # Page should not have product.price (with or without fee) - expect(page).not_to have_price with_currency(10.00) - expect(page).not_to have_price with_currency(33.00) + # Page should have variant prices (with fee) + expect(page).to have_price with_currency(43.00) + expect(page).to have_price with_currency(53.00) - # Page should have variant prices (with fee) - expect(page).to have_price with_currency(43.00) - expect(page).to have_price with_currency(53.00) - - # Product price should be listed as the lesser of these - expect(page).to have_price with_currency(43.00) + # Product price should be listed as the lesser of these + expect(page).to have_price with_currency(43.00) + end end - it "filters search results properly and clears searches" do - visit shop_path - fill_in "search", with: "74576345634XXXXXX" - expect(page).to have_content "Sorry, no results found" - expect(page).not_to have_content product2.name - click_on "Clear search" # clears search by clicking text - expect(page).to have_content("Add", count: 4) - - fill_in "search", with: "Meer" # For product named "Meercats" - expect(page).to have_content product2.name - expect(page).not_to have_content product.name - find("a.clear").click # clears search by clicking the X button - expect(page).to have_content("Add", count: 4) + context "filtering search results" do + before { visit shop_path } + it "returns no results and clears searches by clicking the clear-link" do + fill_in "search", with: "74576345634XXXXXX" + expect(page).to have_content "Sorry, no results found" + expect(page).not_to have_content product2.name + click_on "Clear search" # clears search by clicking text + expect(page).to have_content("Add", count: 4) + end + it "returns results and clears searches by clicking the clear-button" do + fill_in "search", with: "Meer" # For product named "Meercats" + expect(page).to have_content product2.name + expect(page).not_to have_content product.name + find("a.clear").click # clears search by clicking the X button + expect(page).to have_content("Add", count: 4) + end end context "when supplier uses property" do From 7b592fd80b814dd7cbfe79eaa8acd7343fbeb1cc Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 4 Oct 2022 12:27:58 +0100 Subject: [PATCH 4/6] Adds assertion after page visit to promote page loading --- spec/system/consumer/shopping/shopping_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index 4c7fc25d00..c5a835f9be 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -242,8 +242,9 @@ describe "As a consumer I want to shop with a distributor", js: true do end context "filtering search results" do - before { visit shop_path } it "returns no results and clears searches by clicking the clear-link" do + visit shop_path + expect(page).to have_content product2.name fill_in "search", with: "74576345634XXXXXX" expect(page).to have_content "Sorry, no results found" expect(page).not_to have_content product2.name @@ -251,6 +252,8 @@ describe "As a consumer I want to shop with a distributor", js: true do expect(page).to have_content("Add", count: 4) end it "returns results and clears searches by clicking the clear-button" do + visit shop_path + expect(page).to have_content product2.name fill_in "search", with: "Meer" # For product named "Meercats" expect(page).to have_content product2.name expect(page).not_to have_content product.name From f4edfcefa27751f36a945a370c718a5e536c357f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 4 Oct 2022 20:17:14 +0100 Subject: [PATCH 5/6] Adds 2 sec sleep time --- spec/system/consumer/shopping/shopping_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index c5a835f9be..dc8cafbf40 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -244,7 +244,7 @@ describe "As a consumer I want to shop with a distributor", js: true do context "filtering search results" do it "returns no results and clears searches by clicking the clear-link" do visit shop_path - expect(page).to have_content product2.name + sleep(2) fill_in "search", with: "74576345634XXXXXX" expect(page).to have_content "Sorry, no results found" expect(page).not_to have_content product2.name @@ -253,7 +253,7 @@ describe "As a consumer I want to shop with a distributor", js: true do end it "returns results and clears searches by clicking the clear-button" do visit shop_path - expect(page).to have_content product2.name + sleep(2) fill_in "search", with: "Meer" # For product named "Meercats" expect(page).to have_content product2.name expect(page).not_to have_content product.name From 977916cb111cf431131f818f1e88fd8f29b0efb4 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 4 Oct 2022 20:58:30 +0100 Subject: [PATCH 6/6] Adds 2 sec sleep time on other flaky examples --- spec/system/consumer/shopping/shopping_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/system/consumer/shopping/shopping_spec.rb b/spec/system/consumer/shopping/shopping_spec.rb index dc8cafbf40..7c4e42749f 100644 --- a/spec/system/consumer/shopping/shopping_spec.rb +++ b/spec/system/consumer/shopping/shopping_spec.rb @@ -533,6 +533,7 @@ describe "As a consumer I want to shop with a distributor", js: true do context "when a variant is soft-deleted" do describe "adding the soft-deleted variant to the cart" do it "handles it as if the variant has gone out of stock" do + sleep(2) variant.delete click_add_to_cart variant @@ -548,6 +549,7 @@ describe "As a consumer I want to shop with a distributor", js: true do } it "handles it as if the variant has gone out of stock" do + sleep(2) variant.delete click_add_to_cart variant