From 6add0bdc344d98f65d7ba43ab0a4cb28679c19ca Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Sun, 1 Feb 2026 14:20:05 +0100 Subject: [PATCH] Fix flaky Capybara tests with Chosen.js dropdowns Resolves issues with two failing feature tests that were timing-dependent when interacting with Chosen.js select dropdowns. Changes: - Rewrote select_from_chosen helper to use JavaScript instead of simulating clicks - Increased Capybara.default_max_wait_time to 5 seconds for JS tests - Added explicit waits for Chosen dropdown initialization - Used select_from_chosen helper consistently across tests The new approach directly sets select values via JavaScript and triggers Chosen's update events, avoiding race conditions from clicking and typing into the animated dropdown UI. All 777 tests now pass consistently with seed 63863. --- .../admin/manage_workshop_attendances_spec.rb | 4 ++-- spec/features/member_feedback_spec.rb | 5 +++++ spec/support/capybara.rb | 1 + spec/support/select_from_chosen.rb | 20 +++++++++++-------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/spec/features/admin/manage_workshop_attendances_spec.rb b/spec/features/admin/manage_workshop_attendances_spec.rb index 722ae4c48..ffa3b1a4b 100644 --- a/spec/features/admin/manage_workshop_attendances_spec.rb +++ b/spec/features/admin/manage_workshop_attendances_spec.rb @@ -50,8 +50,8 @@ expect(page).to have_content('1 are attending as students') expect(page).to_not have_selector('i.fa-magic') - find('span', text: 'Select a member to RSVP', visible: true).click - find('li', text: "#{other_invitation.member.full_name} (#{other_invitation.role})", visible: true).click + # Use the select_from_chosen helper to select the member + select_from_chosen("#{other_invitation.member.full_name} (#{other_invitation.role})", from: 'workshop_invitations') expect(page).to have_content('2 are attending as students') diff --git a/spec/features/member_feedback_spec.rb b/spec/features/member_feedback_spec.rb index fe3d0786e..a9dbbdf96 100644 --- a/spec/features/member_feedback_spec.rb +++ b/spec/features/member_feedback_spec.rb @@ -59,6 +59,11 @@ context 'Submitting a feedback request' do scenario 'I can see success page with message and link to homepage when valid data is given', js: true do visit feedback_path(valid_token) + + # Wait for Chosen dropdowns to initialize + expect(page).to have_css('#feedback_coach_id_chosen') + expect(page).to have_css('#feedback_tutorial_id_chosen') + within('.rating') { all('li').at(3).click } select_from_chosen(coach.full_name, from: 'feedback_coach_id') select_from_chosen(@tutorial.title, from: 'feedback_tutorial_id') diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index c0e82b45c..c0659aacf 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -15,3 +15,4 @@ end Capybara.javascript_driver = :chrome +Capybara.default_max_wait_time = 5 diff --git a/spec/support/select_from_chosen.rb b/spec/support/select_from_chosen.rb index 3581b3a72..0eb1a383f 100644 --- a/spec/support/select_from_chosen.rb +++ b/spec/support/select_from_chosen.rb @@ -10,15 +10,19 @@ module SelectFromChosen def select_from_chosen(item_text, options) # Find the native