Browse Source

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

pull/1333/head
Arthur Campbell 3 years ago
parent
commit
5af973a026
  1. 14
      app/models/form/lettings/pages/person_age.rb
  2. 5
      app/models/form/lettings/questions/age.rb
  3. 21
      app/models/form/lettings/subsections/household_characteristics.rb
  4. 6
      app/models/log.rb
  5. 35
      spec/models/form/lettings/pages/person_age_spec.rb
  6. 19
      spec/models/form/lettings/questions/age_spec.rb
  7. 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:, is_child:)
super(id, hsh, subsection)
@id = "person_#{person_index}_age"
@depends_on = [{ "details_known_#{person_index}" => 0 }]
@id = is_child ? "person_#{person_index}_age_child" : "person_#{person_index}_age_non_child"
@person_index = person_index
@is_child = is_child
@depends_on = [
{
"details_known_#{person_index}" => 0,
"person_#{person_index}_child_relation?" => is_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, is_child: @is_child),
]
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:, is_child:)
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 is_child
end
end

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

@ -30,7 +30,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 2),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
@ -44,7 +45,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 3),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
@ -58,7 +60,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 4),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
@ -72,7 +75,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 5),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
@ -86,7 +90,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 6),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
@ -100,7 +105,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 7),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
@ -114,7 +120,8 @@ 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),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8, is_child: true),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8, is_child: false),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 8),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,

6
app/models/log.rb

@ -75,6 +75,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:, is_child:) }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 2 }
let(:is_child) { false }
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(:is_child) { true }
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:, is_child:) }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
let(:is_child) { false }
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(:is_child) { true }
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

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