Skip to content

Commit

Permalink
try to make copy to clipboard test more reliable
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
jrochkind committed Dec 5, 2024
1 parent 710f822 commit df77874
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions spec/system/oral_history_with_audio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df77874

Please sign in to comment.