From 12eeb3d18cb26cb087a0d2d8c719bdc01a03c60d Mon Sep 17 00:00:00 2001 From: Mark Taylor <138604938+mtaylorgds@users.noreply.github.com> Date: Fri, 28 Feb 2025 10:44:18 +0000 Subject: [PATCH] Fix flakey test due to Javascript animation timing The test fails intermittently with the error: ``` Capybara::ElementNotFound: Unable to find visible css ".action-content-block-update" within # ``` This seems to be because the expanding of the edition panel is not always completing before the check for the "content block update" element occurs. Adding the extra `within` selector for the `.collapse.in` classes to be present (which happens once the "expand" animation has completed) appears to at least make the test more reliable (I can't really be 100% sure it's completely resolved, but I've run the test dozens of times locally now without failure). --- .../host_content_update_history_test.rb | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/integration/host_content_update_history_test.rb b/test/integration/host_content_update_history_test.rb index 95fa4625b..150adba5a 100644 --- a/test/integration/host_content_update_history_test.rb +++ b/test/integration/host_content_update_history_test.rb @@ -97,25 +97,29 @@ class HostContentUpdateHistoryTest < LegacyJavascriptIntegrationTest click_on "Edition 2" within "#version2" do - within page.all(".action-content-block-update")[0] do - assert page.has_content?(Time.zone.parse(@edition2_content_update_event_2["created_at"]).to_fs(:govuk_date)) - assert page.has_content?("Content block updated by User 1") - assert page.has_content?("Email address updated") - end - - within page.all(".action-content-block-update")[1] do - assert page.has_content?(Time.zone.parse(@edition2_content_update_event_1["created_at"]).to_fs(:govuk_date)) - assert page.has_content?("Content block updated by User 2") - assert page.has_content?("Email address updated") + within ".collapse.in" do + within page.all(".action-content-block-update")[0] do + assert page.has_content?(Time.zone.parse(@edition2_content_update_event_2["created_at"]).to_fs(:govuk_date)) + assert page.has_content?("Content block updated by User 1") + assert page.has_content?("Email address updated") + end + + within page.all(".action-content-block-update")[1] do + assert page.has_content?(Time.zone.parse(@edition2_content_update_event_1["created_at"]).to_fs(:govuk_date)) + assert page.has_content?("Content block updated by User 2") + assert page.has_content?("Email address updated") + end end end click_on "Edition 1" within "#version1" do - within ".action-content-block-update" do - assert page.has_content?(Time.zone.parse(@edition1_content_update_event["created_at"]).to_fs(:govuk_date)) - assert page.has_content?("Content block updated by User 1") - assert page.has_content?("Email address updated") + within ".collapse.in" do + within ".action-content-block-update" do + assert page.has_content?(Time.zone.parse(@edition1_content_update_event["created_at"]).to_fs(:govuk_date)) + assert page.has_content?("Content block updated by User 1") + assert page.has_content?("Email address updated") + end end end end