From 4f9651f5c94ff026c62c0ec9b7f886efb75efb46 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 25 Aug 2023 14:52:50 +1000 Subject: [PATCH 1/2] Wait for pagination message to update Hopefully this fixes openfoodfoundation/openfoodnetwork#11328 --- spec/system/admin/products_v3/products_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index b0e98484c4..6e9a5c1fff 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -53,6 +53,8 @@ describe 'As an admin, I can see the new product page' do within ".pagination" do click_link "2" end + + expect(page).to have_content "Showing 16 to 30" expect_page_to_be 2 expect_per_page_to_be 15 expect_products_count_to_be 15 @@ -60,6 +62,8 @@ describe 'As an admin, I can see the new product page' do it "can change the number of products per page" do select "50", from: "per_page" + + expect(page).to have_content "Showing 1 to 50" expect_page_to_be 1 expect_per_page_to_be 50 expect_products_count_to_be 50 @@ -79,6 +83,7 @@ describe 'As an admin, I can see the new product page' do search_for "searchable product" expect(page).to have_field "search_term", with: "searchable product" + # expect(page).to have_content "1 product found for your search criteria." expect_products_count_to_be 1 end @@ -86,21 +91,26 @@ describe 'As an admin, I can see the new product page' do within ".pagination" do click_link "2" end + + expect(page).to have_content "Showing 16 to 30" expect_page_to_be 2 expect_per_page_to_be 15 expect_products_count_to_be 15 search_for "searchable product" + # expect(page).to have_content "1 product found for your search criteria." expect_products_count_to_be 1 end it "can clear filters" do search_for "searchable product" expect(page).to have_field "search_term", with: "searchable product" + # expect(page).to have_content "1 product found for your search criteria." expect_products_count_to_be 1 expect(page).to have_field "Name", with: product_by_name.name click_link "Clear search" expect(page).to have_field "search_term", with: "" + expect(page).to have_content "Showing 1 to 15" expect_page_to_be 1 expect_products_count_to_be 15 end @@ -120,6 +130,7 @@ describe 'As an admin, I can see the new product page' do it "can search for a product" do search_by_producer "Producer 1" + # expect(page).to have_content "1 product found for your search criteria." expect(page).to have_select "producer_id", selected: "Producer 1" expect_products_count_to_be 1 end @@ -134,6 +145,7 @@ describe 'As an admin, I can see the new product page' do it "can search for a product" do search_by_category "Category 1" + # expect(page).to have_content "1 product found for your search criteria." expect(page).to have_select "category_id", selected: "Category 1" expect_products_count_to_be 1 expect(page).to have_field "Name", with: product_by_category.name From 4d79cdb0eadfd1b9c5f068a11cb1ea4dc2d683a1 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 25 Aug 2023 15:44:54 +1000 Subject: [PATCH 2/2] Ensure records are created before visiting the page 'let!' is executed in the same way as 'before', so it matters which order they are defined in. For contexts with a single example, I just put it straight into the example. --- spec/system/admin/products_v3/products_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 6e9a5c1fff..b18a452e04 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -71,14 +71,14 @@ describe 'As an admin, I can see the new product page' do end describe "search" do - before do - visit admin_products_v3_index_url - end - context "product has searchable term" do # create a product with a name that can be searched let!(:product_by_name) { create(:simple_product, name: "searchable product") } + before do + visit admin_products_v3_index_url + end + it "can search for a product" do search_for "searchable product" @@ -128,6 +128,8 @@ describe 'As an admin, I can see the new product page' do let!(:product_by_supplier) { create(:simple_product, supplier: producer) } it "can search for a product" do + visit admin_products_v3_index_url + search_by_producer "Producer 1" # expect(page).to have_content "1 product found for your search criteria." @@ -143,6 +145,8 @@ describe 'As an admin, I can see the new product page' do } it "can search for a product" do + visit admin_products_v3_index_url + search_by_category "Category 1" # expect(page).to have_content "1 product found for your search criteria."