From 3f84ab0758f14b42d1b2b6cf8408bdb0bcb01582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 21 Mar 2022 20:12:18 +0100 Subject: [PATCH] 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. --- app/views/officing/ballot_sheets/new.html.erb | 4 +- spec/system/officing/ballot_sheets_spec.rb | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 spec/system/officing/ballot_sheets_spec.rb diff --git a/app/views/officing/ballot_sheets/new.html.erb b/app/views/officing/ballot_sheets/new.html.erb index a715933d0..4fbc871ca 100644 --- a/app/views/officing/ballot_sheets/new.html.erb +++ b/app/views/officing/ballot_sheets/new.html.erb @@ -2,12 +2,12 @@

<%= t("officing.poll_budgets.new.title", poll_budget: @poll.name) %>

<%= form_tag(officing_poll_ballot_sheets_path(@poll)) do %> - + <%= label_tag :officer_assignment_id, t("officing.poll_budgets.new.booth") %> <%= select_tag :officer_assignment_id, booths_for_officer_select_options(@officer_assignments), { prompt: t("officing.poll_budgets.new.select_booth") } %> - + <%= label_tag :data, t("officing.poll_budgets.new.csv_data") %> <%= text_area_tag :data, nil, rows: 10 %> <%= submit_tag t("officing.poll_budgets.new.submit"), class: "button" %> diff --git a/spec/system/officing/ballot_sheets_spec.rb b/spec/system/officing/ballot_sheets_spec.rb new file mode 100644 index 000000000..b6d50acb4 --- /dev/null +++ b/spec/system/officing/ballot_sheets_spec.rb @@ -0,0 +1,46 @@ +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