From df77874dc3de32c14408aef9e6b26296f3b4459f Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Thu, 5 Dec 2024 12:57:29 -0500 Subject: [PATCH] try to make copy to clipboard test more reliable In some cases the 'copy to clipboard' button is ending up off-screen when capybara tries to click it. I think this is because bootstrap accordion is doing some crazy animation when we automatically open/close the different elements. We can try to work around it by actually scrolling the browser to right position? a) This may be an actual problem for users of course that we should try to solve, I have kind of noticed it b) I'm not sure if our previous attempts to improve reliability with the rescue right here are necessary working or not? But leaving them in too! --- spec/system/oral_history_with_audio_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/system/oral_history_with_audio_spec.rb b/spec/system/oral_history_with_audio_spec.rb index 596cf101b..4babb7be7 100644 --- a/spec/system/oral_history_with_audio_spec.rb +++ b/spec/system/oral_history_with_audio_spec.rb @@ -411,16 +411,19 @@ copy_to_clipboard = "*[data-trigger='linkClipboardCopy']" begin - expect(page).to have_selector(copy_to_clipboard, wait: 0.05) + copy_button = page.find(copy_to_clipboard, wait: 0.5) rescue RSpec::Expectations::ExpectationNotMetError # the "copy to clipboard" button sometimes fails to show up fast enough. # Just click "search" again. # See similar workaround below. within("*[data-ohms-search-form]") { click_on "Search" } - expect(page).to have_selector(copy_to_clipboard) + copy_button = page.find(copy_to_clipboard, wait: 0.5) end - page.find(copy_to_clipboard).click + # ToC animation has weird jumping around, let's try to make sure + # our button is actually on-screen before clicking + find("body").scroll_to(copy_button, align: :bottom) + copy_button.click expect(page).to have_content("Copied to clipboard") # ToC tab should be selected as it is first tab with results from search