From b1a384e454ef266c41a7220c9514c2cd44eb1f5c Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:41:40 +0000 Subject: [PATCH] Update person relationship questions (#2892) --- .../lettings/pages/person_lead_partner.rb | 12 ++ .../form/lettings/questions/person_partner.rb | 30 ++++ .../subsections/household_characteristics.rb | 22 ++- .../lettings/household_characteristics.en.yml | 28 ++-- .../pages/person_lead_partner_spec.rb | 51 ++++++ .../lettings/questions/person_partner_spec.rb | 57 +++++++ .../household_characteristics_spec.rb | 156 ++++++++++++++++++ 7 files changed, 335 insertions(+), 21 deletions(-) create mode 100644 app/models/form/lettings/pages/person_lead_partner.rb create mode 100644 app/models/form/lettings/questions/person_partner.rb create mode 100644 spec/models/form/lettings/pages/person_lead_partner_spec.rb create mode 100644 spec/models/form/lettings/questions/person_partner_spec.rb diff --git a/app/models/form/lettings/pages/person_lead_partner.rb b/app/models/form/lettings/pages/person_lead_partner.rb new file mode 100644 index 000000000..30613d976 --- /dev/null +++ b/app/models/form/lettings/pages/person_lead_partner.rb @@ -0,0 +1,12 @@ +class Form::Lettings::Pages::PersonLeadPartner < ::Form::Page + def initialize(id, hsh, subsection, person_index:) + super(id, hsh, subsection) + @id = "person_#{person_index}_lead_partner" + @depends_on = [{ "details_known_#{person_index}" => 0 }] + @person_index = person_index + end + + def questions + @questions ||= [Form::Lettings::Questions::PersonPartner.new(nil, nil, self, person_index: @person_index)] + end +end diff --git a/app/models/form/lettings/questions/person_partner.rb b/app/models/form/lettings/questions/person_partner.rb new file mode 100644 index 000000000..25c2d72c1 --- /dev/null +++ b/app/models/form/lettings/questions/person_partner.rb @@ -0,0 +1,30 @@ +class Form::Lettings::Questions::PersonPartner < ::Form::Question + def initialize(id, hsh, page, person_index:) + super(id, hsh, page) + @id = "relat#{person_index}" + @type = "radio" + @check_answers_card_number = person_index + @answer_options = answer_options + @person_index = person_index + @question_number = question_number + end + + def answer_options + { + "P" => { "value" => "Yes" }, + "X" => { "value" => "No" }, + "R" => { "value" => "Tenant prefers not to say" }, + } + end + + def question_number + base_question_number = case form.start_date.year + when 2023 + 30 + else + 29 + end + + base_question_number + (4 * @person_index) + end +end diff --git a/app/models/form/lettings/subsections/household_characteristics.rb b/app/models/form/lettings/subsections/household_characteristics.rb index 61334d84c..a454ffed5 100644 --- a/app/models/form/lettings/subsections/household_characteristics.rb +++ b/app/models/form/lettings/subsections/household_characteristics.rb @@ -32,7 +32,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck.new("working_situation_lead_tenant_under_retirement_value_check", nil, self), Form::Lettings::Pages::LeadTenantOverRetirementValueCheck.new("working_situation_lead_tenant_over_retirement_value_check", nil, self), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 2), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 2), + relationship_question(person_index: 2), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_2_multiple_partners_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2), @@ -52,7 +52,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_2_under_retirement_value_check", nil, self, person_index: 2), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_2_over_retirement_value_check", nil, self, person_index: 2), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 3), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 3), + relationship_question(person_index: 3), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_3_multiple_partners_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3), @@ -72,7 +72,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_3_under_retirement_value_check", nil, self, person_index: 3), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_3_over_retirement_value_check", nil, self, person_index: 3), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 4), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 4), + relationship_question(person_index: 4), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_4_multiple_partners_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4), @@ -92,7 +92,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_4_under_retirement_value_check", nil, self, person_index: 4), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_4_over_retirement_value_check", nil, self, person_index: 4), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 5), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 5), + relationship_question(person_index: 5), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_5_multiple_partners_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5), @@ -112,7 +112,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_5_under_retirement_value_check", nil, self, person_index: 5), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_5_over_retirement_value_check", nil, self, person_index: 5), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 6), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 6), + relationship_question(person_index: 6), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_6_multiple_partners_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6), @@ -132,7 +132,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_6_under_retirement_value_check", nil, self, person_index: 6), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_6_over_retirement_value_check", nil, self, person_index: 6), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 7), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 7), + relationship_question(person_index: 7), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_7_multiple_partners_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7), @@ -152,7 +152,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_7_under_retirement_value_check", nil, self, person_index: 7), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_7_over_retirement_value_check", nil, self, person_index: 7), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 8), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 8), + relationship_question(person_index: 8), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_8_multiple_partners_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8), @@ -173,4 +173,12 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_8_over_retirement_value_check", nil, self, person_index: 8), ].compact end + + def relationship_question(person_index:) + if form.start_year_2025_or_later? + Form::Lettings::Pages::PersonLeadPartner.new(nil, nil, self, person_index:) + else + Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index:) + end + end end diff --git a/config/locales/forms/2025/lettings/household_characteristics.en.yml b/config/locales/forms/2025/lettings/household_characteristics.en.yml index b6d7ad7e9..79646b32b 100644 --- a/config/locales/forms/2025/lettings/household_characteristics.en.yml +++ b/config/locales/forms/2025/lettings/household_characteristics.en.yml @@ -84,9 +84,9 @@ en: relat2: page_header: "" - check_answer_label: "Person 2’s relationship to the lead tenant" + check_answer_label: "Person 2 lead tenant’s partner" hint_text: "" - question_text: "What is person 2’s relationship to the lead tenant?" + question_text: "Is tenant 2 the partner of tenant 1?" age2: page_header: "" @@ -119,9 +119,9 @@ en: relat3: page_header: "" - check_answer_label: "Person 3’s relationship to the lead tenant" + check_answer_label: "Person 3 lead tenant’s partner" hint_text: "" - question_text: "What is person 3’s relationship to the lead tenant?" + question_text: "Is tenant 3 the partner of tenant 1?" age3: page_header: "" @@ -154,9 +154,9 @@ en: relat4: page_header: "" - check_answer_label: "Person 4’s relationship to the lead tenant" + check_answer_label: "Person 4 lead tenant’s partner" hint_text: "" - question_text: "What is person 4’s relationship to the lead tenant?" + question_text: "Is tenant 4 the partner of tenant 1?" age4: page_header: "" @@ -189,9 +189,9 @@ en: relat5: page_header: "" - check_answer_label: "Person 5’s relationship to the lead tenant" + check_answer_label: "Person 5 lead tenant’s partner" hint_text: "" - question_text: "What is person 5’s relationship to the lead tenant?" + question_text: "Is tenant 5 the partner of tenant 1?" age5: page_header: "" @@ -224,9 +224,9 @@ en: relat6: page_header: "" - check_answer_label: "Person 6’s relationship to the lead tenant" + check_answer_label: "Person 6 lead tenant’s partner" hint_text: "" - question_text: "What is person 6’s relationship to the lead tenant?" + question_text: "Is tenant 6 the partner of tenant 1?" age6: page_header: "" @@ -259,9 +259,9 @@ en: relat7: page_header: "" - check_answer_label: "Person 7’s relationship to the lead tenant" + check_answer_label: "Person 7 lead tenant’s partner" hint_text: "" - question_text: "What is person 7’s relationship to the lead tenant?" + question_text: "Is tenant 7 the partner of tenant 1?" age7: page_header: "" @@ -294,9 +294,9 @@ en: relat8: page_header: "" - check_answer_label: "Person 8’s relationship to the lead tenant" + check_answer_label: "Person 8 lead tenant’s partner" hint_text: "" - question_text: "What is person 8’s relationship to the lead tenant?" + question_text: "Is tenant 8 the partner of tenant 1?" age8: page_header: "" diff --git a/spec/models/form/lettings/pages/person_lead_partner_spec.rb b/spec/models/form/lettings/pages/person_lead_partner_spec.rb new file mode 100644 index 000000000..88aa3095d --- /dev/null +++ b/spec/models/form/lettings/pages/person_lead_partner_spec.rb @@ -0,0 +1,51 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection, person_index:) } + + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: true)) } + let(:person_index) { 2 } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has the correct description" do + expect(page.description).to be nil + end + + context "with person 2" do + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + + it "has the correct id" do + expect(page.id).to eq("person_2_lead_partner") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "details_known_2" => 0 }], + ) + end + end + + context "with person 3" do + let(:person_index) { 3 } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat3]) + end + + it "has the correct id" do + expect(page.id).to eq("person_3_lead_partner") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "details_known_3" => 0 }], + ) + end + end +end diff --git a/spec/models/form/lettings/questions/person_partner_spec.rb b/spec/models/form/lettings/questions/person_partner_spec.rb new file mode 100644 index 000000000..7e2d177bd --- /dev/null +++ b/spec/models/form/lettings/questions/person_partner_spec.rb @@ -0,0 +1,57 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do + subject(:question) { described_class.new(nil, question_definition, page, person_index:) } + + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 4), start_year_2025_or_later?: true))) } + let(:person_index) { 2 } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?(nil)).to be false + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq("P" => { "value" => "Yes" }, + "X" => { "value" => "No" }, + "R" => { "value" => "Tenant prefers not to say" }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to be nil + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to be nil + end + + context "with person 2" do + it "has the correct id" do + expect(question.id).to eq("relat2") + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(2) + end + end + + context "with person 3" do + let(:person_index) { 3 } + + it "has the correct id" do + expect(question.id).to eq("relat3") + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end + end +end diff --git a/spec/models/form/lettings/subsections/household_characteristics_spec.rb b/spec/models/form/lettings/subsections/household_characteristics_spec.rb index b45f86fce..5aab3514c 100644 --- a/spec/models/form/lettings/subsections/household_characteristics_spec.rb +++ b/spec/models/form/lettings/subsections/household_characteristics_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod before do allow(section).to receive(:form).and_return(form) + allow(form).to receive(:start_year_2025_or_later?).and_return(false) end it "has correct section" do @@ -304,6 +305,161 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod end end + context "with start year >= 2025" do + before do + allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(form).to receive(:start_year_2025_or_later?).and_return(true) + end + + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[ + household_members + no_females_pregnant_household_lead_hhmemb_value_check + females_in_soft_age_range_in_pregnant_household_lead_hhmemb_value_check + lead_tenant_age + no_females_pregnant_household_lead_age_value_check + females_in_soft_age_range_in_pregnant_household_lead_age_value_check + age_lead_tenant_under_retirement_value_check + age_lead_tenant_over_retirement_value_check + lead_tenant_gender_identity + no_females_pregnant_household_lead_value_check + females_in_soft_age_range_in_pregnant_household_lead_value_check + gender_lead_tenant_over_retirement_value_check + lead_tenant_ethnic_group + lead_tenant_ethnic_background_arab + lead_tenant_ethnic_background_asian + lead_tenant_ethnic_background_black + lead_tenant_ethnic_background_mixed + lead_tenant_ethnic_background_white + lead_tenant_nationality + lead_tenant_working_situation + working_situation_lead_tenant_under_retirement_value_check + working_situation_lead_tenant_over_retirement_value_check + person_2_known + person_2_lead_partner + relationship_2_partner_under_16_value_check + relationship_2_multiple_partners_value_check + person_2_age + no_females_pregnant_household_person_2_age_value_check + females_in_soft_age_range_in_pregnant_household_person_2_age_value_check + age_2_under_retirement_value_check + age_2_over_retirement_value_check + age_2_partner_under_16_value_check + person_2_gender_identity + no_females_pregnant_household_person_2_value_check + females_in_soft_age_range_in_pregnant_household_person_2_value_check + gender_2_over_retirement_value_check + person_2_working_situation + working_situation_2_under_retirement_value_check + working_situation_2_over_retirement_value_check + person_3_known + person_3_lead_partner + relationship_3_partner_under_16_value_check + relationship_3_multiple_partners_value_check + person_3_age + no_females_pregnant_household_person_3_age_value_check + females_in_soft_age_range_in_pregnant_household_person_3_age_value_check + age_3_under_retirement_value_check + age_3_over_retirement_value_check + age_3_partner_under_16_value_check + person_3_gender_identity + no_females_pregnant_household_person_3_value_check + females_in_soft_age_range_in_pregnant_household_person_3_value_check + gender_3_over_retirement_value_check + person_3_working_situation + working_situation_3_under_retirement_value_check + working_situation_3_over_retirement_value_check + person_4_known + person_4_lead_partner + relationship_4_partner_under_16_value_check + relationship_4_multiple_partners_value_check + person_4_age + no_females_pregnant_household_person_4_age_value_check + females_in_soft_age_range_in_pregnant_household_person_4_age_value_check + age_4_under_retirement_value_check + age_4_over_retirement_value_check + age_4_partner_under_16_value_check + person_4_gender_identity + no_females_pregnant_household_person_4_value_check + females_in_soft_age_range_in_pregnant_household_person_4_value_check + gender_4_over_retirement_value_check + person_4_working_situation + working_situation_4_under_retirement_value_check + working_situation_4_over_retirement_value_check + person_5_known + person_5_lead_partner + relationship_5_partner_under_16_value_check + relationship_5_multiple_partners_value_check + person_5_age + no_females_pregnant_household_person_5_age_value_check + females_in_soft_age_range_in_pregnant_household_person_5_age_value_check + age_5_under_retirement_value_check + age_5_over_retirement_value_check + age_5_partner_under_16_value_check + person_5_gender_identity + no_females_pregnant_household_person_5_value_check + females_in_soft_age_range_in_pregnant_household_person_5_value_check + gender_5_over_retirement_value_check + person_5_working_situation + working_situation_5_under_retirement_value_check + working_situation_5_over_retirement_value_check + person_6_known + person_6_lead_partner + relationship_6_partner_under_16_value_check + relationship_6_multiple_partners_value_check + person_6_age + no_females_pregnant_household_person_6_age_value_check + females_in_soft_age_range_in_pregnant_household_person_6_age_value_check + age_6_under_retirement_value_check + age_6_over_retirement_value_check + age_6_partner_under_16_value_check + person_6_gender_identity + no_females_pregnant_household_person_6_value_check + females_in_soft_age_range_in_pregnant_household_person_6_value_check + gender_6_over_retirement_value_check + person_6_working_situation + working_situation_6_under_retirement_value_check + working_situation_6_over_retirement_value_check + person_7_known + person_7_lead_partner + relationship_7_partner_under_16_value_check + relationship_7_multiple_partners_value_check + person_7_age + no_females_pregnant_household_person_7_age_value_check + females_in_soft_age_range_in_pregnant_household_person_7_age_value_check + age_7_under_retirement_value_check + age_7_over_retirement_value_check + age_7_partner_under_16_value_check + person_7_gender_identity + no_females_pregnant_household_person_7_value_check + females_in_soft_age_range_in_pregnant_household_person_7_value_check + gender_7_over_retirement_value_check + person_7_working_situation + working_situation_7_under_retirement_value_check + working_situation_7_over_retirement_value_check + person_8_known + person_8_lead_partner + relationship_8_partner_under_16_value_check + relationship_8_multiple_partners_value_check + person_8_age + no_females_pregnant_household_person_8_age_value_check + females_in_soft_age_range_in_pregnant_household_person_8_age_value_check + age_8_under_retirement_value_check + age_8_over_retirement_value_check + age_8_partner_under_16_value_check + person_8_gender_identity + no_females_pregnant_household_person_8_value_check + females_in_soft_age_range_in_pregnant_household_person_8_value_check + gender_8_over_retirement_value_check + person_8_working_situation + working_situation_8_under_retirement_value_check + working_situation_8_over_retirement_value_check + ], + ) + end + end + it "has the correct id" do expect(household_characteristics.id).to eq("household_characteristics") end