Files
grecia/spec/components/budgets/ballot/ballot_component_spec.rb
CoslaJohn c4d8c92ae2 Change the order in which votes are displayed to be in the order they were selected by the voter
Note that the `budget` parameter was added to the `delete_path` method
so it works in the tests; on production, it worked because this
component is only rendered on pages which already have the `budget`
parameter.

Co-authored-by: Javi Martín <javim@elretirao.net>
2024-04-04 18:47:03 +02:00

65 lines
2.6 KiB
Ruby

require "rails_helper"
describe Budgets::Ballot::BallotComponent do
include Rails.application.routes.url_helpers
before { vc_test_request.session[:ballot_referer] = "/" }
let(:budget) { create(:budget, :balloting) }
let(:ballot) { create(:budget_ballot, user: create(:user), budget: budget) }
describe "link to group" do
let(:group) { create(:budget_group, budget: budget) }
context "group with a single heading" do
let!(:heading) { create(:budget_heading, group: group, price: 1000) }
it "displays a link to vote investments when there aren't any investments in the ballot" do
render_inline Budgets::Ballot::BallotComponent.new(ballot)
expect(page).to have_link "You have not voted on this group yet, go vote!",
href: budget_investments_path(budget, heading_id: heading.id)
end
it "displays a link to continue voting when there are investments in the ballot" do
ballot.investments << create(:budget_investment, :selected, heading: heading, price: 200)
render_inline Budgets::Ballot::BallotComponent.new(ballot)
expect(page).to have_link "Still available to you €800",
href: budget_investments_path(budget, heading_id: heading.id)
end
end
context "group with multiple headings" do
let!(:heading) { create(:budget_heading, group: group, price: 1000) }
before { create(:budget_heading, group: group) }
it "displays a link to vote on a heading when there aren't any investments in the ballot" do
render_inline Budgets::Ballot::BallotComponent.new(ballot)
expect(page).to have_link "You have not voted on this group yet, go vote!",
href: budget_group_path(budget, group)
end
it "displays a link to change the heading when there are invesments in the ballot" do
ballot.investments << create(:budget_investment, :selected, heading: heading, price: 200)
render_inline Budgets::Ballot::BallotComponent.new(ballot)
expect(page).to have_link "Still available to you €800",
href: budget_group_path(budget, group)
end
end
end
it "sorts investments by ballot lines" do
["B letter", "A letter", "C letter"].each do |title|
ballot.add_investment(create(:budget_investment, :selected, budget: budget, title: title))
end
render_inline Budgets::Ballot::BallotComponent.new(ballot)
expect("B letter").to appear_before "A letter"
expect("A letter").to appear_before "C letter"
end
end