Files
nairobi/spec/components/legislation/proposals/votes_component_spec.rb
Javi Martín 86ad2df46d Unify code in debates/legislation vote links
We were using the same code to render links to agree and disagree, so we
can extract a new component for this code.

We're also adding component tests to make it easier to test whether
we're breaking anything while refactoring, although the code is probably
already covered by system tests.

Since the votes mixin was only used in one place, we're removing it and
moving most of its code to a new CSS file for the shared component.
2022-02-21 18:47:13 +01:00

43 lines
1.3 KiB
Ruby

require "rails_helper"
describe Legislation::Proposals::VotesComponent do
let(:proposal) { create(:legislation_proposal, title: "Require wearing masks at home") }
let(:component) { Legislation::Proposals::VotesComponent.new(proposal) }
describe "Agree and disagree links" do
it "is not shown when the proposals phase isn't open" do
proposal.process.update!(
proposals_phase_start_date: 2.days.ago,
proposals_phase_end_date: Date.yesterday
)
sign_in(create(:user))
render_inline component
expect(page).not_to have_content "I agree"
expect(page).not_to have_content "I disagree"
end
it "is shown as plain text to anonymous users" do
render_inline component
expect(page).to have_content "I agree"
expect(page).to have_content "I disagree"
expect(page).to have_content "You must sign in or sign up to continue."
expect(page).not_to have_link "I agree"
expect(page).not_to have_link "I disagree"
end
it "is shown to identified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_link count: 2
expect(page).to have_link "I agree", title: "I agree"
expect(page).to have_link "I disagree", title: "I disagree"
expect(page).not_to have_content "You must sign in or sign up to continue."
end
end
end