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

Fix date picker being blank and jumpy when appearing #16650

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

cbliard
Copy link
Member

@cbliard cbliard commented Sep 6, 2024

It was in order to fix the flaky spec
spec/features/admin/working_days_spec.rb:189. The flakiness can be forced by adding a sleep 2 at the beginning of the test, just before the datepicker.open_modal! call.

Not absolutely sure why so many forced change detection calls are needed, but this way it seems to work. It seems to be related to having a lot of nested templates, outlets and ifs in templates which each time need a new change detection to be reevaluated. But I'm not an expert in this.

As a bonus there is no delay anymore in the drop modal initialization, which should lead to more stable tests. For instance execution time of spec/features/admin/working_days_spec.rb:189 dropped from 17 secs to 7 secs.

FWIW, here is how the error looked on the CI

It was failing at two places: twice when trying to open the modal (it was opened "blank" without the flatpickr initialized on first try, then closed by clicking "Cancel" button on second try, then 3 times when trying to set the date (because it's closed).

-- rspec-retry: failed try 1 of 3 max --
RuntimeError: 'Flatpickr should render a calendar'
occurred on /app/spec/support/components/datepicker/datepicker_modal.rb:8:in `block in open_modal!'
backtrace:
  /app/spec/support/components/datepicker/datepicker_modal.rb:8:in `block in open_modal!'
  /app/spec/support/rspec_retry.rb:79:in `retry_block'
  /app/spec/support/components/datepicker/datepicker_modal.rb:4:in `open_modal!'
  /app/spec/features/admin/working_days_spec.rb:191:in `block (3 levels) in <top (required)>'
  /app/spec/support/capybara.rb:16:in `block (2 levels) in <top (required)>'
  /app/spec/support/shared/with_env.rb:58:in `block (2 levels) in <top (required)>'
  /app/spec/support/rspec_retry.rb:24:in `block (2 levels) in <top (required)>'
  /app/spec/support/cuprite_setup.rb:133:in `block (2 levels) in <top (required)>'
ran 1 try in 11.167048228 seconds, waiting 0.5 seconds until the next try.
--
-- rspec-retry: failed try 2 of 3 max --
Capybara::ElementNotFound: 'Unable to find link or button "Cancel"'
occurred on /app/spec/support/components/datepicker/datepicker_modal.rb:7:in `block in open_modal!'
backtrace:
  /app/spec/support/components/datepicker/datepicker_modal.rb:7:in `block in open_modal!'
  /app/spec/support/rspec_retry.rb:79:in `retry_block'
  /app/spec/support/components/datepicker/datepicker_modal.rb:4:in `open_modal!'
  /app/spec/features/admin/working_days_spec.rb:191:in `block (3 levels) in <top (required)>'
  /app/spec/support/capybara.rb:16:in `block (2 levels) in <top (required)>'
  /app/spec/support/shared/with_env.rb:58:in `block (2 levels) in <top (required)>'
  /app/spec/support/rspec_retry.rb:24:in `block (2 levels) in <top (required)>'
  /app/spec/support/cuprite_setup.rb:133:in `block (2 levels) in <top (required)>'
ran 2 tries in 25.873807058 seconds, waiting 0.75 seconds until the next try.
--
-- rspec-retry: failed try 1 of 3 max --
Capybara::ElementNotFound: 'Unable to find css ".flatpickr-calendar" within #<Capybara::Node::Element tag="body" path="//HTML[1]/BODY[1]">'
occurred on /app/spec/support/components/datepicker/datepicker.rb:36:in `flatpickr_container'
backtrace:
  /app/spec/support/components/datepicker/datepicker.rb:36:in `flatpickr_container'
  /app/spec/support/components/datepicker/datepicker_modal.rb:36:in `block in select_day'
  /app/spec/support/rspec_retry.rb:79:in `retry_block'
  /app/spec/support/components/datepicker/datepicker_modal.rb:30:in `select_day'
  /app/spec/features/admin/working_days_spec.rb:194:in `block (3 levels) in <top (required)>'
  /app/spec/support/capybara.rb:16:in `block (2 levels) in <top (required)>'
  /app/spec/support/shared/with_env.rb:58:in `block (2 levels) in <top (required)>'
  /app/spec/support/rspec_retry.rb:24:in `block (2 levels) in <top (required)>'
  /app/spec/support/cuprite_setup.rb:133:in `block (2 levels) in <top (required)>'
ran 1 try in 4.286365785 seconds, waiting 0.5 seconds until the next try.
--
-- rspec-retry: failed try 2 of 3 max --
Capybara::ElementNotFound: 'Unable to find css ".flatpickr-calendar" within #<Capybara::Node::Element tag="body" path="//HTML[1]/BODY[1]">'
occurred on /app/spec/support/components/datepicker/datepicker.rb:36:in `flatpickr_container'
backtrace:
  /app/spec/support/components/datepicker/datepicker.rb:36:in `flatpickr_container'
  /app/spec/support/components/datepicker/datepicker_modal.rb:31:in `block in select_day'
  /app/spec/support/rspec_retry.rb:79:in `retry_block'
  /app/spec/support/components/datepicker/datepicker_modal.rb:30:in `select_day'
  /app/spec/features/admin/working_days_spec.rb:194:in `block (3 levels) in <top (required)>'
  /app/spec/support/capybara.rb:16:in `block (2 levels) in <top (required)>'
  /app/spec/support/shared/with_env.rb:58:in `block (2 levels) in <top (required)>'
  /app/spec/support/rspec_retry.rb:24:in `block (2 levels) in <top (required)>'
  /app/spec/support/cuprite_setup.rb:133:in `block (2 levels) in <top (required)>'
ran 2 tries in 8.794877994 seconds, waiting 0.75 seconds until the next try.
--
-- rspec-retry: failed try 3 of 3 max --
Capybara::ElementNotFound: 'Unable to find css ".flatpickr-calendar" within #<Capybara::Node::Element tag="body" path="//HTML[1]/BODY[1]">'
occurred on /app/spec/support/components/datepicker/datepicker.rb:36:in `flatpickr_container'
backtrace:
  /app/spec/support/components/datepicker/datepicker.rb:36:in `flatpickr_container'
  /app/spec/support/components/datepicker/datepicker_modal.rb:31:in `block in select_day'
  /app/spec/support/rspec_retry.rb:79:in `retry_block'
  /app/spec/support/components/datepicker/datepicker_modal.rb:30:in `select_day'
  /app/spec/features/admin/working_days_spec.rb:194:in `block (3 levels) in <top (required)>'
  /app/spec/support/capybara.rb:16:in `block (2 levels) in <top (required)>'
  /app/spec/support/shared/with_env.rb:58:in `block (2 levels) in <top (required)>'
  /app/spec/support/rspec_retry.rb:24:in `block (2 levels) in <top (required)>'
  /app/spec/support/cuprite_setup.rb:133:in `block (2 levels) in <top (required)>'
ran 3 tries in 13.592000601 seconds, it was the last try.
--

@cbliard cbliard added needs review flaky-spec Addresses a Flaky Spec labels Sep 6, 2024
@cbliard
Copy link
Member Author

cbliard commented Sep 6, 2024

But it breaks some other behavior...

Edit: it's ok actually. I forgot one important line in my previous commit. I amended it.

@cbliard cbliard force-pushed the fix/fix-flaky-non-working-spec branch from b6a3464 to 4bf5b57 Compare September 6, 2024 13:12
It was in order to fix the flaky spec
`spec/features/admin/working_days_spec.rb:189`. The flakiness can be
forced by adding a `sleep 2` at the beginning of the test, just before
the `datepicker.open_modal!` call.

Not absolutely sure why so many forced change detection calls are
needed, but this way it seems to work. It seems to be related to having
a lot of nested templates, outlets and `if`s in templates which each
time need a new change detection to be reevaluated. But I'm not an
expert in this.

As a bonus there is no delay anymore in the drop modal initialization,
which should lead to more stable tests. For instance execution time of
`spec/features/admin/working_days_spec.rb:189` dropped from 17 secs to 7
secs.
@cbliard cbliard force-pushed the fix/fix-flaky-non-working-spec branch from 4bf5b57 to 3594502 Compare September 6, 2024 13:27
The modal behavior being more reliable now, the `retry_block` is not
needed anymore. Also the `#select_day` method was similar in the parent
class. Better keep only the one from the parent class.
It was stupid to make an assertion on the selected day for the
datepicker in `#select_day` as the date picker is dismissed half of the
time, so the selected element is not there anymore to make assertions on
it.

Replaced with a direct assertion where it matters and reverted the
"safeguard".
modules/team_planner/spec/features/query_handling_spec.rb sometimes
misses the dropdown, because it does not wait long enough after adding a
filter, and once the filter is applied, the page state is reset and the
dropdown is closed, which leads to the error.
@cbliard cbliard marked this pull request as ready for review September 6, 2024 15:26
Copy link
Member

@oliverguenther oliverguenther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialization appears to work a lot better know, although I'm not entirely sure why.

@oliverguenther oliverguenther merged commit acd81de into dev Sep 9, 2024
12 checks passed
@oliverguenther oliverguenther deleted the fix/fix-flaky-non-working-spec branch September 9, 2024 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flaky-spec Addresses a Flaky Spec needs review
Development

Successfully merging this pull request may close these issues.

2 participants