From e87aa77f2b1be542544881db5e843f6c6cbb40b3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Mon, 10 Jun 2024 14:14:07 +0200 Subject: [PATCH] Work around inconsistent button click in promotion order spec Apparently, `find_button(...).click` will not consistently wait for the Javascript imported via importmaps to be loaded before execution. This adds a helper that executes a bit of Javascript that adds some data to the body element of the page after waiting for a minute amount of time, and then waits for this data to actually appear in the DOM. See https://gist.github.com/adrienpoly/862846f5882796fdeb4fc85b260b3c5a for a similar solution. This unfortunately adds code to the production build that's only needed for testing. --- .../lib/solidus_admin/testing_support/feature_helpers.rb | 9 +++++++++ .../spec/features/solidus_admin/orders/index_spec.rb | 2 ++ 2 files changed, 11 insertions(+) diff --git a/admin/lib/solidus_admin/testing_support/feature_helpers.rb b/admin/lib/solidus_admin/testing_support/feature_helpers.rb index 1547590eb8..f101532647 100644 --- a/admin/lib/solidus_admin/testing_support/feature_helpers.rb +++ b/admin/lib/solidus_admin/testing_support/feature_helpers.rb @@ -29,6 +29,15 @@ def find_row_checkbox(text) def select_row(text) find_row_checkbox(text).check end + + def ensure_js_is_ready + page.execute_script <<~JS + requestAnimationFrame(() => { + document.querySelector("body").dataset.jsLoaded = true + } + JS + expect(page).to have_css('[data-js-loaded="true"]') + end end end end diff --git a/legacy_promotions/spec/features/solidus_admin/orders/index_spec.rb b/legacy_promotions/spec/features/solidus_admin/orders/index_spec.rb index 3dec15fffc..8897c69a4e 100644 --- a/legacy_promotions/spec/features/solidus_admin/orders/index_spec.rb +++ b/legacy_promotions/spec/features/solidus_admin/orders/index_spec.rb @@ -12,6 +12,8 @@ it "lists products", :js do visit "/admin/orders" + ensure_js_is_ready + click_button "Filter" within("div[role=search]") do