Files
nairobi/spec/system/officing/ballot_sheets_spec.rb
Javi Martín 3f84ab0758 Add test case for adding budget poll results
While writing the test, we noticed it didn't work because the labels
weren't correctly generated, so we're fixing them as well.
2022-03-21 21:33:07 +01:00

47 lines
1.7 KiB
Ruby

require "rails_helper"
describe "Officing ballot sheets" do
let(:budget) { create(:budget, :reviewing_ballots) }
let(:heading) { create(:budget_heading, budget: budget, price: 300) }
let(:poll) { create(:poll, name: "Latest budget poll", budget: budget, ends_at: Date.current) }
let(:booth) { create(:poll_booth, name: "The only booth") }
let(:officer) { create(:poll_officer) }
let!(:admin) { create(:administrator).user }
scenario "Create a ballot sheet for a budget poll" do
create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth)
create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth, date: Date.current)
titles = %w[First Second Third Fourth]
investments = 4.times.map do |n|
create(:budget_investment, :selected, title: titles[n], heading: heading, price: 100)
end
login_as(officer.user)
visit officing_root_path
click_link "Total recounts and results"
within("tr", text: "Latest budget poll") { click_link "Add results" }
select "The only booth", from: "Booth"
fill_in "CSV data", with: "#{investments[0..1].map(&:id).join(",")};#{investments[1..2].map(&:id).join(",")}"
click_button "Save"
expect(page).to have_content "Creation date"
expect(page).to have_content "CSV data"
logout
login_as(admin)
visit admin_budget_path(budget)
click_button "Calculate Winner Investments"
expect(page).to have_content "Winners being calculated"
visit budget_results_path(budget)
within("tr", text: "Second") { expect(page).to have_content("2") }
within("tr", text: "First") { expect(page).to have_content("1") }
within("tr", text: "Third") { expect(page).to have_content("1") }
expect(page).not_to have_content "Fourth"
end
end