Files
grecia/spec/components/budgets/investments/votes_component_spec.rb
Javi Martín 9247a31e85 Stub current_user in all component tests
The `sign_in(nil)` method was a bit hard to understand IMHO. After all,
in controller and system tests we don't have to specify no user is
signed in; that's the default behavior.

So we're making it the default behavior for component tests as well.
2021-09-08 12:39:36 +02:00

42 lines
1.4 KiB
Ruby

require "rails_helper"
describe Budgets::Investments::VotesComponent do
describe "vote link" do
context "when investment shows votes" do
let(:investment) { create(:budget_investment, title: "Renovate sidewalks in Main Street") }
let(:component) { Budgets::Investments::VotesComponent.new(investment) }
before { allow(investment).to receive(:should_show_votes?).and_return(true) }
it "displays a button to support the investment to identified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_button count: 1
expect(page).to have_button "Support", title: "Support this project", disabled: false
expect(page).to have_button "Support Renovate sidewalks in Main Street"
end
it "disables the button to support the investment to unidentified users" do
render_inline component
expect(page).to have_button count: 1, disabled: :all
expect(page).to have_button "Support", disabled: true
end
it "shows the button to remove support when users have supported the investment" do
user = create(:user)
user.up_votes(investment)
sign_in(user)
render_inline component
expect(page).to have_button count: 1, disabled: :all
expect(page).to have_button "Remove your support"
expect(page).to have_button "Remove your support to Renovate sidewalks in Main Street"
end
end
end
end