Merge pull request #5744 from consuldemocracy/select_name

Associate all select fields with labels
This commit is contained in:
Javi Martín
2024-11-12 16:22:37 +01:00
committed by GitHub
37 changed files with 188 additions and 208 deletions

View File

@@ -0,0 +1,26 @@
require "rails_helper"
describe Shared::DateOfBirthFieldComponent do
before do
dummy_model = Class.new do
include ActiveModel::Model
attr_accessor :date_of_birth
end
stub_const("DummyModel", dummy_model)
end
let(:form) { ConsulFormBuilder.new(:dummy, DummyModel.new, ApplicationController.new.view_context, {}) }
let(:component) { Shared::DateOfBirthFieldComponent.new(form) }
it "uses the minimum required age as the latest date by default" do
Setting["min_age_to_participate"] = 13
travel_to "2015-07-15" do
render_inline component
expect(page).to have_field "Date of birth"
expect(page).to have_css "input[type=date][min='1900-01-01'][max='2002-07-15']"
end
end
end

View File

@@ -84,18 +84,14 @@ describe Officing::Residence do
describe "dates" do
it "is not valid but not because date of birth" do
custom_residence = Officing::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980")
custom_residence = Officing::Residence.new(date_of_birth: "1980-01-01")
expect(custom_residence).not_to be_valid
expect(custom_residence.errors[:date_of_birth]).to be_empty
end
it "is not valid without a date of birth" do
custom_residence = Officing::Residence.new("date_of_birth(3i)" => "",
"date_of_birth(2i)" => "",
"date_of_birth(1i)" => "")
custom_residence = Officing::Residence.new(date_of_birth: "")
expect(custom_residence).not_to be_valid
expect(custom_residence.errors[:date_of_birth]).to include("can't be blank")
end

View File

@@ -57,17 +57,13 @@ describe Verification::Management::Document do
describe "dates" do
it "is valid with a valid date of birth" do
verification_document = Verification::Management::Document.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980")
verification_document = Verification::Management::Document.new(date_of_birth: "1980-01-01")
expect(verification_document.errors[:date_of_birth]).to be_empty
end
it "is not valid without a date of birth" do
verification_document = Verification::Management::Document.new("date_of_birth(3i)" => "",
"date_of_birth(2i)" => "",
"date_of_birth(1i)" => "")
verification_document = Verification::Management::Document.new(date_of_birth: "")
expect(verification_document).not_to be_valid
expect(verification_document.errors[:date_of_birth]).to include("can't be blank")
end

View File

@@ -11,26 +11,20 @@ describe Verification::Residence do
describe "dates" do
it "is valid with a valid date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980")
residence = Verification::Residence.new(date_of_birth: "1980-01-01")
expect(residence.errors[:date_of_birth]).to be_empty
end
it "is not valid without a date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "",
"date_of_birth(2i)" => "",
"date_of_birth(1i)" => "")
residence = Verification::Residence.new(date_of_birth: "")
expect(residence).not_to be_valid
expect(residence.errors[:date_of_birth]).to include("can't be blank")
end
end
it "validates user has allowed age" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => 5.years.ago.year.to_s)
residence = Verification::Residence.new(date_of_birth: 5.years.ago)
expect(residence).not_to be_valid
expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate")
end

View File

@@ -1,17 +1,8 @@
module Verifications
def select_date(values, selector)
selector = selector[:from]
day, month, year = values.split("-")
select day, from: "#{selector}_3i"
select month, from: "#{selector}_2i"
select year, from: "#{selector}_1i"
end
def verify_residence
select "DNI", from: "residence_document_type"
fill_in "residence_document_number", with: "12345678Z"
select_date "31-#{I18n.l(Date.current.at_end_of_year, format: "%B")}-1980",
from: "residence_date_of_birth"
fill_in "residence_date_of_birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"

View File

@@ -26,7 +26,7 @@ describe "Admin download user emails" do
visit admin_emails_download_index_path
within("#admin_download_emails") do
select "Administrators", from: "users_segment"
select "Administrators", from: "Download email addresses"
click_button "Download emails list"
end

View File

@@ -84,9 +84,7 @@ describe "Admin local census records", :admin do
select "DNI", from: :local_census_record_document_type
fill_in :local_census_record_document_number, with: "#DOCUMENT"
select "1982", from: :local_census_record_date_of_birth_1i
select "July", from: :local_census_record_date_of_birth_2i
select "7", from: :local_census_record_date_of_birth_3i
fill_in "Date of birth", with: Date.new(1982, 7, 7)
fill_in :local_census_record_postal_code, with: "07003"
click_button "Save"
@@ -116,9 +114,7 @@ describe "Admin local census records", :admin do
select "Passport", from: :local_census_record_document_type
fill_in :local_census_record_document_number, with: "#NIE_NUMBER"
select "1982", from: :local_census_record_date_of_birth_1i
select "August", from: :local_census_record_date_of_birth_2i
select "8", from: :local_census_record_date_of_birth_3i
fill_in "Date of birth", with: Date.new(1982, 8, 8)
fill_in :local_census_record_postal_code, with: "07007"
click_button "Save"

View File

@@ -53,10 +53,10 @@ describe "Admin shifts", :admin do
click_button "Search"
click_link "Edit shifts"
expect(page).to have_select("shift_date_vote_collection_date",
options: ["Select day", *vote_collection_dates])
expect(page).not_to have_select("shift_date_recount_scrutiny_date")
select I18n.l(Date.current, format: :long), from: "shift_date_vote_collection_date"
expect(page).to have_select "Date", options: ["Select day", *vote_collection_dates]
expect(page).not_to have_select with_options: recount_scrutiny_dates
select I18n.l(Date.current, format: :long), from: "Date"
click_button "Add shift"
expect(page).to have_content "Shift added"
@@ -82,10 +82,9 @@ describe "Admin shifts", :admin do
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date",
options: ["Select day", *recount_scrutiny_dates])
expect(page).not_to have_select("shift_date_vote_collection_date")
select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "shift_date_recount_scrutiny_date"
expect(page).to have_select "Date", options: ["Select day", *recount_scrutiny_dates]
expect(page).not_to have_select with_options: vote_collection_dates
select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "Date"
click_button "Add shift"
expect(page).to have_content "Shift added"
@@ -126,11 +125,9 @@ describe "Admin shifts", :admin do
click_button "Search"
click_link "Edit shifts"
expect(page).to have_select("shift_date_vote_collection_date",
options: ["Select day", *vote_collection_dates])
expect(page).to have_select "Date", options: ["Select day", *vote_collection_dates]
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date",
options: ["Select day", *recount_scrutiny_dates])
expect(page).to have_select "Date", options: ["Select day", *recount_scrutiny_dates]
end
scenario "Change option from Recount & Scrutinity to Collect Votes" do
@@ -144,11 +141,11 @@ describe "Admin shifts", :admin do
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day"])
expect(page).to have_select "Date", options: ["Select day"]
select "Collect Votes", from: "shift_task"
expect(page).to have_select("shift_date_vote_collection_date", options: ["Voting days ended"])
expect(page).to have_select "Date", options: ["Voting days ended"]
end
scenario "Error on create" do

View File

@@ -103,7 +103,7 @@ describe "Poll budget ballot sheets" do
scenario "Ballot sheet is saved" do
visit new_officing_poll_ballot_sheet_path(poll)
select booth.name, from: "officer_assignment_id"
select booth.name, from: "Booth"
fill_in "data", with: "1234;5678"
click_button "Save"
@@ -119,7 +119,7 @@ describe "Poll budget ballot sheets" do
scenario "Ballot sheet is not saved" do
visit new_officing_poll_ballot_sheet_path(poll)
select booth.name, from: "officer_assignment_id"
select booth.name, from: "Booth"
click_button "Save"
expect(page).to have_content("CSV data can't be blank")

View File

@@ -63,7 +63,7 @@ describe "DocumentVerifications" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
select_date "31-December-1980", from: "document_verification_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "document_verification_postal_code", with: "inexisting"
click_button "Check document"
@@ -77,7 +77,7 @@ describe "DocumentVerifications" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
select_date "31-December-1980", from: "document_verification_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "document_verification_postal_code", with: "28013"
click_button "Check document"

View File

@@ -13,7 +13,7 @@ describe "Users" do
fill_in "user_username", with: "pepe"
fill_in "user_email", with: "pepe@gmail.com"
select_date "31-December-1980", from: "user_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
click_button "Create user"
@@ -54,7 +54,7 @@ describe "Users" do
fill_in "user_username", with: "Kelly Sue"
fill_in "user_email", with: ""
select_date "31-December-1980", from: "user_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
click_button "Create user"

View File

@@ -47,7 +47,7 @@ describe "Booth", :with_frozen_time do
expect(page).to have_content "Choose your booth"
select booth2.location, from: "booth_id"
select booth2.location, from: "Choose your booth"
click_button "Enter"
within("#officing-booth") do
@@ -72,6 +72,6 @@ describe "Booth", :with_frozen_time do
expect(page).to have_content "Choose your booth"
expect(page).to have_select("booth_id", options: [booth1.location, booth2.location])
expect(page).to have_select "Choose your booth", options: [booth1.location, booth2.location]
end
end

View File

@@ -162,7 +162,7 @@ describe "Residence", :with_frozen_time do
select "DNI", from: "residence_document_type"
fill_in "residence_document_number", with: "12345678Z"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
click_button "Validate document"

View File

@@ -57,7 +57,7 @@ describe "Officing Results", :with_frozen_time do
expect(page).not_to have_content("Your results")
select booth.name, from: "officer_assignment_id"
select booth.name, from: "Booth"
fill_in "questions[#{question_1.id}][0]", with: "100"
fill_in "questions[#{question_1.id}][1]", with: "200"
@@ -100,7 +100,7 @@ describe "Officing Results", :with_frozen_time do
visit new_officing_poll_result_path(poll)
booth_name = partial_result.booth_assignment.booth.name
select booth_name, from: "officer_assignment_id"
select booth_name, from: "Booth"
fill_in "questions[#{question_1.id}][0]", with: "5555"
fill_in "questions[#{question_1.id}][1]", with: "200"

View File

@@ -12,7 +12,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
click_button "Verify residence"
@@ -30,7 +30,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
click_button "Verify residence"
@@ -38,21 +38,6 @@ describe "Residence" do
expect(page).to have_content "Residence verified"
end
scenario "Residence form use min age to participate" do
min_age = (Setting["min_age_to_participate"] = 16).to_i
underage = min_age - 1
user = create(:user)
login_as(user)
visit account_path
click_link "Verify my account"
expect(page).to have_select("residence_date_of_birth_1i",
with_options: [min_age.years.ago.year])
expect(page).not_to have_select("residence_date_of_birth_1i",
with_options: [underage.years.ago.year])
end
scenario "When trying to verify a deregistered account old votes are reassigned" do
erased_user = create(:user, document_number: "12345678Z", document_type: "1", erased_at: Time.current)
vote = create(:vote, voter: erased_user)
@@ -65,7 +50,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
@@ -100,9 +85,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select "1997", from: "residence_date_of_birth_1i"
select "January", from: "residence_date_of_birth_2i"
select "1", from: "residence_date_of_birth_3i"
fill_in "Date of birth", with: Date.new(1997, 1, 1)
fill_in "residence_postal_code", with: "00000"
check "residence_terms_of_service"
@@ -120,9 +103,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select "1997", from: "residence_date_of_birth_1i"
select "January", from: "residence_date_of_birth_2i"
select "1", from: "residence_date_of_birth_3i"
fill_in "Date of birth", with: Date.new(1997, 1, 1)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
@@ -141,9 +122,7 @@ describe "Residence" do
5.times do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select "1997", from: "residence_date_of_birth_1i"
select "January", from: "residence_date_of_birth_2i"
select "1", from: "residence_date_of_birth_3i"
fill_in "Date of birth", with: Date.new(1997, 1, 1)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"