Use Capybara methods to find/click/check links

We applied the Capybara/SpecificMatcher in commit f52a86b46.  However,
this rule doesn't convert methods finding <a> tags to methods finding
links because <a> tags only count as links when they've got the `href`
attribute. For instance, in the `xss_spec.rb` file we check what happens
when clicking on an anchor tag because we're testing that the `href`
attribute has been removed and so we can't use `click_link`.

So, basically, we can't enable a rule to automatically detect when we're
using `have_css` instead of `have_link`, but we should still do it
because `have_link` adds an extra check which affects accessibility
since it makes sure the tag has the `href` attribute and so it's
recognizable as a link by screen readers.
This commit is contained in:
Javi Martín
2023-09-10 22:19:01 +02:00
parent 614b4fbe4c
commit ea913f9332
15 changed files with 42 additions and 41 deletions

View File

@@ -5,13 +5,13 @@ describe Admin::ActionComponent do
it "includes an HTML class for the action by default" do
render_inline Admin::ActionComponent.new(:edit, double, path: "/")
expect(page).to have_css "a.edit-link.admin-action"
expect(page).to have_link class: %w[edit-link admin-action]
end
it "keeps the admin-action class when the class is overwritten" do
render_inline Admin::ActionComponent.new(:edit, double, path: "/", class: "modify-link")
expect(page).to have_css "a.modify-link.admin-action"
expect(page).to have_link class: %w[modify-link admin-action]
expect(page).not_to have_css ".edit-link"
end
end
@@ -28,7 +28,7 @@ describe Admin::ActionComponent do
render_inline Admin::ActionComponent.new(:edit, record, path: "/")
expect(page).to have_css "a.edit-link#edit_computer_1"
expect(page).to have_link class: "edit-link", id: "edit_computer_1"
end
it "can be overwritten" do
@@ -36,7 +36,7 @@ describe Admin::ActionComponent do
render_inline Admin::ActionComponent.new(:edit, record, path: "/", id: "my_id")
expect(page).to have_css "a.edit-link#my_id"
expect(page).to have_link class: "edit-link", id: "my_id"
expect(page).not_to have_css "#edit_computer_1"
end
end