From c50a5d0aa78e0e58888874d4a66f30afafcacd22 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 20 Mar 2023 09:38:59 +0000 Subject: [PATCH] Add soft validation pages --- .../pages/student_not_child_value_check.rb | 21 ++++ .../student_not_child_value_check.rb | 24 ++++ .../subsections/household_characteristics.rb | 18 +++ config/locales/en.yml | 2 + .../student_not_child_value_check_spec.rb | 106 ++++++++++++++++++ .../student_not_child_value_check_spec.rb | 61 ++++++++++ .../household_characteristics_spec.rb | 36 ++++++ 7 files changed, 268 insertions(+) create mode 100644 app/models/form/sales/pages/student_not_child_value_check.rb create mode 100644 app/models/form/sales/questions/student_not_child_value_check.rb create mode 100644 spec/models/form/sales/pages/student_not_child_value_check_spec.rb create mode 100644 spec/models/form/sales/questions/student_not_child_value_check_spec.rb diff --git a/app/models/form/sales/pages/student_not_child_value_check.rb b/app/models/form/sales/pages/student_not_child_value_check.rb new file mode 100644 index 000000000..3230b09cc --- /dev/null +++ b/app/models/form/sales/pages/student_not_child_value_check.rb @@ -0,0 +1,21 @@ +class Form::Sales::Pages::StudentNotChildValueCheck < Form::Sales::Pages::Person + def initialize(id, hsh, subsection, person_index:) + super + @depends_on = [ + { + "person_#{person_index}_student_not_child?" => true, + }, + ] + @person_index = person_index + @title_text = { + "translation" => "soft_validations.student_not_child.title_text", + } + @informative_text = {} + end + + def questions + @questions ||= [ + Form::Sales::Questions::StudentNotChildValueCheck.new(nil, nil, self, person_index: @person_index), + ] + end +end diff --git a/app/models/form/sales/questions/student_not_child_value_check.rb b/app/models/form/sales/questions/student_not_child_value_check.rb new file mode 100644 index 000000000..b64b64a7f --- /dev/null +++ b/app/models/form/sales/questions/student_not_child_value_check.rb @@ -0,0 +1,24 @@ +class Form::Sales::Questions::StudentNotChildValueCheck < ::Form::Question + def initialize(id, hsh, page, person_index:) + super(id, hsh, page) + @id = "student_not_child_value_check" + @check_answer_label = "Student not child confirmation" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "student_not_child_value_check" => 0, + }, + { + "student_not_child_value_check" => 1, + }, + ], + } + @check_answers_card_number = person_index + @header = "Are you sure this person is not child?" + end +end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 311162e03..72424ac8a 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -27,58 +27,76 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer1IncomeValueCheck.new("working_situation_buyer_1_income_value_check", nil, self), Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), + Form::Sales::Pages::StudentNotChildValueCheck.new("buyer_2_relationship_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::Age2.new(nil, nil, self), Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_2_old_persons_shared_ownership_value_check", nil, self), Form::Sales::Pages::RetirementValueCheck.new("age_2_buyer_retirement_value_check", nil, self, person_index: 2), + Form::Sales::Pages::StudentNotChildValueCheck.new("buyer_2_age_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::GenderIdentity2.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("gender_2_buyer_retirement_value_check", nil, self, person_index: 2), buyer_2_ethnicity_nationality_pages, Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2), Form::Sales::Pages::Buyer2IncomeValueCheck.new("working_situation_buyer_2_income_value_check", nil, self), + Form::Sales::Pages::StudentNotChildValueCheck.new("buyer_2_working_situation_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property", nil, self, joint_purchase: false), Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 2), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1", nil, self, person_index: 2), + Form::Sales::Pages::StudentNotChildValueCheck.new("relationship_2_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("age_2_retirement_value_check", nil, self, person_index: 2), + Form::Sales::Pages::StudentNotChildValueCheck.new("age_2_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonGenderIdentity.new("person_2_gender_identity", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("gender_2_retirement_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check", nil, self, person_index: 2), + Form::Sales::Pages::StudentNotChildValueCheck.new("working_situation_2_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 3), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1", nil, self, person_index: 3), + Form::Sales::Pages::StudentNotChildValueCheck.new("relationship_3_student_not_child_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonAge.new("person_3_age", nil, self, person_index: 3), Form::Sales::Pages::RetirementValueCheck.new("age_3_retirement_value_check", nil, self, person_index: 3), + Form::Sales::Pages::StudentNotChildValueCheck.new("age_3_student_not_child_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonGenderIdentity.new("person_3_gender_identity", nil, self, person_index: 3), Form::Sales::Pages::RetirementValueCheck.new("gender_3_retirement_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self, person_index: 3), Form::Sales::Pages::RetirementValueCheck.new("working_situation_3_retirement_value_check", nil, self, person_index: 3), + Form::Sales::Pages::StudentNotChildValueCheck.new("working_situation_3_student_not_child_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 4), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1", nil, self, person_index: 4), + Form::Sales::Pages::StudentNotChildValueCheck.new("relationship_4_student_not_child_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 4), Form::Sales::Pages::RetirementValueCheck.new("age_4_retirement_value_check", nil, self, person_index: 4), + Form::Sales::Pages::StudentNotChildValueCheck.new("age_4_student_not_child_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonGenderIdentity.new("person_4_gender_identity", nil, self, person_index: 4), Form::Sales::Pages::RetirementValueCheck.new("gender_4_retirement_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self, person_index: 4), Form::Sales::Pages::RetirementValueCheck.new("working_situation_4_retirement_value_check", nil, self, person_index: 4), + Form::Sales::Pages::StudentNotChildValueCheck.new("working_situation_4_student_not_child_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonKnown.new("person_5_known", nil, self, person_index: 5), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_5_relationship_to_buyer_1", nil, self, person_index: 5), + Form::Sales::Pages::StudentNotChildValueCheck.new("relationship_5_student_not_child_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonAge.new("person_5_age", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("age_5_retirement_value_check", nil, self, person_index: 5), + Form::Sales::Pages::StudentNotChildValueCheck.new("age_5_student_not_child_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonGenderIdentity.new("person_5_gender_identity", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("gender_5_retirement_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonWorkingSituation.new("person_5_working_situation", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("working_situation_5_retirement_value_check", nil, self, person_index: 5), + Form::Sales::Pages::StudentNotChildValueCheck.new("working_situation_5_student_not_child_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonKnown.new("person_6_known", nil, self, person_index: 6), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_6_relationship_to_buyer_1", nil, self, person_index: 6), + Form::Sales::Pages::StudentNotChildValueCheck.new("relationship_6_student_not_child_value_check", nil, self, person_index: 6), Form::Sales::Pages::PersonAge.new("person_6_age", nil, self, person_index: 6), Form::Sales::Pages::RetirementValueCheck.new("age_6_retirement_value_check", nil, self, person_index: 6), + Form::Sales::Pages::StudentNotChildValueCheck.new("age_6_student_not_child_value_check", nil, self, person_index: 6), Form::Sales::Pages::PersonGenderIdentity.new("person_6_gender_identity", nil, self, person_index: 6), Form::Sales::Pages::RetirementValueCheck.new("gender_6_retirement_value_check", nil, self, person_index: 6), Form::Sales::Pages::PersonWorkingSituation.new("person_6_working_situation", nil, self, person_index: 6), Form::Sales::Pages::RetirementValueCheck.new("working_situation_6_retirement_value_check", nil, self, person_index: 6), + Form::Sales::Pages::StudentNotChildValueCheck.new("working_situation_6_student_not_child_value_check", nil, self, person_index: 6), ].flatten.compact end diff --git a/config/locales/en.yml b/config/locales/en.yml index d07a84049..8c9cd12c1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -523,6 +523,8 @@ en: staircase_bought_seems_high: "You said %{percentage}% was bought in this staircasing transaction, which seems high. Are you sure?" monthly_charges_over_soft_max: title_text: "The amount of monthly charges is high for this type of property and sale type" + student_not_child: + title_text: "You told us this person is a student aged beween 16 and 19" devise: two_factor_authentication: diff --git a/spec/models/form/sales/pages/student_not_child_value_check_spec.rb b/spec/models/form/sales/pages/student_not_child_value_check_spec.rb new file mode 100644 index 000000000..f04b0195a --- /dev/null +++ b/spec/models/form/sales/pages/student_not_child_value_check_spec.rb @@ -0,0 +1,106 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::StudentNotChildValueCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } + + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + let(:person_index) { 2 } + + let(:page_id) { "person_2_student_not_child_value_check" } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "is interruption screen page" do + expect(page.interruption_screen?).to eq(true) + end + + it "has correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.student_not_child.title_text", + }) + end + + it "has correct informative_text" do + expect(page.informative_text).to eq({}) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[student_not_child_value_check]) + end + + context "with person 2" do + let(:person_index) { 2 } + let(:page_id) { "person_2_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_2_student_not_child?" => true }]) + end + end + + context "with person 3" do + let(:person_index) { 3 } + let(:page_id) { "person_3_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_3_student_not_child?" => true }]) + end + end + + context "with person 4" do + let(:person_index) { 4 } + let(:page_id) { "person_4_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_4_student_not_child?" => true }]) + end + end + + context "with person 5" do + let(:person_index) { 5 } + let(:page_id) { "person_5_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_5_student_not_child?" => true }]) + end + end + + context "with person 6" do + let(:person_index) { 6 } + let(:page_id) { "person_6_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_6_student_not_child?" => true }]) + end + end +end diff --git a/spec/models/form/sales/questions/student_not_child_value_check_spec.rb b/spec/models/form/sales/questions/student_not_child_value_check_spec.rb new file mode 100644 index 000000000..72b98285f --- /dev/null +++ b/spec/models/form/sales/questions/student_not_child_value_check_spec.rb @@ -0,0 +1,61 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::StudentNotChildValueCheck, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page, person_index: 1) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("student_not_child_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure this person is not child?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Student not child confirmation") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has a correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(1) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq({ + "depends_on" => [ + { + "student_not_child_value_check" => 0, + }, + { + "student_not_child_value_check" => 1, + }, + ], + }) + end +end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index b47ac970d..57a9ce019 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -40,57 +40,75 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model working_situation_buyer_1_income_value_check buyer_1_live_in_property buyer_2_relationship_to_buyer_1 + buyer_2_relationship_student_not_child_value_check buyer_2_age age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check + buyer_2_age_student_not_child_value_check buyer_2_gender_identity gender_2_buyer_retirement_value_check buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase working_situation_buyer_2_income_value_check + buyer_2_working_situation_student_not_child_value_check buyer_2_live_in_property number_of_others_in_property number_of_others_in_property_joint_purchase person_2_known person_2_relationship_to_buyer_1 + relationship_2_student_not_child_value_check person_2_age age_2_retirement_value_check + age_2_student_not_child_value_check person_2_gender_identity gender_2_retirement_value_check person_2_working_situation working_situation_2_retirement_value_check + working_situation_2_student_not_child_value_check person_3_known person_3_relationship_to_buyer_1 + relationship_3_student_not_child_value_check person_3_age age_3_retirement_value_check + age_3_student_not_child_value_check person_3_gender_identity gender_3_retirement_value_check person_3_working_situation working_situation_3_retirement_value_check + working_situation_3_student_not_child_value_check person_4_known person_4_relationship_to_buyer_1 + relationship_4_student_not_child_value_check person_4_age age_4_retirement_value_check + age_4_student_not_child_value_check person_4_gender_identity gender_4_retirement_value_check person_4_working_situation working_situation_4_retirement_value_check + working_situation_4_student_not_child_value_check person_5_known person_5_relationship_to_buyer_1 + relationship_5_student_not_child_value_check person_5_age age_5_retirement_value_check + age_5_student_not_child_value_check person_5_gender_identity gender_5_retirement_value_check person_5_working_situation working_situation_5_retirement_value_check + working_situation_5_student_not_child_value_check person_6_known person_6_relationship_to_buyer_1 + relationship_6_student_not_child_value_check person_6_age age_6_retirement_value_check + age_6_student_not_child_value_check person_6_gender_identity gender_6_retirement_value_check person_6_working_situation working_situation_6_retirement_value_check + working_situation_6_student_not_child_value_check ], ) end @@ -124,9 +142,11 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model working_situation_buyer_1_income_value_check buyer_1_live_in_property buyer_2_relationship_to_buyer_1 + buyer_2_relationship_student_not_child_value_check buyer_2_age age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check + buyer_2_age_student_not_child_value_check buyer_2_gender_identity gender_2_buyer_retirement_value_check buyer_2_ethnic_group @@ -139,49 +159,65 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase working_situation_buyer_2_income_value_check + buyer_2_working_situation_student_not_child_value_check buyer_2_live_in_property number_of_others_in_property number_of_others_in_property_joint_purchase person_2_known person_2_relationship_to_buyer_1 + relationship_2_student_not_child_value_check person_2_age age_2_retirement_value_check + age_2_student_not_child_value_check person_2_gender_identity gender_2_retirement_value_check person_2_working_situation working_situation_2_retirement_value_check + working_situation_2_student_not_child_value_check person_3_known person_3_relationship_to_buyer_1 + relationship_3_student_not_child_value_check person_3_age age_3_retirement_value_check + age_3_student_not_child_value_check person_3_gender_identity gender_3_retirement_value_check person_3_working_situation working_situation_3_retirement_value_check + working_situation_3_student_not_child_value_check person_4_known person_4_relationship_to_buyer_1 + relationship_4_student_not_child_value_check person_4_age age_4_retirement_value_check + age_4_student_not_child_value_check person_4_gender_identity gender_4_retirement_value_check person_4_working_situation working_situation_4_retirement_value_check + working_situation_4_student_not_child_value_check person_5_known person_5_relationship_to_buyer_1 + relationship_5_student_not_child_value_check person_5_age age_5_retirement_value_check + age_5_student_not_child_value_check person_5_gender_identity gender_5_retirement_value_check person_5_working_situation working_situation_5_retirement_value_check + working_situation_5_student_not_child_value_check person_6_known person_6_relationship_to_buyer_1 + relationship_6_student_not_child_value_check person_6_age age_6_retirement_value_check + age_6_student_not_child_value_check person_6_gender_identity gender_6_retirement_value_check person_6_working_situation working_situation_6_retirement_value_check + working_situation_6_student_not_child_value_check ], ) end