Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Wait for the list column to stand still before clicking in it

Guido Boyke8a7a184c7946
diff --git a/spec/support/motion_helpers.rb b/spec/support/motion_helpers.rb
new file mode 100644
index 0000000..ecf4611
--- /dev/null
+++ b/spec/support/motion_helpers.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+# A lane opens beside its list by a transition of the grid's columns (layout.css,
+# .layout.two-column: grid-template-columns, 0.25 s), and every control of the list
+# column travels with it, up to 100 px a frame. The driver measures where a control is
+# and clicks there a moment later: a frame in between, and the click lands beside the
+# control, on whatever has moved in. That hit the "+" of both meeting lists (one run in
+# ten) and, on the CI runner, the filter button of a project's meetings, whose click
+# went into the search field next to it.
+module MotionHelpers
+ # How long an element has to keep its place and size to count as still, in seconds.
+ STILL_FOR = 0.15
+
+ # Waits until the element that `find(selector)` finds (visible, within the current
+ # scope: the one a click would hit) has kept its place and size for STILL_FOR seconds.
+ def wait_until_still(selector)
+ page.document.synchronize do
+ element = find(selector)
+ before = MotionHelpers.box(element)
+ sleep STILL_FOR
+ raise Capybara::ExpectationNotMet, "#{selector} is still moving" unless MotionHelpers.box(element) == before
+ end
+ end
+
+ # A module function, not a helper method: several specs define a `box` of their own.
+ def self.box(element)
+ element.evaluate_script('(r => [r.left, r.top, r.width, r.height])(this.getBoundingClientRect())')
+ end
+end
+
+RSpec.configure do |config|
+ config.include MotionHelpers, type: :system
+end
diff --git a/spec/system/meeting_filters_columns_spec.rb b/spec/system/meeting_filters_columns_spec.rb
index 3cf3533..99d6565 100644
--- a/spec/system/meeting_filters_columns_spec.rb
+++ b/spec/system/meeting_filters_columns_spec.rb
@@ -170,6 +170,8 @@ RSpec.describe 'Meeting filters and columns', type: :system do
find("tr[data-meeting-id='#{meetings.first.id}']").click
expect(page).to have_css('#meeting-header', text: 'Alpha')
+ # The filter button moves with the list column while the lane opens.
+ wait_until_still('[data-filter-bar-target="filterButton"]')
find('[data-filter-bar-target="filterButton"]').click
find('[role="menuitem"][data-category="participant"]').click
expect(page).to have_css('[data-filter-bar-target="valueMenu"]:not(.hidden)', wait: 3)
@@ -212,14 +214,8 @@ RSpec.describe 'Meeting filters and columns', type: :system do
expect(page).to have_css('#meeting-header', text: 'Beta', wait: 5)
plus = "a[title='#{I18n.t('views.organisations.meetings.index.new_meeting')}']"
- # The lane opens with a width transition (layout.css, --panel-width), and
- # the "+" moves with the list column until it ends.
- page.document.synchronize(5) do
- left = -> { page.evaluate_script("document.querySelector(\"#{plus}\").getBoundingClientRect().left") }
- before = left.call
- sleep 0.15
- raise Capybara::ExpectationNotMet, 'the "+" is still moving' unless left.call == before
- end
+ # The "+" moves with the list column while the lane opens.
+ wait_until_still(plus)
# A full visit of the href would show the same state: the marker proves
# the lane opened the form in place.
page.execute_script('window.laneStayed = true')
diff --git a/spec/system/meetings_overview_spec.rb b/spec/system/meetings_overview_spec.rb
index f38d5df..cf53c32 100644
--- a/spec/system/meetings_overview_spec.rb
+++ b/spec/system/meetings_overview_spec.rb
@@ -209,15 +209,8 @@ RSpec.describe 'Meetings overview', type: :system do
expect(page).to have_css('#meetings_overview_results tr.selected-row', text: 'Beta Retro', wait: 5)
expect(page).to have_css('#meeting_display_frame h2', text: 'Beta Retro', wait: 5)
- # The lane opens with a width transition (layout.css, --panel-width), and
- # the "+" moves with the list column until it ends: a click during it
- # landed beside the "+" (1 run in 10).
- page.document.synchronize(5) do
- left = -> { page.evaluate_script("document.querySelector(\"#{plus}\").getBoundingClientRect().left") }
- before = left.call
- sleep 0.15
- raise Capybara::ExpectationNotMet, 'the "+" is still moving' unless left.call == before
- end
+ # The "+" moves with the list column while the lane opens.
+ wait_until_still(plus)
open_new_meeting
expect(page).to have_no_css('#meetings_overview_results tr.selected-row')