Add and apply Capybara/ClickLinkOrButtonStyle rule

This rule was added in rubocop-capybara 2.19.0. We were following it
most of the time.
This commit is contained in:
Javi Martín
2023-10-03 18:47:49 +02:00
parent 0cec581ec0
commit 5e7b5ccfd3
21 changed files with 55 additions and 52 deletions

View File

@@ -20,6 +20,9 @@ Bundler/OrderedGems:
Enabled: true
ConsiderPunctuation: true
Capybara/ClickLinkOrButtonStyle:
Enabled: true
Capybara/CurrentPathExpectation:
Enabled: true

View File

@@ -197,7 +197,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id)
find(".map-location").click
click_on("Save changes")
click_button "Save changes"
mappable.reload
expect(page).to have_css(".map-location")
@@ -210,7 +210,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name.camelize} title", with: "New title"
click_on("Save changes")
click_button "Save changes"
mappable.reload
expect(page).to have_css(".map-location")
@@ -223,7 +223,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id)
click_button "Remove map marker"
click_on "Save changes"
click_button "Save changes"
expect(page).not_to have_css(".map-location")
end
@@ -234,7 +234,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name.camelize} title", with: "New title"
click_on("Save changes")
click_button "Save changes"
expect(page).not_to have_css(".map-location")
end
@@ -244,7 +244,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id)
click_button "Remove map marker"
click_on "Save changes"
click_button "Save changes"
expect(page).not_to have_content "Map location can't be blank"
end

View File

@@ -161,7 +161,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments)
click_link "Add new document"
click_on submit_button
click_button submit_button
within "#nested-documents .document-fields" do
expect(page).to have_content("can't be blank", count: 2)
@@ -184,7 +184,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
click_on submit_button
click_button submit_button
expect(page).to have_content documentable_success_notice
end
@@ -196,7 +196,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
send(fill_resource_method_name) if fill_resource_method_name
documentable_attach_new_file(file_fixture("empty.pdf"))
click_on submit_button
click_button submit_button
expect(page).to have_content documentable_success_notice
end
@@ -208,7 +208,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
send(fill_resource_method_name) if fill_resource_method_name
documentable_attach_new_file(file_fixture("empty.pdf"))
click_on submit_button
click_button submit_button
expect(page).to have_content documentable_success_notice
@@ -233,7 +233,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
documentable_attach_new_file(file_fixture("#{filename}.pdf"))
end
click_on submit_button
click_button submit_button
expect(page).to have_content documentable_success_notice
@@ -266,7 +266,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments)
last_document = all("#nested-documents .document-fields").last
within last_document do
click_on "Remove document"
click_link "Remove document"
end
expect(page).to have_link id: "new_document_link"
@@ -276,7 +276,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
create(:document, documentable: documentable)
do_login_for user_to_login, management: management
visit send(path, arguments)
click_on "Remove document"
click_link "Remove document"
expect(page).not_to have_css ".document-fields"
end

View File

@@ -28,7 +28,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user, management: management
visit send(path, arguments)
click_on "Add image"
click_link "Add image"
expect(page).not_to have_css "#new_image_link"
end
@@ -117,7 +117,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
click_link "Add image"
click_on submit_button
click_button submit_button
within "#nested-image .image-fields" do
expect(page).to have_content("can't be blank", count: 2)
@@ -131,7 +131,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
imageable_attach_new_file(file_fixture("clippy.jpg"))
within_fieldset("Descriptive image") { fill_in "Title", with: "" }
click_on submit_button
click_button submit_button
expect(page).to have_content "can't be blank"
expect(page).to have_css "img[src$='clippy.jpg']"
@@ -156,7 +156,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
click_on submit_button
click_button submit_button
expect(page).to have_content imageable_success_notice
end
@@ -169,7 +169,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
expect(page).to have_css ".loading-bar.complete"
click_on submit_button
click_button submit_button
expect(page).to have_content imageable_success_notice
end
@@ -183,7 +183,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
expect(page).to have_css ".loading-bar.complete"
click_on submit_button
click_button submit_button
expect(page).to have_content imageable_success_notice

View File

@@ -1,7 +1,7 @@
module Documents
def documentable_redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal"
click_link "Not now, go to my proposal"
rescue
nil
end

View File

@@ -4,7 +4,7 @@ module Images
when "Budget"
visit edit_admin_budget_path(Budget.last)
when "Proposal"
click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound
click_link "Not now, go to my proposal" rescue Capybara::ElementNotFound
end
end

View File

@@ -53,7 +53,7 @@ describe "Admin budget phases" do
imageable_attach_new_file(file_fixture("clippy.jpg"))
click_on "Save changes"
click_button "Save changes"
expect(page).to have_content "Changes saved"
end

View File

@@ -104,7 +104,7 @@ describe "Admin newsletter emails", :admin do
confirmation = "Are you sure? This action will delete \"#{newsletter.subject}\" and can't be undone."
within("#newsletter_#{newsletter.id}") do
accept_confirm(confirmation) { click_link_or_button "Delete" }
accept_confirm(confirmation) { click_button "Delete" }
end
expect(page).to have_content "Newsletter deleted successfully"

View File

@@ -143,7 +143,7 @@ describe "Admin legislation questions", :admin do
scenario "Add translation for question option" do
visit edit_question_url
click_on "Add option"
click_link "Add option"
find("#nested_question_options input").set("Option 1")
@@ -166,7 +166,7 @@ describe "Admin legislation questions", :admin do
select "Español", from: :select_language
click_on "Add option"
click_link "Add option"
find("#nested_question_options input").set("Opción 1")

View File

@@ -61,7 +61,7 @@ describe "Admin local census records", :admin do
visit admin_local_census_records_path
fill_in :search, with: "X66777888"
click_on "Search"
click_button "Search"
expect(page).to have_content "X66777888"
expect(page).not_to have_content local_census_record.document_number
@@ -73,7 +73,7 @@ describe "Admin local census records", :admin do
scenario "Should show validation errors" do
visit new_admin_local_census_record_path
click_on "Save"
click_button "Save"
expect(page).to have_content "4 errors prevented this Local Census Record from being saved."
expect(page).to have_content "can't be blank", count: 4
@@ -88,7 +88,7 @@ describe "Admin local census records", :admin do
select "July", from: :local_census_record_date_of_birth_2i
select "7", from: :local_census_record_date_of_birth_3i
fill_in :local_census_record_postal_code, with: "07003"
click_on "Save"
click_button "Save"
expect(page).to have_content "New local census record created successfully!"
expect(page).to have_content "DNI"
@@ -105,7 +105,7 @@ describe "Admin local census records", :admin do
visit edit_admin_local_census_record_path(local_census_record)
fill_in :local_census_record_document_number, with: ""
click_on "Save"
click_button "Save"
expect(page).to have_content "1 error prevented this Local Census Record from being saved."
expect(page).to have_content "can't be blank", count: 1
@@ -120,7 +120,7 @@ describe "Admin local census records", :admin do
select "August", from: :local_census_record_date_of_birth_2i
select "8", from: :local_census_record_date_of_birth_3i
fill_in :local_census_record_postal_code, with: "07007"
click_on "Save"
click_button "Save"
expect(page).to have_content "Local census record updated successfully!"
expect(page).to have_content "Passport"
@@ -142,7 +142,7 @@ describe "Admin local census records", :admin do
confirmation = "Are you sure? This action will delete " \
"\"#{local_census_record.title}\" and can't be undone."
accept_confirm(confirmation) { click_on "Delete" }
accept_confirm(confirmation) { click_button "Delete" }
expect(page).to have_content "Local census record removed successfully!"
expect(page).not_to have_content deleted_document_number

View File

@@ -107,7 +107,7 @@ describe "Admin::Organizations" do
visit admin_organizations_path
click_on "Verified"
click_link "Verified"
within("#organization_#{organization.id}") do
expect(page).to have_content "Verified"
@@ -119,7 +119,7 @@ describe "Admin::Organizations" do
expect(page).to have_current_path(admin_organizations_path, ignore_query: true)
expect(page).not_to have_content organization.name
click_on "Rejected"
click_link "Rejected"
within "tr", text: organization.name do
expect(page).to have_content "Rejected"
@@ -130,7 +130,7 @@ describe "Admin::Organizations" do
organization = create(:organization, :rejected)
visit admin_organizations_path
click_on "Rejected"
click_link "Rejected"
within("#organization_#{organization.id}") do
expect(page).to have_button "Verify"
@@ -140,7 +140,7 @@ describe "Admin::Organizations" do
end
expect(page).to have_current_path(admin_organizations_path, ignore_query: true)
expect(page).not_to have_content organization.name
click_on("Verified")
click_link "Verified"
within "tr", text: organization.name do
expect(page).to have_content "Verified"

View File

@@ -78,7 +78,7 @@ describe "Admin settings", :admin do
click_link "Map configuration"
within "#map-form" do
click_on "Update"
click_button "Update"
end
expect(page).to have_content "Map configuration updated successfully"
@@ -100,7 +100,7 @@ describe "Admin settings", :admin do
click_link "Map configuration"
find("#admin-map").click
within "#map-form" do
click_on "Update"
click_button "Update"
end
expect(find("#latitude", visible: :hidden).value).not_to eq "51.48"

View File

@@ -328,7 +328,7 @@ describe "System Emails" do
visit admin_system_email_preview_pending_path("proposal_notification_digest")
within("#proposal_notification_#{proposal_notification1.id}") do
click_on "Moderate notification send"
click_link "Moderate notification send"
end
expect(page).not_to have_content("Proposal A Title")

View File

@@ -40,7 +40,7 @@ describe "Admin tags", :admin do
within("#tag_#{tag2.id}") do
accept_confirm("Are you sure? This action will delete \"Bad tag\" and can't be undone.") do
click_link_or_button "Delete"
click_button "Delete"
end
end
@@ -60,7 +60,7 @@ describe "Admin tags", :admin do
within("#tag_#{tag2.id}") do
accept_confirm("Are you sure? This action will delete \"Bad tag\" and can't be undone.") do
click_link_or_button "Delete"
click_button "Delete"
end
end

View File

@@ -92,7 +92,7 @@ describe "Home" do
visit root_path
within("#section_recommended") do
click_on debate.title
click_link debate.title
end
expect(page).to have_current_path(debate_path(debate))

View File

@@ -109,11 +109,11 @@ describe "Moderate budget investments" do
visit moderation_budget_investments_path
within(".js-check") { click_on "All" }
within(".js-check") { click_link "All" }
expect(all("input[type=checkbox]")).to all(be_checked)
within(".js-check") { click_on "None" }
within(".js-check") { click_link "None" }
all("input[type=checkbox]").each do |checkbox|
expect(checkbox).not_to be_checked

View File

@@ -129,11 +129,11 @@ describe "Moderate comments" do
visit moderation_comments_path
within(".js-check") { click_on "All" }
within(".js-check") { click_link "All" }
expect(all("input[type=checkbox]")).to all(be_checked)
within(".js-check") { click_on "None" }
within(".js-check") { click_link "None" }
all("input[type=checkbox]").each do |checkbox|
expect(checkbox).not_to be_checked

View File

@@ -98,11 +98,11 @@ describe "Moderate debates" do
visit moderation_debates_path
within(".js-check") { click_on "All" }
within(".js-check") { click_link "All" }
expect(all("input[type=checkbox]")).to all(be_checked)
within(".js-check") { click_on "None" }
within(".js-check") { click_link "None" }
all("input[type=checkbox]").each do |checkbox|
expect(checkbox).not_to be_checked

View File

@@ -109,11 +109,11 @@ describe "Moderate proposal notifications" do
visit moderation_proposal_notifications_path
within(".js-check") { click_on "All" }
within(".js-check") { click_link "All" }
expect(all("input[type=checkbox]")).to all(be_checked)
within(".js-check") { click_on "None" }
within(".js-check") { click_link "None" }
all("input[type=checkbox]").each do |checkbox|
expect(checkbox).not_to be_checked

View File

@@ -97,11 +97,11 @@ describe "Moderate proposals" do
visit moderation_proposals_path
within(".js-check") { click_on "All" }
within(".js-check") { click_link "All" }
expect(all("input[type=checkbox]")).to all(be_checked)
within(".js-check") { click_on "None" }
within(".js-check") { click_link "None" }
all("input[type=checkbox]").each do |checkbox|
expect(checkbox).not_to be_checked

View File

@@ -32,8 +32,8 @@ describe "SDGManagement" do
login_as(user)
visit root_path
click_on "Menu"
click_on "SDG content"
click_link "Menu"
click_link "SDG content"
expect(page).to have_current_path(sdg_management_root_path)
expect(page).to have_css ".sdg-content-menu"