Files
nairobi/spec/components/sdg_management/menu_component_spec.rb
Javi Martín ea913f9332 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.
2023-09-11 14:10:41 +02:00

102 lines
3.1 KiB
Ruby

require "rails_helper"
describe SDGManagement::MenuComponent do
let(:component) { SDGManagement::MenuComponent.new }
before do
Setting["feature.sdg"] = true
Setting["sdg.process.budgets"] = true
Setting["sdg.process.debates"] = true
Setting["sdg.process.legislation"] = true
Setting["sdg.process.polls"] = true
Setting["sdg.process.proposals"] = true
end
context "processes enabled" do
it "generates links to all processes" do
render_inline component
expect(page).to have_link "Goals and Targets"
expect(page).to have_link "SDG homepage"
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Debates"
expect(page).to have_link "Legislation processes"
expect(page).to have_link "Legislation proposals"
expect(page).to have_link "Polls"
expect(page).to have_link "Proposals"
end
end
context "processes disabled" do
before do
Setting["process.budgets"] = false
Setting["process.debates"] = false
Setting["process.legislation"] = false
Setting["process.polls"] = false
Setting["process.proposals"] = false
end
it "does not generate links to any processes" do
render_inline component
expect(page).to have_link count: 2
expect(page).to have_link "Goals and Targets"
expect(page).to have_link "SDG homepage"
end
end
context "SDG processes disabled" do
before do
Setting["sdg.process.budgets"] = false
Setting["sdg.process.debates"] = false
Setting["sdg.process.legislation"] = false
Setting["sdg.process.polls"] = false
Setting["sdg.process.proposals"] = false
end
it "does not generate links to any processes" do
render_inline component
expect(page).to have_link count: 2
expect(page).to have_link "Goals and Targets"
expect(page).to have_link "SDG homepage"
end
end
context "one process disabled" do
before { Setting["process.debates"] = false }
it "generates links to the enabled processes" do
render_inline component
expect(page).to have_link "Goals and Targets"
expect(page).to have_link "SDG homepage"
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Legislation processes"
expect(page).to have_link "Legislation proposals"
expect(page).to have_link "Polls"
expect(page).to have_link "Proposals"
expect(page).not_to have_link "Debates"
end
end
context "one SDG process disabled" do
before { Setting["sdg.process.legislation"] = false }
it "generates links to the enabled processes" do
render_inline component
expect(page).to have_link "Goals and Targets"
expect(page).to have_link "SDG homepage"
expect(page).to have_link "Debates"
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Polls"
expect(page).to have_link "Proposals"
expect(page).not_to have_link "Legislation processes"
expect(page).not_to have_link "Legislation proposals"
end
end
end