From fc2515eac1e224fa6e49b69b42489f1c7e6e3a41 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 6 Mar 2025 17:16:43 +1100 Subject: [PATCH] Make sure the first page load is complete before updating database --- .../consumer/caching/shops_caching_spec.rb | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/spec/system/consumer/caching/shops_caching_spec.rb b/spec/system/consumer/caching/shops_caching_spec.rb index d9cda44d54..66b60415cd 100644 --- a/spec/system/consumer/caching/shops_caching_spec.rb +++ b/spec/system/consumer/caching/shops_caching_spec.rb @@ -95,23 +95,33 @@ RSpec.describe "Shops caching", caching: true do Timecop.travel(10.minutes.ago) do visit enterprise_shop_path(distributor) - expect(page).to have_content taxon.name - expect(page).to have_content property.presentation + # The page HTML contains the cached text but we need to test for the + # visible filters which are loaded asynchronously. + # Otherwise we may update the database before the AJAX requests + # and cache the new data. + within(".sticky-shop-filters-container", text: "Filter by") do + expect(page).to have_content taxon.name + expect(page).to have_content property.presentation + end variant.update_attribute(:primary_taxon, taxon2) product.update_attribute(:properties, [property2]) visit enterprise_shop_path(distributor) - expect(page).to have_content taxon.name # Taxon list is unchanged - expect(page).to have_content property.presentation # Property list is unchanged + within(".sticky-shop-filters-container", text: "Filter by") do + expect(page).to have_content taxon.name # Taxon list is unchanged + expect(page).to have_content property.presentation # Property list is unchanged + end end # A while later... visit enterprise_shop_path(distributor) - expect(page).to have_content taxon2.name - expect(page).to have_content property2.presentation + within(".sticky-shop-filters-container", text: "Filter by") do + expect(page).to have_content taxon2.name + expect(page).to have_content property2.presentation + end end end