Use number fields to enter number of votes

This way the fields are easier to use, and we can get rid of the
placeholders.

Note we're simplifying the `answer_result_value` in order to make it
easier to return `0` instead of `nil` when the field is empty.

Also note there's a small change of behavior here; previously, these
fields were empty by default, and now their value is `0` by default, so
blindly clicking the "Save" button would send `0` instead of an empty
value. I don't think it's a big deal, though, but we need to keep that
in mind.
This commit is contained in:
Javi Martín
2025-04-02 19:20:21 +02:00
parent ff3ada780d
commit 9308189a00
3 changed files with 24 additions and 9 deletions

View File

@@ -0,0 +1,19 @@
require "rails_helper"
describe Officing::Results::FormComponent do
let(:poll) { create(:poll, ends_at: 1.day.ago) }
before { create(:poll_question, :yes_no, poll: poll, title: "Agreed?") }
it "uses number fields with 0 as a default value" do
render_inline Officing::Results::FormComponent.new(poll, Poll::OfficerAssignment.none)
page.find(:fieldset, "Agreed?") do |fieldset|
expect(fieldset).to have_field "Yes", with: 0, type: :number
expect(fieldset).to have_field "No", with: 0, type: :number
end
expect(page).to have_field "Totally blank ballots", with: 0, type: :number
expect(page).to have_field "Invalid ballots", with: 0, type: :number
expect(page).to have_field "Valid ballots", with: 0, type: :number
end
end