Skip to content

Commit

Permalink
Fix tests failing due to overlapping elements
Browse files Browse the repository at this point in the history
Poltergeist is seeing '.help-block' overlapping
the 'Save' button, hence can't click it without
a `.trigger('click')` on that element.

This needs to be followed by an assertion that
waits for the edition to get saved, or else
capybara jumps to the next statement.
  • Loading branch information
Vinay Patel committed Sep 10, 2014
1 parent 29529e4 commit 9e50049
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion test/integration/adding_parts_to_guides_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AddingPartsToGuidesTest < JavascriptIntegrationTest
fill_in 'Body', :with => 'Body text'
fill_in 'Slug', :with => 'part-three'
end
within(:css, '.workflow-buttons') { click_on 'Save' }
save_edition

assert page.has_css?('section#parts div#part-one', count: 1)
assert page.has_css?('section#parts div#part-two', count: 1)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/business_support_create_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def areas_response(areas)
find('#edition_sectors_manufacturing').trigger('click')
uncheck "edition_support_types_loan"

click_button "Save"
save_edition

assert page.has_content? "Business support edition was successfully updated."

Expand Down Expand Up @@ -242,7 +242,7 @@ def areas_response(areas)
fill_in "Max value", :with => "£10,000"
fill_in "Max employees", :with => "1,000"

click_button "Save"
save_edition

assert page.has_content?("We had some problems saving")

Expand Down
8 changes: 4 additions & 4 deletions test/integration/campaign_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CampaignEditTest < JavascriptIntegrationTest
select "Portcullis", :from => "Organisation crest"
select "cabinet-office", :from => "Organisation brand colour"

click_button "Save"
save_edition

assert page.has_content? "Campaign edition was successfully updated."

Expand Down Expand Up @@ -125,7 +125,7 @@ class CampaignEditTest < JavascriptIntegrationTest
attach_file("Upload image", large_image.path)
end

click_on "Save"
save_edition

assert page.has_content?("Campaign edition was successfully updated.")

Expand All @@ -134,7 +134,7 @@ class CampaignEditTest < JavascriptIntegrationTest
assert page.has_selector?("#large-campaign-image a[href$='campaign_large.jpg']")

# ensure files are not removed on save
click_on "Save"
save_edition

assert page.has_selector?("#small-campaign-image a[href$='campaign_small.jpg']")
assert page.has_selector?("#medium-campaign-image a[href$='campaign_medium.jpg']")
Expand All @@ -145,7 +145,7 @@ class CampaignEditTest < JavascriptIntegrationTest
find('#edition_remove_medium_image').trigger('click')
find('#edition_remove_large_image').trigger('click')

click_on "Save"
save_edition

refute page.has_selector?("#small-campaign-image a")
refute page.has_selector?("#medium-campaign-image a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CompletedTransactionCreateEditTest < JavascriptIntegrationTest

assert page.has_field?("Title", :with => "All bar done")

click_button "Save"
save_edition

assert page.has_content? "Completed transaction edition was successfully updated."

Expand Down
2 changes: 1 addition & 1 deletion test/integration/edition_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def assign(guide, user)
visit_edition guide

select user, from: "Assigned to"
click_on "Save"
save_edition

assert page.has_content?("successfully updated")
guide.reload
Expand Down
2 changes: 1 addition & 1 deletion test/integration/guide_create_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class GuideCreateEditTest < JavascriptIntegrationTest
fill_in 'Slug', :with => 'part-two'
end

click_button "Save"
save_edition

assert page.has_content? "Guide edition was successfully updated."

Expand Down
2 changes: 1 addition & 1 deletion test/integration/help_page_create_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HelpPageCreateEditTest < JavascriptIntegrationTest

fill_in "Body", :with => "This body has changed"

click_button "Save"
save_edition

assert page.has_content? "Help page edition was successfully updated."

Expand Down
2 changes: 1 addition & 1 deletion test/integration/licence_create_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LicenceCreateEditTest < JavascriptIntegrationTest
fill_in "Will continue on", :with => "The DVLA website"
fill_in "Link to competent authority", :with => "http://www.dvla.gov.uk"

click_button "Save"
save_edition

assert page.has_content? "Licence edition was successfully updated."

Expand Down
4 changes: 2 additions & 2 deletions test/integration/local_transaction_create_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LocalTransactionCreateEditTest < JavascriptIntegrationTest

fill_in "LGIL override", :with => '7'

click_button "Save"
save_edition

assert page.has_content? "Local transaction edition was successfully updated."

Expand All @@ -73,7 +73,7 @@ class LocalTransactionCreateEditTest < JavascriptIntegrationTest

# Ensure it gets set to nil when clearing field
fill_in "LGIL override", :with => ''
click_button "Save"
save_edition

assert page.has_content? "Local transaction edition was successfully updated."

Expand Down
4 changes: 2 additions & 2 deletions test/integration/mark_edition_in_beta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MarkEditionInBetaTest < JavascriptIntegrationTest
refute find('#edition_in_beta').checked?

check 'Content is in beta'
click_button 'Save'
save_edition

assert find('#edition_in_beta').checked?

Expand All @@ -27,7 +27,7 @@ class MarkEditionInBetaTest < JavascriptIntegrationTest
assert find('#edition_in_beta').checked?

uncheck 'Content is in beta'
click_button 'Save'
save_edition

refute find('#edition_in_beta').checked?

Expand Down
3 changes: 1 addition & 2 deletions test/integration/programme_editions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def setup
fill_in "Slug", :with => "imagine-this-is-welsh"
end
end

within(:css, ".workflow-buttons") { click_on "Save" }
save_edition

assert_includes page.body, "Programme edition was successfully updated."

Expand Down
8 changes: 4 additions & 4 deletions test/integration/simple_smart_answers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class SimpleSmartAnswersTest < JavascriptIntegrationTest
assert page.has_css?(".nodes .outcome", count: 3)
assert page.has_css?(".nodes .node", count: 5)

click_on "Save"
save_edition

assert page.has_content?("Simple smart answer edition was successfully updated.")

Expand Down Expand Up @@ -325,7 +325,7 @@ class SimpleSmartAnswersTest < JavascriptIntegrationTest
end
end

click_on "Save"
save_edition
page.has_content?("We had some problems saving. Please check the form below.")

assert page.has_css?(".nodes .node", count: 4)
Expand Down Expand Up @@ -427,7 +427,7 @@ class SimpleSmartAnswersTest < JavascriptIntegrationTest
assert page.has_no_content?("Outcome 2")
assert page.has_selector?(".nodes .outcome:nth-child(3)", :visible => false)

click_button "Save"
save_edition

page.has_content?("Simple smart answer edition was successfully updated.")

Expand Down Expand Up @@ -498,7 +498,7 @@ class SimpleSmartAnswersTest < JavascriptIntegrationTest
assert_equal "", find(:css, 'input.next-node-id', :visible => false).value
end

click_on "Save"
save_edition

within ".nodes .question:first-child .option:first-child" do
assert_equal "", find(:css, 'input.next-node-id', :visible => false).value
Expand Down
16 changes: 6 additions & 10 deletions test/integration/video_edition_create_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class VideoEditionCreateEditTest < JavascriptIntegrationTest
fill_in "Video Summary", :with => "A simple fried plantain recipe"
fill_in "Body", :with => "Description of video"

within :css, ".workflow-buttons" do
click_on "Save"
end
save_edition

assert page.has_content? @artefact.name

Expand Down Expand Up @@ -57,9 +55,7 @@ class VideoEditionCreateEditTest < JavascriptIntegrationTest
fill_in "Video Summary", :with => "A simple fried plantain recipe"
fill_in "Body", :with => "Description of video"

within ".workflow-buttons" do
click_button "Save"
end
save_edition

assert page.has_content? "Video edition was successfully updated."

Expand Down Expand Up @@ -104,14 +100,14 @@ class VideoEditionCreateEditTest < JavascriptIntegrationTest

assert page.has_field?("Upload a new caption file", :type => "file")
attach_file("Upload a new caption file", file_one.path)
click_on "Save"
save_edition

within(:css, ".uploaded-caption-file") do
assert page.has_selector?("a[href$='captions.txt']")
end

# ensure file is not removed on save
click_on "Save"
save_edition

within(:css, ".uploaded-caption-file") do
assert page.has_selector?("a[href$='captions.txt']")
Expand All @@ -122,15 +118,15 @@ class VideoEditionCreateEditTest < JavascriptIntegrationTest
GdsApi::AssetManager.any_instance.stubs(:asset).with("another_image_id").returns(asset_two)

attach_file("Upload a new caption file", file_two.path)
click_on "Save"
save_edition

within(:css, ".uploaded-caption-file") do
assert page.has_selector?("a[href$='captions_two.txt']")
end

# remove file
check "Remove caption file?"
click_on "Save"
save_edition

refute page.has_selector?(".uploaded-caption-file")
end
Expand Down
13 changes: 12 additions & 1 deletion test/integration_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def fill_in_parts(guide)
fill_in 'Body', with: 'Body text'
fill_in 'Slug', with: 'part-one'
end
save_edition

click_on "Save"
assert page.has_content?("was successfully updated"), "No successful update message"

guide.reload
Expand All @@ -105,6 +105,17 @@ def select2(value, element_selector)
find(:xpath, "//body").find("#{drop_container} li", text: value).click
end

def save_edition
# using trigger because poltergeist
# thinks there are overlapping elements
page.find_button('Save').trigger('click')

# using .trigger("click") causes race conditions,
# hence we need to explicitly wait till the page reloads.
# save button is disabled after one click, so refreshing should enable it.
assert page.has_selector?("input[type=submit]#save-edition:enabled"), "Failed to save edition."
end

def clear_cookies
Capybara.current_session.driver.browser.cookies.each do |k, v|
Capybara.current_session.driver.browser.remove_cookie(k)
Expand Down

0 comments on commit 9e50049

Please sign in to comment.