Files
grecia/spec/components/budgets/investments/ballot_component_spec.rb
dependabot[bot] af0128860f Bump view_component from 2.78.0 to 3.5.0
Note version 3.0 removed the `controller` and `request` methods used in
component tests, introducing `vc_test_controller` and `vc_test_request`
instead.

Bumps [view_component](https://github.com/viewcomponent/view_component) from 2.78.0 to 3.5.0.
- [Release notes](https://github.com/viewcomponent/view_component/releases)
- [Changelog](https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/viewcomponent/view_component/compare/v2.78.0...v3.5.0)

---
updated-dependencies:
- dependency-name: view_component
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-05 14:17:36 +02:00

87 lines
2.7 KiB
Ruby

require "rails_helper"
describe Budgets::Investments::BallotComponent do
describe "vote investment button" do
let(:budget) { create(:budget, :balloting) }
let(:investment) { create(:budget_investment, :selected, title: "New Sports Center", budget: budget) }
let(:component) do
Budgets::Investments::BallotComponent.new(
investment: investment,
investment_ids: [],
ballot: Budget::Ballot.where(budget: budget, user: vc_test_controller.current_user).first_or_create!
)
end
it "is shown alongside a 'not allowed' message to unverified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_button "Vote"
expect(page).to have_content "Only verified users can vote on investments; verify your account."
end
it "is shown to verified users" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).to have_button count: 1
expect(page).to have_button "Vote", title: "Support this project"
expect(page).to have_button "Vote New Sports Center"
expect(page).not_to have_button "Remove vote", disabled: :all
end
it "is replaced with a button to remove the vote when the user has already voted" do
sign_in(create(:user, :level_two, ballot_lines: [investment]))
render_inline component
expect(page).to have_button count: 1
expect(page).to have_button "Remove vote"
expect(page).to have_button "Remove your vote for New Sports Center"
expect(page).not_to have_button "Vote", disabled: :all
end
end
describe "price" do
let(:budget) { create(:budget, :approval, :balloting) }
let(:investment) { create(:budget_investment, :selected, price: 20, budget: budget) }
let(:component) do
Budgets::Investments::BallotComponent.new(
investment: investment,
investment_ids: [],
ballot: Budget::Ballot.where(budget: budget, user: vc_test_controller.current_user).first_or_create!
)
end
it "is shown when the budget has not hidey_money active" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).to have_content "€20"
end
context "when the budget has hidey_money active" do
before { budget.update!(hide_money: true) }
it "is not shown when the user has already voted" do
sign_in(create(:user, :level_two, ballot_lines: [investment]))
render_inline component
expect(page).not_to have_content "€20"
end
it "is not shown when the user has not already voted" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).not_to have_content "€20"
end
end
end
end