Browse Source

CLDC-1629-update-card-titles (#1103)

* Refactor details known to reuse pages and questions

* Refactor page_depends_on

* Use field_for_person

* feat: tweak person_known behaviour to only show for people 2-4, and ask person_known regardless of answer to previous person_known questions. Also remove redundant personx_known files

* test: update tests

* feat: add dynamic cya card titles

* refactor: simplificaiton

* refactor: use check_answers_card_number again

* refactor: linting

* tests: add card title tests for sales log CYA page

* refactor: linting

* feat: make private method private

* feat: update person known behaviour

* test: update tests

* test: update tests

* test: add new person known tests

* feat: remove buyer 1 working situation duplicated header

* refactor: linting

Co-authored-by: Kat <katrina@kosiak.co.uk>
pull/1134/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
9dbf44f914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/components/check_answers_summary_list_card_component.html.erb
  2. 24
      app/components/check_answers_summary_list_card_component.rb
  3. 2
      app/models/form/sales/pages/buyer1_working_situation.rb
  4. 2
      app/models/form/sales/pages/person.rb
  5. 8
      app/models/form/sales/pages/person_age.rb
  6. 8
      app/models/form/sales/pages/person_known.rb
  7. 8
      app/models/form/sales/pages/person_working_situation.rb
  8. 2
      app/models/form/sales/questions/person.rb
  9. 6
      app/models/form/sales/questions/person_known.rb
  10. 12
      app/models/form/sales/subsections/household_characteristics.rb
  11. 2
      config/forms/2021_2022.json
  12. 2
      config/forms/2022_2023.json
  13. 6
      db/schema.rb
  14. 2
      spec/features/form/check_answers_page_lettings_logs_spec.rb
  15. 62
      spec/features/form/check_answers_page_sales_logs_spec.rb
  16. 2
      spec/models/form/sales/pages/buyer1_working_situation_spec.rb
  17. 4
      spec/models/form/sales/pages/person_age_spec.rb
  18. 264
      spec/models/form/sales/pages/person_known_spec.rb
  19. 4
      spec/models/form/sales/pages/person_working_situation_spec.rb
  20. 303
      spec/models/form/sales/questions/person_known_spec.rb
  21. 4
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  22. 4
      spec/models/form_handler_spec.rb

7
app/components/check_answers_summary_list_card_component.html.erb

@ -2,12 +2,7 @@
<div class="x-govuk-summary-card govuk-!-margin-bottom-6"> <div class="x-govuk-summary-card govuk-!-margin-bottom-6">
<% 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 != 0 && applicable_questions.first.check_answers_card_number.present? %>
<div class="x-govuk-summary-card__header"> <div class="x-govuk-summary-card__header">
<% if applicable_questions.first.check_answers_card_number == 1 %> <h3 class="x-govuk-summary-card__title"><%= check_answers_card_title(applicable_questions.first) %></h3>
<h3 class="x-govuk-summary-card__title">Lead tenant</h3>
<% end %>
<% if applicable_questions.first.check_answers_card_number > 1 %>
<h3 class="x-govuk-summary-card__title">Person <%= applicable_questions.first.check_answers_card_number %></h3>
<% end %>
</div> </div>
<% end %> <% end %>
<div class="x-govuk-summary-card__body"> <div class="x-govuk-summary-card__body">

24
app/components/check_answers_summary_list_card_component.rb

@ -15,4 +15,28 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
def get_answer_label(question) def get_answer_label(question)
question.answer_label(log).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe question.answer_label(log).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end 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 end

2
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) def initialize(id, hsh, subsection)
super super
@id = "buyer_1_working_situation" @id = "buyer_1_working_situation"
@header = "Which of these best describes buyer 1's working situation?" @header = ""
@description = "" @description = ""
@subsection = subsection @subsection = subsection
end end

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

@ -17,6 +17,8 @@ class Form::Sales::Pages::Person < ::Form::Page
end end
def field_for_person(field, suffix = "") def field_for_person(field, suffix = "")
return [field, person_display_number, suffix].join if field == "details_known_"
[field, @person_index, suffix].join [field, @person_index, suffix].join
end end
end end

8
app/models/form/sales/pages/person_age.rb

@ -4,7 +4,7 @@ class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person
@header = "" @header = ""
@description = "" @description = ""
@subsection = subsection @subsection = subsection
@depends_on = page_depends_on @depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
end end
def questions 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), Form::Sales::Questions::PersonAge.new(field_for_person("age"), nil, self, person_index: @person_index),
] ]
end 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 end

8
app/models/form/sales/pages/person_known.rb

@ -1,11 +1,11 @@
class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super super
@header_partial = "#{id}_page" @header_partial = "person_#{person_display_number}_known_page"
@header = "" @header = ""
@description = "" @description = ""
@subsection = subsection @subsection = subsection
@depends_on = page_depends_on @depends_on = (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } }
end end
def questions 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), Form::Sales::Questions::PersonKnown.new(field_for_person("details_known_"), nil, self, person_index: @person_index),
] ]
end end
def page_depends_on
(@person_index..4).map { |index| { "hholdcount" => index } }
end
end end

8
app/models/form/sales/pages/person_working_situation.rb

@ -4,7 +4,7 @@ class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person
@header = "" @header = ""
@description = "" @description = ""
@subsection = subsection @subsection = subsection
@depends_on = page_depends_on @depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
end end
def questions 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), Form::Sales::Questions::PersonWorkingSituation.new(field_for_person("ecstat"), nil, self, person_index: @person_index),
] ]
end 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 end

2
app/models/form/sales/questions/person.rb

@ -13,6 +13,8 @@ class Form::Sales::Questions::Person < ::Form::Question
end end
def field_for_person(field, suffix = "") def field_for_person(field, suffix = "")
return [field, person_display_number, suffix].join if field == "details_known_"
[field, @person_index, suffix].join [field, @person_index, suffix].join
end end
end end

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

@ -1,8 +1,8 @@
class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person
def initialize(id, hsh, page, person_index:) def initialize(id, hsh, page, person_index:)
super super
@check_answer_label = "Details known for person #{person_index}?" @check_answer_label = "Details known for person #{person_display_number}?"
@header = "Do you know the details for person #{person_index}?" @header = "Do you know the details for person #{person_display_number}?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@page = page @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 end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {

12
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::Buyer2WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.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", 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::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), 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::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", nil, self, person_index: 2),
Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self, person_index: 3), 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", 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::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", nil, self, person_index: 3),
Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self, person_index: 4), 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", nil, self, person_index: 3),
Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self, person_index: 4), 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", 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::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", nil, self, person_index: 4),
Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self, person_index: 5), 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", nil, self, person_index: 4),
Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self, person_index: 5), 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", 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::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), Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 5),

2
config/forms/2021_2022.json

@ -4624,7 +4624,7 @@
} }
}, },
"person_7_known": { "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": "", "description": "",
"questions": { "questions": {
"details_known_7": { "details_known_7": {

2
config/forms/2022_2023.json

@ -4623,7 +4623,7 @@
} }
}, },
"person_7_known": { "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": "", "description": "",
"questions": { "questions": {
"details_known_7": { "details_known_7": {

6
db/schema.rb

@ -420,6 +420,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.string "relat4" t.string "relat4"
t.string "relat5" t.string "relat5"
t.string "relat6" t.string "relat6"
t.integer "hb"
t.integer "savings_value_check"
t.integer "deposit_value_check"
t.integer "frombeds" t.integer "frombeds"
t.integer "staircase" t.integer "staircase"
t.integer "stairbought" t.integer "stairbought"
@ -455,9 +458,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.integer "hhregresstill" t.integer "hhregresstill"
t.integer "proplen" t.integer "proplen"
t.integer "prevten" t.integer "prevten"
t.integer "savings_value_check"
t.integer "deposit_value_check"
t.integer "hb"
t.integer "mortgageused" t.integer "mortgageused"
t.integer "wchair" t.integer "wchair"
t.integer "armedforcesspouse" t.integer "armedforcesspouse"

2
spec/features/form/check_answers_page_spec.rb → spec/features/form/check_answers_page_lettings_logs_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
require_relative "helpers" require_relative "helpers"
RSpec.describe "Form Check Answers Page" do RSpec.describe "Lettings Log Check Answers Page" do
include Helpers include Helpers
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:subsection) { "household-characteristics" } let(:subsection) { "household-characteristics" }

62
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

2
spec/models/form/sales/pages/buyer1_working_situation_spec.rb

@ -20,6 +20,6 @@ RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do
end end
it "has the correct header" do 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
end end

4
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 it "has correct depends_on" do
expect(page.depends_on).to eq( 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
end end
@ -119,7 +119,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( 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
end end

264
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 RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) }
let(:page_id) { "person_2_known" } context "without joint purchase" do
let(:page_definition) { nil } let(:page_id) { "person_2_known" }
let(:subsection) { instance_double(Form::Subsection) } let(:page_definition) { nil }
let(:person_index) { 1 } let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 3 }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end end
it "has the correct header" do it "has the correct header" do
expect(page.header).to eq("") expect(page.header).to eq("")
end end
it "has the correct description" do it "has the correct description" do
expect(page.description).to eq("") expect(page.description).to eq("")
end 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 it "has the correct header_partial" do
let(:page_id) { "person_1_known" } expect(page.header_partial).to eq("person_1_known_page")
let(:person_index) { 1 } end
it "has correct questions" do it "has correct depends_on" do
expect(page.questions.map(&:id)).to eq(%w[details_known_1]) expect(page.depends_on).to eq(
[
{ "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }
],
)
end
end end
it "has the correct id" do context "with person 2" do
expect(page.id).to eq("person_1_known") 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 end
it "has the correct header_partial" do context "with person 3" do
expect(page.header_partial).to eq("person_1_known_page") 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 end
it "has correct depends_on" do context "with person 4" do
expect(page.depends_on).to eq( let(:page_id) { "person_4_known" }
[ let(:person_index) { 5 }
{ "hholdcount" => 1 },
{ "hholdcount" => 2 }, it "has correct questions" do
{ "hholdcount" => 3 }, expect(page.questions.map(&:id)).to eq(%w[details_known_4])
{ "hholdcount" => 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
end end
context "with person 2" do context "with joint purchase" do
let(:page_id) { "person_2_known" } 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 it "has correct subsection" do
expect(page.questions.map(&:id)).to eq(%w[details_known_2]) expect(page.subsection).to eq(subsection)
end end
it "has the correct id" do it "has the correct header" do
expect(page.id).to eq("person_2_known") expect(page.header).to eq("")
end end
it "has the correct header_partial" do it "has the correct description" do
expect(page.header_partial).to eq("person_2_known_page") expect(page.description).to eq("")
end end
it "has correct depends_on" do context "with person 1" do
expect(page.depends_on).to eq( let(:page_id) { "person_1_known_joint_purchase" }
[{ "hholdcount" => 2 }, { "hholdcount" => 3 }, { "hholdcount" => 4 }], let(:person_index) { 3 }
)
end
end
context "with person 3" do it "has correct questions" do
let(:page_id) { "person_3_known" } expect(page.questions.map(&:id)).to eq(%w[details_known_1])
let(:person_index) { 3 } end
it "has correct questions" do it "has the correct id" do
expect(page.questions.map(&:id)).to eq(%w[details_known_3]) expect(page.id).to eq("person_1_known_joint_purchase")
end end
it "has the correct id" do it "has the correct header_partial" do
expect(page.id).to eq("person_3_known") expect(page.header_partial).to eq("person_1_known_page")
end end
it "has the correct header_partial" do it "has correct depends_on" do
expect(page.header_partial).to eq("person_3_known_page") expect(page.depends_on).to eq(
[
{ "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }
],
)
end
end end
it "has correct depends_on" do context "with person 2" do
expect(page.depends_on).to eq( let(:page_id) { "person_2_known_joint_purchase" }
[{ "hholdcount" => 3 }, { "hholdcount" => 4 }], let(:person_index) { 4 }
)
end
end
context "with person 4" do it "has correct questions" do
let(:page_id) { "person_4_known" } expect(page.questions.map(&:id)).to eq(%w[details_known_2])
let(:person_index) { 4 } end
it "has correct questions" do it "has the correct id" do
expect(page.questions.map(&:id)).to eq(%w[details_known_4]) expect(page.id).to eq("person_2_known_joint_purchase")
end 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 it "has correct depends_on" do
expect(page.id).to eq("person_4_known") expect(page.depends_on).to eq(
[{ "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }],
)
end
end end
it "has the correct header_partial" do context "with person 3" do
expect(page.header_partial).to eq("person_4_known_page") 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 end
it "has correct depends_on" do context "with person 4" do
expect(page.depends_on).to eq( let(:page_id) { "person_4_known_joint_purchase" }
[{ "hholdcount" => 4 }], 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 end
end end

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

@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do
end end
it "has correct depends_on" 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 }]) expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }])
end end
end end
@ -119,7 +119,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do
end end
it "has correct depends_on" 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 }]) expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end end
end end

303
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_id) { "details_known_1" }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } 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 it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -27,44 +31,291 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do
}) })
end end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to eq("") expect(question.hint_text).to eq("")
end end
context "with person 1" do context "with a non joint purchase" do
let(:question_id) { "details_known_1" } context "and person 1" do
let(:person_index) { 1 } 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 it "has the correct header" do
expect(question.id).to eq("details_known_1") 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
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 it "has the correct check_answer_label" do
expect(question.header).to eq("Do you know the details for person 1?") 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 end
it "has the correct check_answer_label" do context "and person 2" do
expect(question.check_answer_label).to eq("Details known for person 1?") 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 end
it "has the correct hidden_in_check_answers" do context "and person 3" do
expect(question.hidden_in_check_answers).to eq( let(:question_id) { "details_known_3" }
{ let(:person_index) { 5 }
"depends_on" => [
{ before do
"details_known_1" => 1, 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 end
it "has the correct check_answers_card_number" do context "and person 4" do
expect(question.check_answers_card_number).to eq(3) 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 end
end end

4
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 buyer_2_live_in_property
number_of_others_in_property number_of_others_in_property
person_1_known person_1_known
person_1_known_joint_purchase
person_1_relationship_to_buyer_1 person_1_relationship_to_buyer_1
person_1_relationship_to_buyer_1_joint_purchase person_1_relationship_to_buyer_1_joint_purchase
person_1_age person_1_age
@ -44,6 +45,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
person_1_working_situation person_1_working_situation
person_1_working_situation_joint_purchase person_1_working_situation_joint_purchase
person_2_known person_2_known
person_2_known_joint_purchase
person_2_relationship_to_buyer_1 person_2_relationship_to_buyer_1
person_2_relationship_to_buyer_1_joint_purchase person_2_relationship_to_buyer_1_joint_purchase
person_2_age person_2_age
@ -51,6 +53,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
person_2_working_situation person_2_working_situation
person_2_working_situation_joint_purchase person_2_working_situation_joint_purchase
person_3_known person_3_known
person_3_known_joint_purchase
person_3_relationship_to_buyer_1 person_3_relationship_to_buyer_1
person_3_relationship_to_buyer_1_joint_purchase person_3_relationship_to_buyer_1_joint_purchase
person_3_age person_3_age
@ -58,6 +61,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
person_3_working_situation person_3_working_situation
person_3_working_situation_joint_purchase person_3_working_situation_joint_purchase
person_4_known person_4_known
person_4_known_joint_purchase
person_4_relationship_to_buyer_1 person_4_relationship_to_buyer_1
person_4_relationship_to_buyer_1_joint_purchase person_4_relationship_to_buyer_1_joint_purchase
person_4_age person_4_age

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) 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") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) 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") expect(form.name).to eq("2021_2022_sales")
end end
end end

Loading…
Cancel
Save