Skip to content

Commit 3a736e8

Browse files
awwaiidclaude
andcommitted
Wait for Litepicker before typing into the date range field
The shared "Date Range Picker" examples typed into #filters_date_range as soon as the page loaded. Litepicker seeds that field from the server's dates as the last step of its setup, so if setup finishes after the typing, the seed overwrites it and the form filters on the default range. On main the race rarely shows, because a render-blocking Google Fonts stylesheet slows every page load. Removing that request (previous commit) made pages load sooner, and with --seed 1234 spec/system/purchase_system_spec.rb failed 2-3 examples every run. Putting the font link back made them pass again, which pins the cause to the timing, not the typeface. The examples now wait for Litepicker's markup before typing (or before scripting the field), and confirm the value stuck. Ported from 6077ba5 on the design branch, which hit the same race. All 36 date range picker examples pass across six system specs under seeds 1234, 8576 and 4242. This can also land on main by itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzWYw6Gq5YdmU4MaiGnQa
1 parent bdce1d4 commit 3a736e8

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

‎spec/support/date_range_picker_shared_example.rb‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ def date_range_picker_select_range(range_name)
99
end
1010
end
1111

12+
# Litepicker seeds the field from the server's dates as the last step of its setup. Typing
13+
# before that happens means the seed overwrites what was typed, and the form then filters on
14+
# the default range. That is a race, so it depends on the machine, on example ordering and on
15+
# how quickly the page loads. Waiting for the calendar's own markup to appear means setup has
16+
# run. (Ported from 6077ba541 on the design branch.)
17+
def wait_for_date_range_picker(page)
18+
page.assert_selector(".litepicker", visible: :all, wait: 5)
19+
end
20+
21+
def fill_in_date_range(page, date_range)
22+
wait_for_date_range_picker(page)
23+
page.fill_in "filters_date_range", with: date_range
24+
expect(page).to have_field("filters_date_range", with: date_range, wait: 5)
25+
end
26+
1227
RSpec.shared_examples_for "Date Range Picker" do |described_class, date_field|
1328
before :each do
1429
date_field ||= "created_at"
@@ -50,7 +65,7 @@ def date_range_picker_select_range(range_name)
5065
it "shows all the records" do
5166
visit subject
5267
date_range = "#{Time.zone.local(1919, 7, 1).to_fs(:date_picker)} - #{Time.zone.local(2020, 7, 31).to_fs(:date_picker)}"
53-
fill_in "filters_date_range", with: date_range
68+
fill_in_date_range(page, date_range)
5469
click_on "Filter"
5570
expect(page).to have_css("table tbody tr", count: 6)
5671
end
@@ -68,7 +83,7 @@ def date_range_picker_select_range(range_name)
6883
it "shows only 2 of the records" do
6984
visit subject
7085
date_range = "#{Time.zone.local(2019, 7, 1).to_fs(:date_picker)} - #{Time.zone.local(2019, 7, 31).to_fs(:date_picker)}"
71-
fill_in "filters_date_range", with: date_range
86+
fill_in_date_range(page, date_range)
7287
click_on "Filter"
7388
expect(page).to have_css("table tbody tr", count: 2)
7489
end
@@ -78,7 +93,7 @@ def date_range_picker_select_range(range_name)
7893
it "shows only 1 record" do
7994
visit subject
8095
date_range = "#{Time.zone.local(2019, 7, 22).to_fs(:date_picker)} - #{Time.zone.local(2019, 7, 28).to_fs(:date_picker)}"
81-
fill_in "filters_date_range", with: date_range
96+
fill_in_date_range(page, date_range)
8297
click_on "Filter"
8398
expect(page).to have_css("table tbody tr", count: 1)
8499
end
@@ -112,6 +127,7 @@ def date_range_picker_select_range(range_name)
112127
visit subject
113128

114129
date_range = "nov 08 - feb 08"
130+
wait_for_date_range_picker(page)
115131
page.execute_script(<<~JS)
116132
var input = document.getElementById('filters_date_range');
117133
input.dataset.skipValidation = 'true';
@@ -132,6 +148,7 @@ def date_range_picker_select_range(range_name)
132148
visit subject
133149

134150
date_range = "nov 08 - feb 08"
151+
wait_for_date_range_picker(page)
135152
page.execute_script("document.getElementById('filters_date_range').focus();")
136153
page.execute_script("document.getElementById('filters_date_range').value = '#{date_range}';")
137154

@@ -140,7 +157,7 @@ def date_range_picker_select_range(range_name)
140157
end
141158

142159
valid_date_range = "#{Time.zone.local(2019, 7, 22).to_fs(:date_picker)} - #{Time.zone.local(2019, 7, 28).to_fs(:date_picker)}"
143-
fill_in "filters_date_range", with: valid_date_range
160+
fill_in_date_range(page, valid_date_range)
144161
click_button "Filter"
145162
expect(page).to have_css("table tbody tr", count: 1)
146163
end

0 commit comments

Comments
 (0)