Skip to content

Commit

Permalink
Merge pull request #3353 from projectblacklight/flaky-typeahead-iiif-…
Browse files Browse the repository at this point in the history
…test

Increase reliability of Sir Trevor feature tests
  • Loading branch information
jcoyne authored Dec 19, 2024
2 parents 105986e + d3e3204 commit f7a4498
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
2 changes: 2 additions & 0 deletions spec/features/autocomplete_typeahead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
# Open the multi-image selector and choose the last one
click_link('Change')
find('.thumbs-list li:last-child').click
sleep 1
expect(page).to have_css('.leaflet-container', visible: true)

click_button 'Save changes'
sleep 1

expect(page).to have_content('The exhibit was successfully updated.')

Expand Down
24 changes: 2 additions & 22 deletions spec/features/javascript/blocks/solr_documents_block_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,12 @@
it 'allows you to toggle visibility of solr documents', js: true do
fill_in_solr_document_block_typeahead_field with: 'dq287tq6352'

# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="dq287tq6352"] .img-thumbnail[src^="http"]')

within(:css, '.card') do
uncheck 'Display?'
end

fill_in_solr_document_block_typeahead_field with: 'gk446cj2442'

# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="gk446cj2442"] .img-thumbnail[src^="http"]')

# display the title as the primary caption
within('.primary-caption') do
check('Primary caption')
Expand All @@ -111,6 +105,7 @@
expect(page).to have_no_content "L'AMERIQUE"

visit spotlight.edit_exhibit_feature_page_path(exhibit, feature_page)
wait_for_sir_trevor
# display the title as the primary caption
within('.primary-caption') do
uncheck('Primary caption')
Expand Down Expand Up @@ -149,9 +144,6 @@
it 'allows you to optionally display a ZPR link with the image', js: true do
fill_in_solr_document_block_typeahead_field with: 'gk446cj2442'

# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="gk446cj2442"] .img-thumbnail[src^="http"]')

check 'Offer "View larger" option'

save_page_changes
Expand Down Expand Up @@ -182,9 +174,6 @@
it 'allows you to choose which side the text will be on', js: true do
fill_in_solr_document_block_typeahead_field with: 'dq287tq6352'

# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="dq287tq6352"] .img-thumbnail[src^="http"]')

# Select to align the text right
choose 'Left'

Expand All @@ -211,8 +200,6 @@

it 'toggles alt text input when marking an image as decorative', js: true do
fill_in_solr_document_block_typeahead_field with: 'gk446cj2442'
# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="gk446cj2442"] .img-thumbnail[src^="http"]')

fill_in 'Alternative text', with: 'custom alt text'
check 'Decorative'
Expand All @@ -223,32 +210,25 @@

it 'retains custom alt text after marking as decorative and saving', js: true do
fill_in_solr_document_block_typeahead_field with: 'gk446cj2442'
# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="gk446cj2442"] .img-thumbnail[src^="http"]')

fill_in 'Alternative text', with: 'custom alt text'
check 'Decorative'
save_page_changes
click_on 'Edit'
wait_for_sir_trevor
uncheck 'Decorative'
expect(page).to have_field('Alternative text', type: 'textarea', disabled: false, with: 'custom alt text')
end

it 'round-trip data', js: true do
fill_in_solr_document_block_typeahead_field with: 'dq287tq6352'

# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="dq287tq6352"] .img-thumbnail[src^="http"]')

within(:css, '.card') do
uncheck 'Display?'
end

fill_in_solr_document_block_typeahead_field with: 'gk446cj2442'

# Flappy guard. Wait for the thumbnail src to be populated.
expect(page).to have_selector('li[data-resource-id="gk446cj2442"] .img-thumbnail[src^="http"]')

# display the title as the primary caption
within('.primary-caption') do
check('Primary caption')
Expand Down
25 changes: 14 additions & 11 deletions spec/support/features/test_features_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ module TestFeaturesHelpers
def fill_in_typeahead_field(opts = {})
type = opts[:type] || 'default'

# This first click here is not needed in terms of user interaction, but it
# makes the test more reliable. Otherwise the fill_in can happen prior
# to auto-complete-element being fully initialized and the test will fail.
find("auto-complete [data-#{type}-typeahead]").click
find("auto-complete[open] [data-#{type}-typeahead]").fill_in(with: opts[:with])
# Role=combobox indicates that the auto-complete is initialized
expect(page).to have_css("auto-complete [data-#{type}-typeahead][role='combobox']")
find("auto-complete [data-#{type}-typeahead]").fill_in(with: opts[:with])
find('auto-complete[open] [role="option"]', text: opts[:with], match: :first).click
end

# just like #fill_in_typeahead_field, but wait for the
# form fields to show up on the page too
# form fields/thumbnail preview to show up on the page too
def fill_in_solr_document_block_typeahead_field(opts)
fill_in_typeahead_field(opts)
expect(page).to have_css('li[data-resource-id="' + opts[:with] + '"]')
expect(page).to have_css('li[data-resource-id="' + opts[:with] + '"] .img-thumbnail[src^="http"]')
end

def add_widget(type)
Expand All @@ -37,12 +35,17 @@ def click_add_widget
first('.st-block-replacer').click
end

def wait_for_sir_trevor
expect(page).to have_selector('.st-blocks.st-ready')
sleep 1
end

def save_page_changes
page.execute_script <<-EOF
SirTrevor.getInstance().onFormSubmit();
EOF
wait_for_sir_trevor
click_button('Save changes')
# verify that the page was created
# Load bearing sleep. Remove or reduce at your own risk. Revisit if Sir Trevor is removed.
sleep 3 if ENV['CI']
# verify that the page was created.
expect(page).to have_no_selector('.alert-danger')
expect(page).to have_selector('.alert-info', text: 'page was successfully updated')
end
Expand Down

0 comments on commit f7a4498

Please sign in to comment.