Remove redundant visibility matcher usages

By default, Capybara only finds visible elements, so adding the
`visible: true` option is usually redundant.

We were using it sometimes to make it an obvious contrast with another
test using `visible: false`. However, from the user's perspective, we
don't care whether the element has been removed from the DOM or has been
hidden, so we can just test that the visible selector can't be found.

Besides, using `visible: false` means the test will also pass if the
element is present and visible. However, we want the test to fail if the
element is visible. That's why a couple of JavaScript-dependant tests
were passing even when JavaScript was disabled.
This commit is contained in:
Javi Martín
2020-10-13 18:11:39 +02:00
parent 202fe2953b
commit 6088334dbf
15 changed files with 54 additions and 50 deletions

View File

@@ -22,7 +22,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login
visit send(path, arguments)
expect(page).to have_css "#new_document_link", visible: true
expect(page).to have_css "#new_document_link"
end
scenario "Should not show new document link when
@@ -34,14 +34,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_link "Add new document"
end
expect(page).to have_css "#new_document_link", visible: false
expect(page).not_to have_css "#new_document_link"
end
scenario "Should not show max documents warning when no documents added", :js do
login_as user_to_login
visit send(path, arguments)
expect(page).to have_css ".max-documents-notice", visible: false
expect(page).not_to have_css ".max-documents-notice"
end
scenario "Should show max documents warning when max documents allowed limit is reached", :js do
@@ -51,7 +51,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
end
expect(page).to have_css ".max-documents-notice", visible: true
expect(page).to have_css ".max-documents-notice"
expect(page).to have_content "Remove document"
end
@@ -65,7 +65,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
all("a", text: "Cancel").last.click
expect(page).to have_css ".max-documents-notice", visible: false
expect(page).not_to have_css ".max-documents-notice"
end
scenario "Should update nested document file name after choosing a file", :js do
@@ -263,7 +263,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login
visit send(path, arguments)
expect(page).to have_css "#new_document_link", visible: false
expect(page).not_to have_css "#new_document_link"
end
scenario "Should show add document button after destroy one document", :js do
@@ -275,7 +275,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_on "Remove document"
end
expect(page).to have_css "#new_document_link", visible: true
expect(page).to have_css "#new_document_link"
end
scenario "Should remove nested field after remove document", :js do

View File

@@ -17,16 +17,16 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user
visit send(path, arguments)
expect(page).to have_selector "#new_image_link", visible: true
expect(page).to have_selector "#new_image_link"
end
scenario "Should hide new image link after adding one image" do
scenario "Should hide new image link after adding one image", :js do
login_as user
visit send(path, arguments)
click_on "Add image"
expect(page).to have_selector "#new_image_link", visible: false
expect(page).not_to have_selector "#new_image_link"
end
scenario "Should update nested image file name after choosing any file", :js do
@@ -226,7 +226,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user
visit send(path, arguments)
expect(page).to have_css "a#new_image_link", visible: false
expect(page).not_to have_css "a#new_image_link"
end
scenario "Should remove nested field after remove image", :js do
@@ -244,7 +244,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
click_on "Remove image"
expect(page).to have_css "a#new_image_link", visible: true
expect(page).to have_css "a#new_image_link"
end
end
end

View File

@@ -23,13 +23,13 @@ shared_examples "relationable" do |relationable_model_name|
expect(page).not_to have_css("#related-content-list")
end
scenario "related contents can be added" do
scenario "related contents can be added", :js do
login_as(user)
visit relationable.url
expect(page).to have_selector("#related_content", visible: false)
expect(page).not_to have_selector("#related_content")
click_on("Add related content")
expect(page).to have_selector("#related_content", visible: true)
within("#related_content") do
fill_in "url", with: "#{Setting["url"] + related1.url}"
@@ -46,6 +46,8 @@ shared_examples "relationable" do |relationable_model_name|
expect(page).to have_content(relationable.title)
end
click_on("Add related content")
within("#related_content") do
fill_in "url", with: "#{Setting["url"] + related2.url}"
click_button "Add"

View File

@@ -5,9 +5,11 @@ module Votes
end
def expect_message_you_need_to_sign_in_to_vote_comments
expect(page).to have_content "You must sign in or sign up to vote"
expect(page).to have_selector(".participation-allowed", visible: false)
expect(page).to have_selector(".participation-not-allowed", visible: true)
within(".participation-not-allowed") do
expect(page).to have_content "You must sign in or sign up to vote"
end
expect(page).not_to have_selector(".participation-allowed")
end
def expect_message_to_many_anonymous_votes

View File

@@ -50,7 +50,7 @@ describe "Admin settings" do
find("#map-tab").click
expect(page).to have_css("#admin-map.leaflet-container", visible: true)
expect(page).to have_css("#admin-map.leaflet-container")
end
end

View File

@@ -690,11 +690,11 @@ describe "Ballots" do
find(".in-favor a").click
expect(page).not_to have_content "Remove"
expect(page).to have_selector(".participation-not-allowed", visible: false)
expect(page).not_to have_selector(".participation-not-allowed")
hover_over_ballot
expect(page).to have_selector(".participation-not-allowed", visible: true)
expect(page).to have_selector(".participation-not-allowed")
expect(page).to have_selector(".in-favor a", obscured: true)
end
end

View File

@@ -241,7 +241,7 @@ describe "Commenting Budget::Investments" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply update parent comment responses count", :js do
@@ -357,7 +357,7 @@ describe "Commenting Budget::Investments" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -456,7 +456,7 @@ describe "Commenting Budget::Investments" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
expect(page).to have_css "div.is-admin"
end

View File

@@ -210,7 +210,7 @@ describe "Internal valuation comments on Budget::Investments" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
visit budget_investment_path(investment.budget, investment)
expect(page).not_to have_content("It will be done next week.")
@@ -328,7 +328,7 @@ describe "Internal valuation comments on Budget::Investments" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
end

View File

@@ -254,7 +254,7 @@ describe "Commenting debates" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply to reply", :js do
@@ -408,7 +408,7 @@ describe "Commenting debates" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -464,7 +464,7 @@ describe "Commenting debates" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do

View File

@@ -277,7 +277,7 @@ describe "Commenting legislation questions" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply update parent comment responses count", :js do
@@ -430,7 +430,7 @@ describe "Commenting legislation questions" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -493,7 +493,7 @@ describe "Commenting legislation questions" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do

View File

@@ -258,7 +258,7 @@ describe "Commenting legislation questions" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply update parent comment responses count", :js do
@@ -387,7 +387,7 @@ describe "Commenting legislation questions" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -443,7 +443,7 @@ describe "Commenting legislation questions" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do

View File

@@ -237,7 +237,7 @@ describe "Commenting polls" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply update parent comment responses count", :js do
@@ -357,7 +357,7 @@ describe "Commenting polls" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -419,7 +419,7 @@ describe "Commenting polls" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do

View File

@@ -237,7 +237,7 @@ describe "Commenting proposals" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply update parent comment responses count", :js do
@@ -353,7 +353,7 @@ describe "Commenting proposals" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -409,7 +409,7 @@ describe "Commenting proposals" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do

View File

@@ -263,7 +263,7 @@ describe "Commenting topics from proposals" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Reply update parent comment responses count", :js do
@@ -393,7 +393,7 @@ describe "Commenting topics from proposals" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -455,7 +455,7 @@ describe "Commenting topics from proposals" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do
@@ -807,7 +807,7 @@ describe "Commenting topics from budget investments" do
expect(page).to have_content "It will be done next week."
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "Errors on reply", :js do
@@ -901,7 +901,7 @@ describe "Commenting topics from budget investments" do
expect(page).to have_css "img.moderator-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as an administrator" do
@@ -963,7 +963,7 @@ describe "Commenting topics from budget investments" do
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}")
end
scenario "can not comment as a moderator" do

View File

@@ -115,7 +115,7 @@ describe "Home" do
)
visit root_path
expect(page).to have_xpath(ie_alert_box_xpath, visible: false)
expect(page).to have_xpath(ie_alert_box_xpath)
expect(page.driver.request.cookies["ie_alert_closed"]).to be_nil
# faking close button, since a normal find and click
@@ -123,13 +123,13 @@ describe "Home" do
page.driver.browser.set_cookie("ie_alert_closed=true")
visit root_path
expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false)
expect(page).not_to have_xpath(ie_alert_box_xpath)
expect(page.driver.request.cookies["ie_alert_closed"]).to eq("true")
end
scenario "non-IE visitors are not bothered with IE alerts", :page_driver do
visit root_path
expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false)
expect(page).not_to have_xpath(ie_alert_box_xpath)
expect(page.driver.request.cookies["ie_alert_closed"]).to be_nil
end