Browse Source

Cldc 1537 details for person x (#944)

* feat: add question with dynamic header

* feat: remove question dynamic behaviour

* feat: add more age questions

* feat: add new ages

* feat: add extra person known pages

* feat: add person 4 known question

* feat: add routing behaviour

* tests: update old tests to pass

* tests: add new tests

* refactor: pass linting

* refactor: remove redundant routing

* feat: respond to pr comments

* test: pass tests

* refactor: linting
pull/977/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
97ba0ccb29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/form/page.rb
  2. 6
      app/models/form/sales/pages/person2_age.rb
  3. 21
      app/models/form/sales/pages/person2_known.rb
  4. 4
      app/models/form/sales/pages/person3_age.rb
  5. 20
      app/models/form/sales/pages/person3_known.rb
  6. 2
      app/models/form/sales/pages/person4_age.rb
  7. 19
      app/models/form/sales/pages/person4_known.rb
  8. 6
      app/models/form/sales/questions/person2_age_known.rb
  9. 24
      app/models/form/sales/questions/person2_known.rb
  10. 6
      app/models/form/sales/questions/person3_age_known.rb
  11. 24
      app/models/form/sales/questions/person3_known.rb
  12. 6
      app/models/form/sales/questions/person4_age_known.rb
  13. 24
      app/models/form/sales/questions/person4_known.rb
  14. 3
      app/models/form/sales/subsections/household_characteristics.rb
  15. 1
      app/views/form/headers/_person_2_known_page.erb
  16. 1
      app/views/form/headers/_person_3_known_page.erb
  17. 1
      app/views/form/headers/_person_4_known_page.erb
  18. 10
      app/views/form/page.html.erb
  19. 7
      db/migrate/20221010085259_add_details_known_to_sales_log.rb
  20. 3
      db/schema.rb
  21. 3
      spec/factories/sales_log.rb
  22. 6
      spec/models/form/sales/pages/person2_age_spec.rb
  23. 43
      spec/models/form/sales/pages/person2_known_spec.rb
  24. 5
      spec/models/form/sales/pages/person3_age_spec.rb
  25. 42
      spec/models/form/sales/pages/person3_known_spec.rb
  26. 4
      spec/models/form/sales/pages/person4_age_spec.rb
  27. 41
      spec/models/form/sales/pages/person4_known_spec.rb
  28. 6
      spec/models/form/sales/questions/person2_age_known_spec.rb
  29. 60
      spec/models/form/sales/questions/person2_known_spec.rb
  30. 6
      spec/models/form/sales/questions/person3_age_known_spec.rb
  31. 60
      spec/models/form/sales/questions/person3_known_spec.rb
  32. 6
      spec/models/form/sales/questions/person4_age_known_spec.rb
  33. 60
      spec/models/form/sales/questions/person4_known_spec.rb
  34. 3
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  35. 4
      spec/models/form_handler_spec.rb

3
app/models/form/page.rb

@ -1,5 +1,5 @@
class Form::Page
attr_accessor :id, :header, :description, :questions, :depends_on, :title_text,
attr_accessor :id, :header, :header_partial, :description, :questions, :depends_on, :title_text,
:informative_text, :subsection, :hide_subsection_label
def initialize(id, hsh, subsection)
@ -7,6 +7,7 @@ class Form::Page
@subsection = subsection
if hsh
@header = hsh["header"]
@header_partial = hsh["header_partial"]
@description = hsh["description"]
@questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) }
@depends_on = hsh["depends_on"]

6
app/models/form/sales/pages/person2_age.rb

@ -6,9 +6,9 @@ class Form::Sales::Pages::Person2Age < ::Form::Page
@description = ""
@subsection = subsection
@depends_on = [
{ "hholdcount" => 2 },
{ "hholdcount" => 3 },
{ "hholdcount" => 4 },
{ "hholdcount" => 2, "details_known_2" => 1 },
{ "hholdcount" => 3, "details_known_2" => 1 },
{ "hholdcount" => 4, "details_known_2" => 1 },
]
end

21
app/models/form/sales/pages/person2_known.rb

@ -0,0 +1,21 @@
class Form::Sales::Pages::Person2Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_2_known"
@header_partial = "person_2_known_page"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "hholdcount" => 2 },
{ "hholdcount" => 3 },
{ "hholdcount" => 4 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person2Known.new(nil, nil, self),
]
end
end

4
app/models/form/sales/pages/person3_age.rb

@ -6,8 +6,8 @@ class Form::Sales::Pages::Person3Age < ::Form::Page
@description = ""
@subsection = subsection
@depends_on = [
{ "hholdcount" => 3 },
{ "hholdcount" => 4 },
{ "hholdcount" => 3, "details_known_3" => 1 },
{ "hholdcount" => 4, "details_known_3" => 1 },
]
end

20
app/models/form/sales/pages/person3_known.rb

@ -0,0 +1,20 @@
class Form::Sales::Pages::Person3Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_3_known"
@header_partial = "person_3_known_page"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "hholdcount" => 3, "details_known_2" => 1 },
{ "hholdcount" => 4, "details_known_2" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person3Known.new(nil, nil, self),
]
end
end

2
app/models/form/sales/pages/person4_age.rb

@ -6,7 +6,7 @@ class Form::Sales::Pages::Person4Age < ::Form::Page
@description = ""
@subsection = subsection
@depends_on = [
{ "hholdcount" => 4 },
{ "hholdcount" => 4, "details_known_4" => 1 },
]
end

19
app/models/form/sales/pages/person4_known.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::Person4Known < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_4_known"
@header_partial = "person_4_known_page"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "hholdcount" => 4, "details_known_3" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person4Known.new(nil, nil, self),
]
end
end

6
app/models/form/sales/questions/person2_age_known.rb

@ -16,6 +16,12 @@ class Form::Sales::Questions::Person2AgeKnown < ::Form::Question
{
"age4_known" => 0,
},
{
"details_known_2" => nil,
},
{
"details_known_2" => 2,
},
],
}
end

24
app/models/form/sales/questions/person2_known.rb

@ -0,0 +1,24 @@
class Form::Sales::Questions::Person2Known < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_2"
@check_answer_label = "Details known for person 2?"
@header = "Do you know the details for person 2?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@hidden_in_check_answers = {
"depends_on" => [
{
"details_known_2" => 1,
},
],
}
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

6
app/models/form/sales/questions/person3_age_known.rb

@ -16,6 +16,12 @@ class Form::Sales::Questions::Person3AgeKnown < ::Form::Question
{
"age5_known" => 0,
},
{
"details_known_3" => nil,
},
{
"details_known_3" => 2,
},
],
}
end

24
app/models/form/sales/questions/person3_known.rb

@ -0,0 +1,24 @@
class Form::Sales::Questions::Person3Known < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_3"
@check_answer_label = "Details known for person 3?"
@header = "Do you know the details for person 3?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@hidden_in_check_answers = {
"depends_on" => [
{
"details_known_3" => 1,
},
],
}
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

6
app/models/form/sales/questions/person4_age_known.rb

@ -16,6 +16,12 @@ class Form::Sales::Questions::Person4AgeKnown < ::Form::Question
{
"age6_known" => 0,
},
{
"details_known_4" => nil,
},
{
"details_known_4" => 2,
},
],
}
end

24
app/models/form/sales/questions/person4_known.rb

@ -0,0 +1,24 @@
class Form::Sales::Questions::Person4Known < ::Form::Question
def initialize(id, hsh, page)
super
@id = "details_known_4"
@check_answer_label = "Details known for person 4?"
@header = "Do you know the details for person 4?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@hidden_in_check_answers = {
"depends_on" => [
{
"details_known_4" => 1,
},
],
}
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

3
app/models/form/sales/subsections/household_characteristics.rb

@ -29,8 +29,11 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self),
Form::Sales::Pages::Person1Age.new(nil, nil, self),
Form::Sales::Pages::Person2Known.new(nil, nil, self),
Form::Sales::Pages::Person2Age.new(nil, nil, self),
Form::Sales::Pages::Person3Known.new(nil, nil, self),
Form::Sales::Pages::Person3Age.new(nil, nil, self),
Form::Sales::Pages::Person4Known.new(nil, nil, self),
Form::Sales::Pages::Person4Age.new(nil, nil, self),
]
end

1
app/views/form/headers/_person_2_known_page.erb

@ -0,0 +1 @@
You have given us the details for 1 of the <%= log.hholdcount %> other people in the household

1
app/views/form/headers/_person_3_known_page.erb

@ -0,0 +1 @@
You have given us the details for 2 of the <%= log.hholdcount %> other people in the household

1
app/views/form/headers/_person_4_known_page.erb

@ -0,0 +1 @@
You have given us the details for 3 of the <%= log.hholdcount %> other people in the household

10
app/views/form/page.html.erb

@ -11,12 +11,16 @@
<% remove_other_page_errors(@log, @page) %>
<%= f.govuk_error_summary %>
<% if @page.header.present? %>
<% if @page.header.present? || @page.header_partial.present? %>
<h1 class="govuk-heading-l">
<% if !@page.hide_subsection_label %>
<span class="govuk-caption-l"><%= @subsection.label %></span>
<% end %>
<%= @page.header %>
<% if @page.header_partial.present? %>
<%= render partial: "form/headers/#{@page.header_partial}", locals: { log: @log } %>
<% else %>
<%= @page.header %>
<% end %>
</h1>
<% end %>
@ -32,7 +36,7 @@
<% if question.type == "interruption_screen" %>
<%= render partial: "form/#{question.type}_question", locals: { question:, caption_text: @subsection.label, page_header: @page.header, lettings_log: @log, title_text: @page.title_text, informative_text: @page.informative_text, form: @form, f:, conditional: false } %>
<% else %>
<%= render partial: "form/#{question.type}_question", locals: { question:, caption_text: @subsection.label, page_header: @page.header, lettings_log: @log, f:, conditional: false } %>
<%= render partial: "form/#{question.type}_question", locals: { question:, caption_text: @page.header_partial.present? ? nil : @subsection.label, page_header: @page.header, lettings_log: @log, f:, conditional: false } %>
<% end %>
</div>
<% end %>

7
db/migrate/20221010085259_add_details_known_to_sales_log.rb

@ -0,0 +1,7 @@
class AddDetailsKnownToSalesLog < ActiveRecord::Migration[7.0]
change_table :sales_logs, bulk: true do |t|
t.column :details_known_2, :integer
t.column :details_known_3, :integer
t.column :details_known_4, :integer
end
end

3
db/schema.rb

@ -369,6 +369,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_19_082625) do
t.integer "la_known"
t.integer "income1"
t.integer "income1nk"
t.integer "details_known_2"
t.integer "details_known_3"
t.integer "details_known_4"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

3
spec/factories/sales_log.rb

@ -41,10 +41,13 @@ FactoryBot.define do
wheel { 1 }
age3_known { 0 }
age3 { 40 }
details_known_2 { 1 }
age4_known { 0 }
age4 { 40 }
details_known_3 { 1 }
age5_known { 0 }
age5 { 40 }
details_known_4 { 1 }
age6_known { 0 }
age6 { 40 }
income1nk { 0 }

6
spec/models/form/sales/pages/person2_age_spec.rb

@ -29,11 +29,7 @@ RSpec.describe Form::Sales::Pages::Person2Age, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "hholdcount" => 2 },
{ "hholdcount" => 3 },
{ "hholdcount" => 4 },
],
[{ "details_known_2" => 1, "hholdcount" => 2 }, { "details_known_2" => 1, "hholdcount" => 3 }, { "details_known_2" => 1, "hholdcount" => 4 }],
)
end
end

43
spec/models/form/sales/pages/person2_known_spec.rb

@ -0,0 +1,43 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Person2Known, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
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 the correct header" do
expect(page.header).to eq("")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_2_known_page")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "hholdcount" => 2 },
{ "hholdcount" => 3 },
{ "hholdcount" => 4 },
],
)
end
end

5
spec/models/form/sales/pages/person3_age_spec.rb

@ -29,10 +29,7 @@ RSpec.describe Form::Sales::Pages::Person3Age, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "hholdcount" => 3 },
{ "hholdcount" => 4 },
],
[{ "details_known_3" => 1, "hholdcount" => 3 }, { "details_known_3" => 1, "hholdcount" => 4 }],
)
end
end

42
spec/models/form/sales/pages/person3_known_spec.rb

@ -0,0 +1,42 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Person3Known, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
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 the correct header" do
expect(page.header).to eq("")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_3_known_page")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_2" => 1, "hholdcount" => 3 },
{ "details_known_2" => 1, "hholdcount" => 4 },
],
)
end
end

4
spec/models/form/sales/pages/person4_age_spec.rb

@ -29,9 +29,7 @@ RSpec.describe Form::Sales::Pages::Person4Age, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "hholdcount" => 4 },
],
[{ "details_known_4" => 1, "hholdcount" => 4 }],
)
end
end

41
spec/models/form/sales/pages/person4_known_spec.rb

@ -0,0 +1,41 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Person4Known, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_4])
end
it "has the correct id" do
expect(page.id).to eq("person_4_known")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_4_known_page")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_3" => 1, "hholdcount" => 4 },
],
)
end
end

6
spec/models/form/sales/questions/person2_age_known_spec.rb

@ -51,11 +51,7 @@ RSpec.describe Form::Sales::Questions::Person2AgeKnown, type: :model do
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age4_known" => 0,
},
],
"depends_on" => [{ "age4_known" => 0 }, { "details_known_2" => nil }, { "details_known_2" => 2 }],
},
)
end

60
spec/models/form/sales/questions/person2_known_spec.rb

@ -0,0 +1,60 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Person2Known, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
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("details_known_2")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 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 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 answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"details_known_2" => 1,
},
],
},
)
end
end

6
spec/models/form/sales/questions/person3_age_known_spec.rb

@ -51,11 +51,7 @@ RSpec.describe Form::Sales::Questions::Person3AgeKnown, type: :model do
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age5_known" => 0,
},
],
"depends_on" => [{ "age5_known" => 0 }, { "details_known_3" => nil }, { "details_known_3" => 2 }],
},
)
end

60
spec/models/form/sales/questions/person3_known_spec.rb

@ -0,0 +1,60 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Person3Known, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
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("details_known_3")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 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 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 answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"details_known_3" => 1,
},
],
},
)
end
end

6
spec/models/form/sales/questions/person4_age_known_spec.rb

@ -51,11 +51,7 @@ RSpec.describe Form::Sales::Questions::Person4AgeKnown, type: :model do
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age6_known" => 0,
},
],
"depends_on" => [{ "age6_known" => 0 }, { "details_known_4" => nil }, { "details_known_4" => 2 }],
},
)
end

60
spec/models/form/sales/questions/person4_known_spec.rb

@ -0,0 +1,60 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Person4Known, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
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("details_known_4")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 4?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 4?")
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 answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"details_known_4" => 1,
},
],
},
)
end
end

3
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -34,8 +34,11 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_2_live_in_property
number_of_others_in_property
person_1_age
person_2_known
person_2_age
person_3_known
person_3_age
person_4_known
person_4_age
],
)

4
spec/models/form_handler_spec.rb

@ -61,14 +61,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(41)
expect(form.pages.count).to eq(44)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(41)
expect(form.pages.count).to eq(44)
expect(form.name).to eq("2021_2022_sales")
end
end

Loading…
Cancel
Save