Skip to content

Commit

Permalink
Work around inconsistent button click in promotion order spec
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mamhoff committed Jun 11, 2024
1 parent e0c883b commit e87aa77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions admin/lib/solidus_admin/testing_support/feature_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
it "lists products", :js do
visit "/admin/orders"

ensure_js_is_ready

click_button "Filter"

within("div[role=search]") do
Expand Down

0 comments on commit e87aa77

Please sign in to comment.