diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index d04283939..0005ed790 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -2,12 +2,7 @@
<% if applicable_questions.first.check_answers_card_number != 0 && applicable_questions.first.check_answers_card_number.present? %>
- <% if applicable_questions.first.check_answers_card_number == 1 %> -

Lead tenant

- <% end %> - <% if applicable_questions.first.check_answers_card_number > 1 %> -

Person <%= applicable_questions.first.check_answers_card_number %>

- <% end %> +

<%= check_answers_card_title(applicable_questions.first) %>

<% end %>
diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index de7fe9685..246173f48 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -15,4 +15,28 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base def get_answer_label(question) question.answer_label(log).presence || "You didn’t answer this question".html_safe end + + def check_answers_card_title(question) + if question.form.type == "lettings" + case question.check_answers_card_number + when 1 + "Lead tenant" + when 2..8 + "Person #{question.check_answers_card_number}" + end + else + case question.check_answers_card_number + when 1..number_of_buyers + "Buyer #{question.check_answers_card_number}" + when (number_of_buyers + 1)..(number_of_buyers + 4) + "Person #{question.check_answers_card_number - number_of_buyers}" + end + end + end + +private + + def number_of_buyers + log[:jointpur] == 1 ? 2 : 1 + end end diff --git a/app/models/form/sales/pages/buyer1_working_situation.rb b/app/models/form/sales/pages/buyer1_working_situation.rb index caaa0e60f..bde1dba09 100644 --- a/app/models/form/sales/pages/buyer1_working_situation.rb +++ b/app/models/form/sales/pages/buyer1_working_situation.rb @@ -2,7 +2,7 @@ class Form::Sales::Pages::Buyer1WorkingSituation < ::Form::Page def initialize(id, hsh, subsection) super @id = "buyer_1_working_situation" - @header = "Which of these best describes buyer 1's working situation?" + @header = "" @description = "" @subsection = subsection end diff --git a/app/models/form/sales/pages/person.rb b/app/models/form/sales/pages/person.rb index 66e797cfa..3cf347353 100644 --- a/app/models/form/sales/pages/person.rb +++ b/app/models/form/sales/pages/person.rb @@ -17,6 +17,8 @@ class Form::Sales::Pages::Person < ::Form::Page end def field_for_person(field, suffix = "") + return [field, person_display_number, suffix].join if field == "details_known_" + [field, @person_index, suffix].join end end diff --git a/app/models/form/sales/pages/person_age.rb b/app/models/form/sales/pages/person_age.rb index 1eea81818..f0f86a251 100644 --- a/app/models/form/sales/pages/person_age.rb +++ b/app/models/form/sales/pages/person_age.rb @@ -4,7 +4,7 @@ class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person @header = "" @description = "" @subsection = subsection - @depends_on = page_depends_on + @depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }] end def questions @@ -13,10 +13,4 @@ class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person Form::Sales::Questions::PersonAge.new(field_for_person("age"), nil, self, person_index: @person_index), ] end - - def page_depends_on - return (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } } if person_display_number == 1 - - [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }] - end end diff --git a/app/models/form/sales/pages/person_known.rb b/app/models/form/sales/pages/person_known.rb index 8a2d29bba..df82ff41d 100644 --- a/app/models/form/sales/pages/person_known.rb +++ b/app/models/form/sales/pages/person_known.rb @@ -1,11 +1,11 @@ class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person def initialize(id, hsh, subsection, person_index:) super - @header_partial = "#{id}_page" + @header_partial = "person_#{person_display_number}_known_page" @header = "" @description = "" @subsection = subsection - @depends_on = page_depends_on + @depends_on = (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } } end def questions @@ -13,8 +13,4 @@ class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person Form::Sales::Questions::PersonKnown.new(field_for_person("details_known_"), nil, self, person_index: @person_index), ] end - - def page_depends_on - (@person_index..4).map { |index| { "hholdcount" => index } } - end end diff --git a/app/models/form/sales/pages/person_working_situation.rb b/app/models/form/sales/pages/person_working_situation.rb index f232f6a84..a78e90be3 100644 --- a/app/models/form/sales/pages/person_working_situation.rb +++ b/app/models/form/sales/pages/person_working_situation.rb @@ -4,7 +4,7 @@ class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person @header = "" @description = "" @subsection = subsection - @depends_on = page_depends_on + @depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }] end def questions @@ -12,10 +12,4 @@ class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person Form::Sales::Questions::PersonWorkingSituation.new(field_for_person("ecstat"), nil, self, person_index: @person_index), ] end - - def page_depends_on - return (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } } if person_display_number == 1 - - [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }] - end end diff --git a/app/models/form/sales/questions/person.rb b/app/models/form/sales/questions/person.rb index ebc280860..3c7f78214 100644 --- a/app/models/form/sales/questions/person.rb +++ b/app/models/form/sales/questions/person.rb @@ -13,6 +13,8 @@ class Form::Sales::Questions::Person < ::Form::Question end def field_for_person(field, suffix = "") + return [field, person_display_number, suffix].join if field == "details_known_" + [field, @person_index, suffix].join end end diff --git a/app/models/form/sales/questions/person_known.rb b/app/models/form/sales/questions/person_known.rb index 0c1ef09c2..487b3f6d9 100644 --- a/app/models/form/sales/questions/person_known.rb +++ b/app/models/form/sales/questions/person_known.rb @@ -1,8 +1,8 @@ class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person def initialize(id, hsh, page, person_index:) super - @check_answer_label = "Details known for person #{person_index}?" - @header = "Do you know the details for person #{person_index}?" + @check_answer_label = "Details known for person #{person_display_number}?" + @header = "Do you know the details for person #{person_display_number}?" @type = "radio" @answer_options = ANSWER_OPTIONS @page = page @@ -14,7 +14,7 @@ class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person }, ], } - @check_answers_card_number = person_index + 2 + @check_answers_card_number = person_index end ANSWER_OPTIONS = { diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 4eb252c52..763577ffe 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -29,7 +29,8 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self), - Form::Sales::Pages::PersonKnown.new("person_1_known", nil, self, person_index: 1), + Form::Sales::Pages::PersonKnown.new("person_1_known", nil, self, person_index: 2), + Form::Sales::Pages::PersonKnown.new("person_1_known_joint_purchase", nil, self, person_index: 3), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_relationship_to_buyer_1", nil, self, person_index: 2), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 3), Form::Sales::Pages::PersonAge.new("person_1_age", nil, self, person_index: 2), @@ -38,21 +39,24 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self, person_index: 2), Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self, person_index: 3), - Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 2), + Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 3), + Form::Sales::Pages::PersonKnown.new("person_2_known_joint_purchase", nil, self, person_index: 4), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1", nil, self, person_index: 3), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 4), Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 3), Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self, person_index: 4), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self, person_index: 3), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self, person_index: 4), - Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 3), + Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 4), + Form::Sales::Pages::PersonKnown.new("person_3_known_joint_purchase", nil, self, person_index: 5), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1", nil, self, person_index: 4), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 5), Form::Sales::Pages::PersonAge.new("person_3_age", nil, self, person_index: 4), Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self, person_index: 5), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self, person_index: 4), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self, person_index: 5), - Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 4), + Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 5), + Form::Sales::Pages::PersonKnown.new("person_4_known_joint_purchase", nil, self, person_index: 6), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1", nil, self, person_index: 5), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 6), Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 5), diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index ca2fa6e2e..92d495f24 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -4624,7 +4624,7 @@ } }, "person_7_known": { - "header": "You’ve given us the details for 7 people in the household", + "header": "You’ve given us the details for 6 people in the household", "description": "", "questions": { "details_known_7": { diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index dd6d933a3..f49070bbf 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -4623,7 +4623,7 @@ } }, "person_7_known": { - "header": "You’ve given us the details for 7 people in the household", + "header": "You’ve given us the details for 6 people in the household", "description": "", "questions": { "details_known_7": { diff --git a/db/schema.rb b/db/schema.rb index 30a510ab1..49f59a503 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -420,6 +420,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do t.string "relat4" t.string "relat5" t.string "relat6" + t.integer "hb" + t.integer "savings_value_check" + t.integer "deposit_value_check" t.integer "frombeds" t.integer "staircase" t.integer "stairbought" @@ -455,9 +458,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do t.integer "hhregresstill" t.integer "proplen" t.integer "prevten" - t.integer "savings_value_check" - t.integer "deposit_value_check" - t.integer "hb" t.integer "mortgageused" t.integer "wchair" t.integer "armedforcesspouse" diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_lettings_logs_spec.rb similarity index 99% rename from spec/features/form/check_answers_page_spec.rb rename to spec/features/form/check_answers_page_lettings_logs_spec.rb index 7834e0dad..f8f0b8064 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_lettings_logs_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" require_relative "helpers" -RSpec.describe "Form Check Answers Page" do +RSpec.describe "Lettings Log Check Answers Page" do include Helpers let(:user) { FactoryBot.create(:user) } let(:subsection) { "household-characteristics" } diff --git a/spec/features/form/check_answers_page_sales_logs_spec.rb b/spec/features/form/check_answers_page_sales_logs_spec.rb new file mode 100644 index 000000000..9d1f33d64 --- /dev/null +++ b/spec/features/form/check_answers_page_sales_logs_spec.rb @@ -0,0 +1,62 @@ +require "rails_helper" +require_relative "helpers" + +RSpec.describe "Sales Log Check Answers Page" do + include Helpers + let(:user) { FactoryBot.create(:user) } + let(:subsection) { "household-characteristics" } + let(:conditional_subsection) { "conditional-question" } + + let(:completed_sales_log_joint_purchase) do + FactoryBot.create( + :sales_log, + :completed, + created_by: user, + jointpur: 1, + ) + end + + let(:completed_sales_log_non_joint_purchase) do + FactoryBot.create( + :sales_log, + :completed, + created_by: user, + jointpur: 2, + ) + end + + before do + sign_in user + end + + context "when the user needs to check their answers for a subsection" do + let(:last_question_for_subsection) { "propcode" } + + it "does not group questions into summary cards if the questions in the subsection don't have a check_answers_card_number attribute" do + visit("/sales-logs/#{completed_sales_log_joint_purchase.id}/household-needs/check-answers") + assert_selector ".x-govuk-summary-card__title", count: 0 + end + + context "when the user is checking their answers for the household characteristics subsection" do + context "and the log is for a joint purchase" do + it "they see a seperate summary card for each member of the household" do + visit("/sales-logs/#{completed_sales_log_joint_purchase.id}/#{subsection}/check-answers") + assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1 + assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 1 + assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 1 + assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 0 + end + end + + context "and the log is for a non-joint purchase" do + it "they see a seperate summary card for each member of the household" do + visit("/sales-logs/#{completed_sales_log_non_joint_purchase.id}/#{subsection}/check-answers") + assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1 + assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 0 + assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 1 + assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 0 + end + end + end + end +end diff --git a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb index 2a48f0b0f..4b432ed03 100644 --- a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb +++ b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb @@ -20,6 +20,6 @@ RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do end it "has the correct header" do - expect(page.header).to eq("Which of these best describes buyer 1's working situation?") + expect(page.header).to eq("") end end diff --git a/spec/models/form/sales/pages/person_age_spec.rb b/spec/models/form/sales/pages/person_age_spec.rb index 4c4159896..f8bc96692 100644 --- a/spec/models/form/sales/pages/person_age_spec.rb +++ b/spec/models/form/sales/pages/person_age_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq( - [{ "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }], + [{ "details_known_1" => 1, "jointpur" => 2 }], ) end end @@ -119,7 +119,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq( - [{ "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }], + [{ "details_known_1" => 1, "jointpur" => 1 }], ) end end diff --git a/spec/models/form/sales/pages/person_known_spec.rb b/spec/models/form/sales/pages/person_known_spec.rb index 0dc454143..bb73d6b63 100644 --- a/spec/models/form/sales/pages/person_known_spec.rb +++ b/spec/models/form/sales/pages/person_known_spec.rb @@ -3,117 +3,229 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } - let(:page_id) { "person_2_known" } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } - let(:person_index) { 1 } + context "without joint purchase" do + let(:page_id) { "person_2_known" } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + let(:person_index) { 3 } - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end - it "has the correct header" do - expect(page.header).to eq("") - end + it "has the correct header" do + expect(page.header).to eq("") + end - it "has the correct description" do - expect(page.description).to eq("") - end + it "has the correct description" do + expect(page.description).to eq("") + end + + context "with person 1" do + let(:page_id) { "person_1_known" } + let(:person_index) { 2 } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[details_known_1]) + end + + it "has the correct id" do + expect(page.id).to eq("person_1_known") + end - context "with person 1" do - let(:page_id) { "person_1_known" } - let(:person_index) { 1 } + it "has the correct header_partial" do + expect(page.header_partial).to eq("person_1_known_page") + end - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[details_known_1]) + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 } + ], + ) + end end - it "has the correct id" do - expect(page.id).to eq("person_1_known") + context "with person 2" do + let(:page_id) { "person_2_known" } + let(:person_index) { 3 } + + 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_partial" do + expect(page.header_partial).to eq("person_2_known_page") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }], + ) + end end - it "has the correct header_partial" do - expect(page.header_partial).to eq("person_1_known_page") + context "with person 3" do + let(:page_id) { "person_3_known" } + let(:person_index) { 4 } + + 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_partial" do + expect(page.header_partial).to eq("person_3_known_page") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }], + ) + end end - it "has correct depends_on" do - expect(page.depends_on).to eq( - [ - { "hholdcount" => 1 }, - { "hholdcount" => 2 }, - { "hholdcount" => 3 }, - { "hholdcount" => 4 }, - ], - ) + context "with person 4" do + let(:page_id) { "person_4_known" } + let(:person_index) { 5 } + + 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_partial" do + expect(page.header_partial).to eq("person_4_known_page") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "hholdcount" => 4, "jointpur" => 2 }], + ) + end end end - context "with person 2" do + context "with joint purchase" do let(:page_id) { "person_2_known" } - let(:person_index) { 2 } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + let(:person_index) { 4 } - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[details_known_2]) + it "has correct subsection" do + expect(page.subsection).to eq(subsection) end - it "has the correct id" do - expect(page.id).to eq("person_2_known") + 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") + 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 + context "with person 1" do + let(:page_id) { "person_1_known_joint_purchase" } + let(:person_index) { 3 } - context "with person 3" do - let(:page_id) { "person_3_known" } - let(:person_index) { 3 } + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[details_known_1]) + 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_1_known_joint_purchase") + end - it "has the correct id" do - expect(page.id).to eq("person_3_known") - end + it "has the correct header_partial" do + expect(page.header_partial).to eq("person_1_known_page") + end - it "has the correct header_partial" do - expect(page.header_partial).to eq("person_3_known_page") + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 } + ], + ) + end end - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "hholdcount" => 3 }, { "hholdcount" => 4 }], - ) - end - end + context "with person 2" do + let(:page_id) { "person_2_known_joint_purchase" } + let(:person_index) { 4 } - context "with person 4" do - let(:page_id) { "person_4_known" } - let(:person_index) { 4 } + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[details_known_2]) + 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_2_known_joint_purchase") + end + + it "has the correct header_partial" do + expect(page.header_partial).to eq("person_2_known_page") + end - it "has the correct id" do - expect(page.id).to eq("person_4_known") + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }], + ) + end end - it "has the correct header_partial" do - expect(page.header_partial).to eq("person_4_known_page") + context "with person 3" do + let(:page_id) { "person_3_known_joint_purchase" } + let(:person_index) { 5 } + + 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_joint_purchase") + end + + it "has the correct header_partial" do + expect(page.header_partial).to eq("person_3_known_page") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }], + ) + end end - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "hholdcount" => 4 }], - ) + context "with person 4" do + let(:page_id) { "person_4_known_joint_purchase" } + let(:person_index) { 6 } + + 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_joint_purchase") + end + + it "has the correct header_partial" do + expect(page.header_partial).to eq("person_4_known_page") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "hholdcount" => 4, "jointpur" => 1 }], + ) + end end end end diff --git a/spec/models/form/sales/pages/person_working_situation_spec.rb b/spec/models/form/sales/pages/person_working_situation_spec.rb index e38d5ff47..65bdb42d0 100644 --- a/spec/models/form/sales/pages/person_working_situation_spec.rb +++ b/spec/models/form/sales/pages/person_working_situation_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to eq([{ "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }]) + expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }]) end end @@ -119,7 +119,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to eq([{ "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }]) + expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }]) end end diff --git a/spec/models/form/sales/questions/person_known_spec.rb b/spec/models/form/sales/questions/person_known_spec.rb index 2c33346f0..551ac096e 100644 --- a/spec/models/form/sales/questions/person_known_spec.rb +++ b/spec/models/form/sales/questions/person_known_spec.rb @@ -6,7 +6,11 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do let(:question_id) { "details_known_1" } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } - let(:person_index) { 1 } + let(:person_index) { 2 } + + before do + allow(page).to receive(:id).and_return("person_1_known") + end it "has correct page" do expect(question.page).to eq(page) @@ -27,44 +31,291 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do }) 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 - context "with person 1" do - let(:question_id) { "details_known_1" } - let(:person_index) { 1 } + context "with a non joint purchase" do + context "and person 1" do + let(:question_id) { "details_known_1" } + let(:person_index) { 2 } + + before do + allow(page).to receive(:id).and_return("person_1_known") + end + + it "has the correct id" do + expect(question.id).to eq("details_known_1") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know the details for person 1?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Details known for person 1?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to be_nil + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + "depends_on" => [{ "details_known_1" => 1 }], + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(2) + end + end + + context "and person 2" do + let(:question_id) { "details_known_2" } + let(:person_index) { 3 } + + before do + allow(page).to receive(:id).and_return("person_2_known") + 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 correct conditional for" do + expect(question.conditional_for).to be_nil + 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 + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end + end + + context "and person 3" do + let(:question_id) { "details_known_3" } + let(:person_index) { 4 } + + before do + allow(page).to receive(:id).and_return("person_3_known") + 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 correct conditional for" do + expect(question.conditional_for).to be_nil + 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 + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end + end + + context "and person 4" do + let(:question_id) { "details_known_4" } + let(:person_index) { 5 } + + before do + allow(page).to receive(:id).and_return("person_4_known") + end + + it "has the correct id" do + expect(question.id).to eq("details_known_4") + end - it "has the correct id" do - expect(question.id).to eq("details_known_1") + 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 correct conditional for" do + expect(question.conditional_for).to be_nil + 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 + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(5) + end end + end + + context "with a joint purchase" do + context "and person 1" do + let(:question_id) { "details_known_1" } + let(:person_index) { 3 } + + before do + allow(page).to receive(:id).and_return("person_1_known_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("details_known_1") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know the details for person 1?") + end - it "has the correct header" do - expect(question.header).to eq("Do you know the details for person 1?") + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Details known for person 1?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to be_nil + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + "depends_on" => [{ "details_known_1" => 1 }], + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end end - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Details known for person 1?") + context "and person 2" do + let(:question_id) { "details_known_2" } + let(:person_index) { 4 } + + before do + allow(page).to receive(:id).and_return("person_2_known_joint_purchase") + 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 correct conditional for" do + expect(question.conditional_for).to be_nil + 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 + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end end - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq( - { - "depends_on" => [ - { - "details_known_1" => 1, - }, - ], - }, - ) + context "and person 3" do + let(:question_id) { "details_known_3" } + let(:person_index) { 5 } + + before do + allow(page).to receive(:id).and_return("person_3_known_joint_purchase") + 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 correct conditional for" do + expect(question.conditional_for).to be_nil + 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 + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(5) + end end - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(3) + context "and person 4" do + let(:question_id) { "details_known_4" } + let(:person_index) { 6 } + + before do + allow(page).to receive(:id).and_return("person_4_known_joint_purchase") + 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 correct conditional for" do + expect(question.conditional_for).to be_nil + 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 + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(6) + end end 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 9c96ecb3a..ecdeca2dd 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -35,6 +35,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_live_in_property number_of_others_in_property person_1_known + person_1_known_joint_purchase person_1_relationship_to_buyer_1 person_1_relationship_to_buyer_1_joint_purchase person_1_age @@ -44,6 +45,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model person_1_working_situation person_1_working_situation_joint_purchase person_2_known + person_2_known_joint_purchase person_2_relationship_to_buyer_1 person_2_relationship_to_buyer_1_joint_purchase person_2_age @@ -51,6 +53,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model person_2_working_situation person_2_working_situation_joint_purchase person_3_known + person_3_known_joint_purchase person_3_relationship_to_buyer_1 person_3_relationship_to_buyer_1_joint_purchase person_3_age @@ -58,6 +61,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model person_3_working_situation person_3_working_situation_joint_purchase person_4_known + person_4_known_joint_purchase person_4_relationship_to_buyer_1 person_4_relationship_to_buyer_1_joint_purchase person_4_age diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 355f8cf2c..7d5339806 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -52,14 +52,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(118) + expect(form.pages.count).to eq(122) 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(118) + expect(form.pages.count).to eq(122) expect(form.name).to eq("2021_2022_sales") end end