Browse Source

CLDC-1817 age questions update for children (#1333)

* amend copy of hint text

* update test to reflect copy change

* display hint text on age question if that person is a child

* updates from code review

* update tests to reflect changes in class interfaces for page and question
pull/1393/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
e0bde3a4b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/models/form/lettings/pages/person_age.rb
  2. 5
      app/models/form/lettings/questions/age.rb
  3. 2
      app/models/form/lettings/questions/person_relationship.rb
  4. 7
      app/models/form/lettings/subsections/household_characteristics.rb
  5. 6
      app/models/log.rb
  6. 35
      spec/models/form/lettings/pages/person_age_spec.rb
  7. 19
      spec/models/form/lettings/questions/age_spec.rb
  8. 2
      spec/models/form/lettings/questions/person_relationship_spec.rb
  9. 21
      spec/models/form/lettings/subsections/household_characteristics_spec.rb

14
app/models/form/lettings/pages/person_age.rb

@ -1,15 +1,21 @@
class Form::Lettings::Pages::PersonAge < ::Form::Page
def initialize(id, hsh, subsection, person_index:)
def initialize(id, hsh, subsection, person_index:, person_type: "non_child")
super(id, hsh, subsection)
@id = "person_#{person_index}_age"
@depends_on = [{ "details_known_#{person_index}" => 0 }]
@id = "person_#{person_index}_age_#{person_type}"
@person_index = person_index
@person_type = person_type
@depends_on = [
{
"details_known_#{person_index}" => 0,
"person_#{person_index}_child_relation?" => (person_type == "child"),
},
]
end
def questions
@questions ||= [
Form::Lettings::Questions::AgeKnown.new(nil, nil, self, person_index: @person_index),
Form::Lettings::Questions::Age.new(nil, nil, self, person_index: @person_index),
Form::Lettings::Questions::Age.new(nil, nil, self, person_index: @person_index, person_type: @person_type),
]
end
end

5
app/models/form/lettings/questions/age.rb

@ -1,5 +1,5 @@
class Form::Lettings::Questions::Age < ::Form::Question
def initialize(id, hsh, page, person_index:)
def initialize(id, hsh, page, person_index:, person_type:)
super(id, hsh, page)
@id = "age#{person_index}"
@check_answer_label = "Person #{person_index}’s age"
@ -9,7 +9,8 @@ class Form::Lettings::Questions::Age < ::Form::Question
@inferred_check_answers_value = [{ "condition" => { "age#{person_index}_known" => 1 }, "value" => "Not known" }]
@check_answers_card_number = person_index
@max = 120
@min = 0
@min = 1
@step = 1
@hint_text = "For a child under 1, enter 1" if person_type == "child"
end
end

2
app/models/form/lettings/questions/person_relationship.rb

@ -14,7 +14,7 @@ class Form::Lettings::Questions::PersonRelationship < ::Form::Question
"P" => { "value" => "Partner" },
"C" => {
"value" => "Child",
"hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education.",
"hint" => "Must be eligible for child benefit: under age 16 or under 20 if still in full-time education.",
},
"X" => { "value" => "Other" },
"divider" => { "value" => true },

7
app/models/form/lettings/subsections/household_characteristics.rb

@ -30,6 +30,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::LeadTenantOverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 2),
@ -44,6 +45,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new(nil, 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 3),
@ -58,6 +60,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new(nil, 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 4),
@ -72,6 +75,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new(nil, 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 5),
@ -86,6 +90,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new(nil, 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 6),
@ -100,6 +105,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new(nil, 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 7),
@ -114,6 +120,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonOverRetirementValueCheck.new(nil, 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8, person_type: "child"),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 8),

6
app/models/log.rb

@ -81,6 +81,12 @@ class Log < ApplicationRecord
end
end
(2..8).each do |person_num|
define_method("person_#{person_num}_child_relation?") do
send("relat#{person_num}") == "C"
end
end
private
def plural_gender_for_person(person_num)

35
spec/models/form/lettings/pages/person_age_spec.rb

@ -1,11 +1,12 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::PersonAge, type: :model do
subject(:page) { described_class.new(nil, page_definition, subsection, person_index:) }
subject(:page) { described_class.new(nil, page_definition, subsection, person_index:, person_type:) }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 2 }
let(:person_type) { "non_child" }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
@ -24,14 +25,30 @@ RSpec.describe Form::Lettings::Pages::PersonAge, type: :model do
expect(page.questions.map(&:id)).to eq(%w[age2_known age2])
end
it "has the correct id" do
expect(page.id).to eq("person_2_age")
context "when child" do
let(:person_type) { "child" }
it "has the correct id" do
expect(page.id).to eq("person_2_age_child")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_2" => 0, "person_2_child_relation?" => true }],
)
end
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_2" => 0 }],
)
context "when not child" do
it "has the correct id" do
expect(page.id).to eq("person_2_age_non_child")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_2" => 0, "person_2_child_relation?" => false }],
)
end
end
end
@ -43,12 +60,12 @@ RSpec.describe Form::Lettings::Pages::PersonAge, type: :model do
end
it "has the correct id" do
expect(page.id).to eq("person_3_age")
expect(page.id).to eq("person_3_age_non_child")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_3" => 0 }],
[{ "details_known_3" => 0, "person_3_child_relation?" => false }],
)
end
end

19
spec/models/form/lettings/questions/age_spec.rb

@ -1,11 +1,12 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::Age, type: :model do
subject(:question) { described_class.new(nil, question_definition, page, person_index:) }
subject(:question) { described_class.new(nil, question_definition, page, person_index:, person_type:) }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
let(:person_type) { "non_child" }
it "has correct page" do
expect(question.page).to eq(page)
@ -23,12 +24,22 @@ RSpec.describe Form::Lettings::Questions::Age, type: :model do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
context "when child" do
let(:person_type) { "child" }
it "has the correct hint" do
expect(question.hint_text).to eq("For a child under 1, enter 1")
end
end
context "when not child" do
it "has no hint" do
expect(question.hint_text).to be nil
end
end
it "has the correct min" do
expect(question.min).to eq(0)
expect(question.min).to eq(1)
end
it "has the correct max" do

2
spec/models/form/lettings/questions/person_relationship_spec.rb

@ -20,7 +20,7 @@ RSpec.describe Form::Lettings::Questions::PersonRelationship, type: :model do
end
it "has the correct answer_options" do
expect(question.answer_options).to eq("C" => { "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education.", "value" => "Child" },
expect(question.answer_options).to eq("C" => { "hint" => "Must be eligible for child benefit: under age 16 or under 20 if still in full-time education.", "value" => "Child" },
"P" => { "value" => "Partner" },
"R" => { "value" => "Person prefers not to say" },
"X" => { "value" => "Other" },

21
spec/models/form/lettings/subsections/household_characteristics_spec.rb

@ -36,7 +36,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
lead_tenant_over_retirement_value_check
person_2_known
person_2_relationship_to_lead
person_2_age
person_2_age_child
person_2_age_non_child
no_females_pregnant_household_person_2_age_value_check
females_in_soft_age_range_in_pregnant_household_person_2_age_value_check
person_2_gender_identity
@ -47,7 +48,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
person_2_over_retirement_value_check
person_3_known
person_3_relationship_to_lead
person_3_age
person_3_age_child
person_3_age_non_child
no_females_pregnant_household_person_3_age_value_check
females_in_soft_age_range_in_pregnant_household_person_3_age_value_check
person_3_gender_identity
@ -58,7 +60,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
person_3_over_retirement_value_check
person_4_known
person_4_relationship_to_lead
person_4_age
person_4_age_child
person_4_age_non_child
no_females_pregnant_household_person_4_age_value_check
females_in_soft_age_range_in_pregnant_household_person_4_age_value_check
person_4_gender_identity
@ -69,7 +72,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
person_4_over_retirement_value_check
person_5_known
person_5_relationship_to_lead
person_5_age
person_5_age_child
person_5_age_non_child
no_females_pregnant_household_person_5_age_value_check
females_in_soft_age_range_in_pregnant_household_person_5_age_value_check
person_5_gender_identity
@ -80,7 +84,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
person_5_over_retirement_value_check
person_6_known
person_6_relationship_to_lead
person_6_age
person_6_age_child
person_6_age_non_child
no_females_pregnant_household_person_6_age_value_check
females_in_soft_age_range_in_pregnant_household_person_6_age_value_check
person_6_gender_identity
@ -91,7 +96,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
person_6_over_retirement_value_check
person_7_known
person_7_relationship_to_lead
person_7_age
person_7_age_child
person_7_age_non_child
no_females_pregnant_household_person_7_age_value_check
females_in_soft_age_range_in_pregnant_household_person_7_age_value_check
person_7_gender_identity
@ -102,7 +108,8 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
person_7_over_retirement_value_check
person_8_known
person_8_relationship_to_lead
person_8_age
person_8_age_child
person_8_age_non_child
no_females_pregnant_household_person_8_age_value_check
females_in_soft_age_range_in_pregnant_household_person_8_age_value_check
person_8_gender_identity

Loading…
Cancel
Save