From 97ba0ccb2966a1baf03670c2555944cf72a33499 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Tue, 8 Nov 2022 15:18:21 +0000 Subject: [PATCH] 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 --- app/models/form/page.rb | 3 +- app/models/form/sales/pages/person2_age.rb | 6 +- app/models/form/sales/pages/person2_known.rb | 21 +++++++ app/models/form/sales/pages/person3_age.rb | 4 +- app/models/form/sales/pages/person3_known.rb | 20 +++++++ app/models/form/sales/pages/person4_age.rb | 2 +- app/models/form/sales/pages/person4_known.rb | 19 ++++++ .../form/sales/questions/person2_age_known.rb | 6 ++ .../form/sales/questions/person2_known.rb | 24 ++++++++ .../form/sales/questions/person3_age_known.rb | 6 ++ .../form/sales/questions/person3_known.rb | 24 ++++++++ .../form/sales/questions/person4_age_known.rb | 6 ++ .../form/sales/questions/person4_known.rb | 24 ++++++++ .../subsections/household_characteristics.rb | 3 + .../form/headers/_person_2_known_page.erb | 1 + .../form/headers/_person_3_known_page.erb | 1 + .../form/headers/_person_4_known_page.erb | 1 + app/views/form/page.html.erb | 10 +++- ...10085259_add_details_known_to_sales_log.rb | 7 +++ db/schema.rb | 3 + spec/factories/sales_log.rb | 3 + .../form/sales/pages/person2_age_spec.rb | 6 +- .../form/sales/pages/person2_known_spec.rb | 43 +++++++++++++ .../form/sales/pages/person3_age_spec.rb | 5 +- .../form/sales/pages/person3_known_spec.rb | 42 +++++++++++++ .../form/sales/pages/person4_age_spec.rb | 4 +- .../form/sales/pages/person4_known_spec.rb | 41 +++++++++++++ .../sales/questions/person2_age_known_spec.rb | 6 +- .../sales/questions/person2_known_spec.rb | 60 +++++++++++++++++++ .../sales/questions/person3_age_known_spec.rb | 6 +- .../sales/questions/person3_known_spec.rb | 60 +++++++++++++++++++ .../sales/questions/person4_age_known_spec.rb | 6 +- .../sales/questions/person4_known_spec.rb | 60 +++++++++++++++++++ .../household_characteristics_spec.rb | 3 + spec/models/form_handler_spec.rb | 4 +- 35 files changed, 501 insertions(+), 39 deletions(-) create mode 100644 app/models/form/sales/pages/person2_known.rb create mode 100644 app/models/form/sales/pages/person3_known.rb create mode 100644 app/models/form/sales/pages/person4_known.rb create mode 100644 app/models/form/sales/questions/person2_known.rb create mode 100644 app/models/form/sales/questions/person3_known.rb create mode 100644 app/models/form/sales/questions/person4_known.rb create mode 100644 app/views/form/headers/_person_2_known_page.erb create mode 100644 app/views/form/headers/_person_3_known_page.erb create mode 100644 app/views/form/headers/_person_4_known_page.erb create mode 100644 db/migrate/20221010085259_add_details_known_to_sales_log.rb create mode 100644 spec/models/form/sales/pages/person2_known_spec.rb create mode 100644 spec/models/form/sales/pages/person3_known_spec.rb create mode 100644 spec/models/form/sales/pages/person4_known_spec.rb create mode 100644 spec/models/form/sales/questions/person2_known_spec.rb create mode 100644 spec/models/form/sales/questions/person3_known_spec.rb create mode 100644 spec/models/form/sales/questions/person4_known_spec.rb diff --git a/app/models/form/page.rb b/app/models/form/page.rb index 3ee1932cc..5bf1e1618 100644 --- a/app/models/form/page.rb +++ b/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"] diff --git a/app/models/form/sales/pages/person2_age.rb b/app/models/form/sales/pages/person2_age.rb index aaf818b5a..3b300f957 100644 --- a/app/models/form/sales/pages/person2_age.rb +++ b/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 diff --git a/app/models/form/sales/pages/person2_known.rb b/app/models/form/sales/pages/person2_known.rb new file mode 100644 index 000000000..c1eeebf20 --- /dev/null +++ b/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 diff --git a/app/models/form/sales/pages/person3_age.rb b/app/models/form/sales/pages/person3_age.rb index 39aa45f27..0f8635b23 100644 --- a/app/models/form/sales/pages/person3_age.rb +++ b/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 diff --git a/app/models/form/sales/pages/person3_known.rb b/app/models/form/sales/pages/person3_known.rb new file mode 100644 index 000000000..7671a0de4 --- /dev/null +++ b/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 diff --git a/app/models/form/sales/pages/person4_age.rb b/app/models/form/sales/pages/person4_age.rb index d2ff447e3..42d926c2b 100644 --- a/app/models/form/sales/pages/person4_age.rb +++ b/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 diff --git a/app/models/form/sales/pages/person4_known.rb b/app/models/form/sales/pages/person4_known.rb new file mode 100644 index 000000000..c6c0208ea --- /dev/null +++ b/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 diff --git a/app/models/form/sales/questions/person2_age_known.rb b/app/models/form/sales/questions/person2_age_known.rb index d91fc87ad..af06a0eb8 100644 --- a/app/models/form/sales/questions/person2_age_known.rb +++ b/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 diff --git a/app/models/form/sales/questions/person2_known.rb b/app/models/form/sales/questions/person2_known.rb new file mode 100644 index 000000000..bc931d23f --- /dev/null +++ b/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 diff --git a/app/models/form/sales/questions/person3_age_known.rb b/app/models/form/sales/questions/person3_age_known.rb index a0e5d3da1..c784ef1cb 100644 --- a/app/models/form/sales/questions/person3_age_known.rb +++ b/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 diff --git a/app/models/form/sales/questions/person3_known.rb b/app/models/form/sales/questions/person3_known.rb new file mode 100644 index 000000000..f6f79447e --- /dev/null +++ b/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 diff --git a/app/models/form/sales/questions/person4_age_known.rb b/app/models/form/sales/questions/person4_age_known.rb index 2ba5256da..e21aa51d6 100644 --- a/app/models/form/sales/questions/person4_age_known.rb +++ b/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 diff --git a/app/models/form/sales/questions/person4_known.rb b/app/models/form/sales/questions/person4_known.rb new file mode 100644 index 000000000..ab6d4c132 --- /dev/null +++ b/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 diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index c7c0846c3..fb2b7dc6e 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/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 diff --git a/app/views/form/headers/_person_2_known_page.erb b/app/views/form/headers/_person_2_known_page.erb new file mode 100644 index 000000000..e305e36f4 --- /dev/null +++ b/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 diff --git a/app/views/form/headers/_person_3_known_page.erb b/app/views/form/headers/_person_3_known_page.erb new file mode 100644 index 000000000..2fd31a963 --- /dev/null +++ b/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 diff --git a/app/views/form/headers/_person_4_known_page.erb b/app/views/form/headers/_person_4_known_page.erb new file mode 100644 index 000000000..b96949344 --- /dev/null +++ b/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 diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 8d90f12b9..7a860c1db 100644 --- a/app/views/form/page.html.erb +++ b/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? %>

<% if !@page.hide_subsection_label %> <%= @subsection.label %> <% end %> - <%= @page.header %> + <% if @page.header_partial.present? %> + <%= render partial: "form/headers/#{@page.header_partial}", locals: { log: @log } %> + <% else %> + <%= @page.header %> + <% end %>

<% 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 %> <% end %> diff --git a/db/migrate/20221010085259_add_details_known_to_sales_log.rb b/db/migrate/20221010085259_add_details_known_to_sales_log.rb new file mode 100644 index 000000000..0b99acb2c --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index ebe7598a5..43fc94775 100644 --- a/db/schema.rb +++ b/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" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 31c4f1882..8e37581c5 100644 --- a/spec/factories/sales_log.rb +++ b/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 } diff --git a/spec/models/form/sales/pages/person2_age_spec.rb b/spec/models/form/sales/pages/person2_age_spec.rb index d24797b43..7ade29b65 100644 --- a/spec/models/form/sales/pages/person2_age_spec.rb +++ b/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 diff --git a/spec/models/form/sales/pages/person2_known_spec.rb b/spec/models/form/sales/pages/person2_known_spec.rb new file mode 100644 index 000000000..57bac950f --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/pages/person3_age_spec.rb b/spec/models/form/sales/pages/person3_age_spec.rb index ca3a36c94..5089ae7ae 100644 --- a/spec/models/form/sales/pages/person3_age_spec.rb +++ b/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 diff --git a/spec/models/form/sales/pages/person3_known_spec.rb b/spec/models/form/sales/pages/person3_known_spec.rb new file mode 100644 index 000000000..ef4c1c34d --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/pages/person4_age_spec.rb b/spec/models/form/sales/pages/person4_age_spec.rb index cc61b3287..e8b331435 100644 --- a/spec/models/form/sales/pages/person4_age_spec.rb +++ b/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 diff --git a/spec/models/form/sales/pages/person4_known_spec.rb b/spec/models/form/sales/pages/person4_known_spec.rb new file mode 100644 index 000000000..024c121c9 --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/questions/person2_age_known_spec.rb b/spec/models/form/sales/questions/person2_age_known_spec.rb index e64db0dff..7ebee9dee 100644 --- a/spec/models/form/sales/questions/person2_age_known_spec.rb +++ b/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 diff --git a/spec/models/form/sales/questions/person2_known_spec.rb b/spec/models/form/sales/questions/person2_known_spec.rb new file mode 100644 index 000000000..4e8a639c0 --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/questions/person3_age_known_spec.rb b/spec/models/form/sales/questions/person3_age_known_spec.rb index 3b3ef6ff2..bb1762c88 100644 --- a/spec/models/form/sales/questions/person3_age_known_spec.rb +++ b/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 diff --git a/spec/models/form/sales/questions/person3_known_spec.rb b/spec/models/form/sales/questions/person3_known_spec.rb new file mode 100644 index 000000000..bab7d864c --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/questions/person4_age_known_spec.rb b/spec/models/form/sales/questions/person4_age_known_spec.rb index c72d92997..41a64cbea 100644 --- a/spec/models/form/sales/questions/person4_age_known_spec.rb +++ b/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 diff --git a/spec/models/form/sales/questions/person4_known_spec.rb b/spec/models/form/sales/questions/person4_known_spec.rb new file mode 100644 index 000000000..667a71f01 --- /dev/null +++ b/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 diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 1c0bdca86..dbe8a24a3 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/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 ], ) diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 87a04487a..81a9b1c45 100644 --- a/spec/models/form_handler_spec.rb +++ b/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