Browse Source

Make person known questions generic

pull/1254/head
Kat 3 years ago
parent
commit
f22661b9d3
  1. 13
      app/models/form/lettings/pages/person_2_known.rb
  2. 13
      app/models/form/lettings/pages/person_3_known.rb
  3. 13
      app/models/form/lettings/pages/person_4_known.rb
  4. 13
      app/models/form/lettings/pages/person_5_known.rb
  5. 13
      app/models/form/lettings/pages/person_6_known.rb
  6. 13
      app/models/form/lettings/pages/person_7_known.rb
  7. 13
      app/models/form/lettings/pages/person_8_known.rb
  8. 14
      app/models/form/lettings/pages/person_known.rb
  9. 14
      app/models/form/lettings/questions/details_known.rb
  10. 14
      app/models/form/lettings/questions/details_known_2.rb
  11. 14
      app/models/form/lettings/questions/details_known_3.rb
  12. 14
      app/models/form/lettings/questions/details_known_4.rb
  13. 14
      app/models/form/lettings/questions/details_known_5.rb
  14. 14
      app/models/form/lettings/questions/details_known_6.rb
  15. 14
      app/models/form/lettings/questions/details_known_7.rb
  16. 14
      app/models/form/lettings/questions/details_known_8.rb
  17. 14
      app/models/form/lettings/subsections/household_characteristics.rb
  18. 66
      spec/models/form/lettings/pages/person_known_spec.rb
  19. 63
      spec/models/form/lettings/questions/details_known_spec.rb

13
app/models/form/lettings/pages/person_2_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person2Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_2_known"
@header = "You’ve given us the details for 1 person in the household"
@depends_on = [{ "hhmemb" => 2 }, { "hhmemb" => 3 }, { "hhmemb" => 4 }, { "hhmemb" => 5 }, { "hhmemb" => 6 }, { "hhmemb" => 7 }, { "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown2.new(nil, nil, self)]
end
end

13
app/models/form/lettings/pages/person_3_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person3Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_3_known"
@header = "You’ve given us the details for 2 people in the household"
@depends_on = [{ "hhmemb" => 3 }, { "hhmemb" => 4 }, { "hhmemb" => 5 }, { "hhmemb" => 6 }, { "hhmemb" => 7 }, { "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown3.new(nil, nil, self)]
end
end

13
app/models/form/lettings/pages/person_4_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person4Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_4_known"
@header = "You’ve given us the details for 3 people in the household"
@depends_on = [{ "hhmemb" => 4 }, { "hhmemb" => 5 }, { "hhmemb" => 6 }, { "hhmemb" => 7 }, { "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown4.new(nil, nil, self)]
end
end

13
app/models/form/lettings/pages/person_5_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person5Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_5_known"
@header = "You’ve given us the details for 4 people in the household"
@depends_on = [{ "hhmemb" => 5 }, { "hhmemb" => 6 }, { "hhmemb" => 7 }, { "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown5.new(nil, nil, self)]
end
end

13
app/models/form/lettings/pages/person_6_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person6Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_6_known"
@header = "You’ve given us the details for 5 people in the household"
@depends_on = [{ "hhmemb" => 6 }, { "hhmemb" => 7 }, { "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown6.new(nil, nil, self)]
end
end

13
app/models/form/lettings/pages/person_7_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person7Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_7_known"
@header = "You’ve given us the details for 6 people in the household"
@depends_on = [{ "hhmemb" => 7 }, { "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown7.new(nil, nil, self)]
end
end

13
app/models/form/lettings/pages/person_8_known.rb

@ -1,13 +0,0 @@
class Form::Lettings::Pages::Person8Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_8_known"
@header = "You’ve given us the details for 7 people in the household"
@depends_on = [{ "hhmemb" => 8 }]
@description = ""
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown8.new(nil, nil, self)]
end
end

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

@ -0,0 +1,14 @@
class Form::Lettings::Pages::PersonKnown < ::Form::Page
def initialize(id, hsh, subsection, person_index:)
super(id, hsh, subsection)
@id = "person_#{person_index}_known"
@header = "You’ve given us the details for #{person_index - 1} person in the household"
@depends_on = (person_index..8).map { |index| { "hhmemb" => index } }
@description = ""
@person_index = person_index
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown.new(nil, nil, self, person_index: @person_index)]
end
end

14
app/models/form/lettings/questions/details_known.rb

@ -0,0 +1,14 @@
class Form::Lettings::Questions::DetailsKnown < ::Form::Question
def initialize(id, hsh, page, person_index:)
super(id, hsh, page)
@id = "details_known_#{person_index}"
@check_answer_label = "Details known for person #{person_index}"
@header = "Do you know details for person #{person_index}?"
@type = "radio"
@check_answers_card_number = person_index
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_2.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown2 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_2"
@check_answer_label = "Details known for person 2"
@header = "Do you know details for person 2?"
@type = "radio"
@check_answers_card_number = 2
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_3.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown3 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_3"
@check_answer_label = "Details known for person 3"
@header = "Do you know details for person 3?"
@type = "radio"
@check_answers_card_number = 3
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_4.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown4 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_4"
@check_answer_label = "Details known for person 4"
@header = "Do you know details for person 4?"
@type = "radio"
@check_answers_card_number = 4
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_5.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown5 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_5"
@check_answer_label = "Details known for person 5"
@header = "Do you know details for person 5?"
@type = "radio"
@check_answers_card_number = 5
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_6.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown6 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_6"
@check_answer_label = "Details known for person 6"
@header = "Do you know details for person 6?"
@type = "radio"
@check_answers_card_number = 6
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_7.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown7 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_7"
@check_answer_label = "Details known for person 7"
@header = "Do you know details for person 7?"
@type = "radio"
@check_answers_card_number = 7
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

14
app/models/form/lettings/questions/details_known_8.rb

@ -1,14 +0,0 @@
class Form::Lettings::Questions::DetailsKnown8 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_8"
@check_answer_label = "Details known for person 8"
@header = "Do you know details for person 8?"
@type = "radio"
@check_answers_card_number = 8
@hint_text = "You must provide details for everyone in the household if you know them."
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

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

@ -27,7 +27,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::LeadTenantWorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::LeadTenantOverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person2Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::Person2RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson2AgeValueCheck.new(nil, nil, self),
@ -38,7 +38,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::Person2WorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::Person2UnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person2OverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person3Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 3),
Form::Lettings::Pages::Person3RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson3AgeValueCheck.new(nil, nil, self),
@ -49,7 +49,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::Person3WorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::Person3UnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person3OverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person4Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 4),
Form::Lettings::Pages::Person4RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson4AgeValueCheck.new(nil, nil, self),
@ -60,7 +60,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::Person4WorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::Person4UnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person4OverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person5Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 5),
Form::Lettings::Pages::Person5RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson5AgeValueCheck.new(nil, nil, self),
@ -71,7 +71,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::Person5WorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::Person5UnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person5OverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person6Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 6),
Form::Lettings::Pages::Person6RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson6AgeValueCheck.new(nil, nil, self),
@ -82,7 +82,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::Person6WorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::Person6UnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person6OverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person7Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 7),
Form::Lettings::Pages::Person7RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson7AgeValueCheck.new(nil, nil, self),
@ -93,7 +93,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::Person7WorkingSituation.new(nil, nil, self),
Form::Lettings::Pages::Person7UnderRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person7OverRetirementValueCheck.new(nil, nil, self),
Form::Lettings::Pages::Person8Known.new(nil, nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 8),
Form::Lettings::Pages::Person8RelationshipToLead.new(nil, nil, self),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPerson8AgeValueCheck.new(nil, nil, self),

66
spec/models/form/lettings/pages/person_known_spec.rb

@ -0,0 +1,66 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::PersonKnown, type: :model do
subject(:page) { described_class.new(nil, page_definition, subsection, person_index:) }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 2 }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has the correct header" do
expect(page.header).to eq("You’ve given us the details for 1 person in the household")
end
it "has the correct description" do
expect(page.description).to eq("")
end
context "with person 2" do
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_2])
end
it "has the correct id" do
expect(page.id).to eq("person_2_known")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hhmemb" => 2 },
{ "hhmemb" => 3 },
{ "hhmemb" => 4 },
{ "hhmemb" => 5 },
{ "hhmemb" => 6 },
{ "hhmemb" => 7 },
{ "hhmemb" => 8 }],
)
end
end
context "with person 3" do
let(:person_index) { 3 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_3])
end
it "has the correct id" do
expect(page.id).to eq("person_3_known")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hhmemb" => 3 },
{ "hhmemb" => 4 },
{ "hhmemb" => 5 },
{ "hhmemb" => 6 },
{ "hhmemb" => 7 },
{ "hhmemb" => 8 }],
)
end
end
end

63
spec/models/form/lettings/questions/details_known_spec.rb

@ -0,0 +1,63 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::DetailsKnown, type: :model do
subject(:question) { described_class.new(nil, question_definition, page, person_index:) }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
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?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("You must provide details for everyone in the household if you know them.")
end
context "with person 2" do
it "has the correct id" do
expect(question.id).to eq("details_known_2")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 2")
end
it "has the correct header" do
expect(question.header).to eq("Do you know details for person 2?")
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("details_known_3")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 3")
end
it "has the correct header" do
expect(question.header).to eq("Do you know details for person 3?")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
end
end
Loading…
Cancel
Save