Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RfC: Work around inconsistent button click in promotion order spec #5782

Closed
wants to merge 3 commits into from

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jun 10, 2024

Apparently, find_button(...).click will not consistently wait for the
Stimulus JS to be loaded. This adds a small controller that simply
changes an attribute on the body, and expects that to be present before
running any feature specs.

See https://gist.github.com/adrienpoly/862846f5882796fdeb4fc85b260b3c5a

for inspiration.

I don't love to introduce code into the production build to get the tests stable, but I haven't found another good option that worked.

@github-actions github-actions bot added the changelog:repository Changes to the repository not within any gem label Jun 10, 2024
@mamhoff mamhoff force-pushed the fix-flaky-orders-index-spec branch 2 times, most recently from b3802d3 to 75382c5 Compare June 10, 2024 15:36
@github-actions github-actions bot added changelog:solidus_admin and removed changelog:repository Changes to the repository not within any gem labels Jun 10, 2024
Copy link

codecov bot commented Jun 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.71%. Comparing base (dc780f6) to head (46888aa).
Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5782   +/-   ##
=======================================
  Coverage   88.71%   88.71%           
=======================================
  Files         712      712           
  Lines       16893    16895    +2     
=======================================
+ Hits        14987    14989    +2     
  Misses       1906     1906           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mamhoff mamhoff force-pushed the fix-flaky-orders-index-spec branch from 75382c5 to 60fe006 Compare June 10, 2024 15:46
@mamhoff mamhoff marked this pull request as ready for review June 11, 2024 09:17
@mamhoff mamhoff requested a review from a team as a code owner June 11, 2024 09:17
@mamhoff mamhoff force-pushed the fix-flaky-orders-index-spec branch 2 times, most recently from e87aa77 to 97121d5 Compare June 11, 2024 15:49
@mamhoff mamhoff force-pushed the fix-flaky-orders-index-spec branch from 97121d5 to b9493da Compare June 12, 2024 07:11
It's cumbersome to find elements by CSS selectors to click them, and the
new admin has a few instances where we have no standalone label.
Apparently, `find_button(...).click` will not consistently wait for the
Javascript imported via importmaps to be loaded before execution. This
adds a Controller that adds a data attribute to the body element of the
page once it connects. This way we know the Stimulus controllers have
loaded before testing their behavior in feature specs.

See https://gist.github.com/adrienpoly/862846f5882796fdeb4fc85b260b3c5a
for a similar solution.

I am not a big fan of adding production code just to get specs stable,
but this is the only solution I found that reliably works.
I'm getting a code coverage issue because the `ensure_js_is_ready`
helper is only used in the `solidus_leagcy_promotions`. Adding a spec
here for filtering by payment state.
@mamhoff mamhoff force-pushed the fix-flaky-orders-index-spec branch from b9493da to 46888aa Compare June 12, 2024 07:20
mamhoff added a commit to mamhoff/solidus that referenced this pull request Jun 12, 2024
We need to wait for the JS to be loaded and connected here, otherwise
the click doesn't do anything. There is an alternative fix for this in
solidusio#5782
mamhoff added a commit to mamhoff/solidus that referenced this pull request Jun 12, 2024
This will keep clicking the Filter button until the promotions menu
appears. The problem this fixes is that a few milliseconds after
navigation, the JS controller that switches the filter bar out might not
have loaded.

Alternative fixes here:
solidusio#5782
solidusio#5783
@mamhoff
Copy link
Contributor Author

mamhoff commented Jun 12, 2024

I'm keeping this open to see how folks feel about it. We can't keep adding sleep statements to specs forever.

@mamhoff mamhoff changed the title Work around inconsistent button click in promotion order spec RfC: Work around inconsistent button click in promotion order spec Jun 12, 2024
@kennyadsl
Copy link
Member

Thanks for taking the time here @mamhoff, I've also tried multiple times to fix this spec, without success.

If we can't find an "elegant" solution, may I suggest to use the flaky tag on the test? It will retry it a couple of times, making it transparent for us. Not great, but it won't slow us down at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants