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:
@@ -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
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Admin::TableActionsComponent, :admin do
|
||||
render_inline Admin::TableActionsComponent.new(record)
|
||||
|
||||
expect(page).to have_link count: 1
|
||||
expect(page).to have_css "a[href*='edit']", exact_text: "Edit"
|
||||
expect(page).to have_link "Edit", href: /edit/
|
||||
expect(page).to have_css "a[aria-label='Edit Important!']"
|
||||
|
||||
expect(page).to have_button count: 1
|
||||
@@ -56,7 +56,7 @@ describe Admin::TableActionsComponent, :admin do
|
||||
it "allows custom options" do
|
||||
render_inline Admin::TableActionsComponent.new(record, edit_options: { id: "edit_me" })
|
||||
|
||||
expect(page).to have_css "a#edit_me"
|
||||
expect(page).to have_link id: "edit_me"
|
||||
end
|
||||
|
||||
it "allows custom content" do
|
||||
@@ -64,7 +64,7 @@ describe Admin::TableActionsComponent, :admin do
|
||||
"<a href='/'>Main</a>".html_safe
|
||||
end
|
||||
|
||||
expect(page).to have_css "a", count: 2
|
||||
expect(page).to have_link count: 2
|
||||
expect(page).to have_link "Main", href: "/"
|
||||
expect(page).to have_link "Edit"
|
||||
|
||||
@@ -77,7 +77,7 @@ describe Admin::TableActionsComponent, :admin do
|
||||
render_inline Admin::TableActionsComponent.new(create(:sdg_local_target))
|
||||
|
||||
expect(page).to have_link count: 1
|
||||
expect(page).to have_css "a[href^='/sdg_management/'][href*='edit']", exact_text: "Edit"
|
||||
expect(page).to have_link "Edit", href: /\A\/sdg_management\/(.+)edit/
|
||||
|
||||
expect(page).to have_button count: 1
|
||||
expect(page).to have_css "form[action^='/sdg_management/']", exact_text: "Delete"
|
||||
|
||||
@@ -11,7 +11,6 @@ describe Budgets::PhasesComponent do
|
||||
budget.current_phase.update!(main_link_text: "Phase link!", main_link_url: "https://consuldemocracy.org")
|
||||
render_inline Budgets::PhasesComponent.new(budget)
|
||||
|
||||
expect(page).to have_css(".main-link")
|
||||
expect(page).to have_link("Phase link!", href: "https://consuldemocracy.org")
|
||||
expect(page).to have_link "Phase link!", href: "https://consuldemocracy.org", class: "main-link"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ describe SDGManagement::MenuComponent do
|
||||
it "does not generate links to any processes" do
|
||||
render_inline component
|
||||
|
||||
expect(page).to have_css "a", count: 2
|
||||
expect(page).to have_link count: 2
|
||||
expect(page).to have_link "Goals and Targets"
|
||||
expect(page).to have_link "SDG homepage"
|
||||
end
|
||||
@@ -57,7 +57,7 @@ describe SDGManagement::MenuComponent do
|
||||
it "does not generate links to any processes" do
|
||||
render_inline component
|
||||
|
||||
expect(page).to have_css "a", count: 2
|
||||
expect(page).to have_link count: 2
|
||||
expect(page).to have_link "Goals and Targets"
|
||||
expect(page).to have_link "SDG homepage"
|
||||
end
|
||||
|
||||
@@ -44,9 +44,9 @@ describe Shared::LinkListComponent do
|
||||
["Home", "/", class: "root"], ["Info", "/info", id: "info"]
|
||||
)
|
||||
|
||||
expect(page).to have_css "a", count: 2
|
||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||
expect(page).to have_link count: 2
|
||||
expect(page).to have_link "Home", class: "root", count: 1
|
||||
expect(page).to have_link "Info", id: "info", count: 1
|
||||
end
|
||||
|
||||
it "ignores nil entries" do
|
||||
@@ -55,8 +55,8 @@ describe Shared::LinkListComponent do
|
||||
)
|
||||
|
||||
expect(page).to have_css "li", count: 2
|
||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||
expect(page).to have_link "Home", class: "root", count: 1
|
||||
expect(page).to have_link "Info", id: "info", count: 1
|
||||
end
|
||||
|
||||
it "ignores empty entries" do
|
||||
@@ -65,8 +65,8 @@ describe Shared::LinkListComponent do
|
||||
)
|
||||
|
||||
expect(page).to have_css "li", count: 2
|
||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||
expect(page).to have_link "Home", class: "root", count: 1
|
||||
expect(page).to have_link "Info", id: "info", count: 1
|
||||
end
|
||||
|
||||
it "accepts an optional condition to check the active element" do
|
||||
@@ -90,8 +90,8 @@ describe Shared::LinkListComponent do
|
||||
expect(page).to have_css "li", count: 3
|
||||
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
|
||||
|
||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||
expect(page).to have_link "Home", class: "root", count: 1
|
||||
expect(page).to have_link "Info", id: "info", count: 1
|
||||
expect(page).to have_css "a[rel='help']", count: 1, exact_text: "Help"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user