From 724b199db1f571c3dfa001bc54b6de6d218f7349 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Mon, 20 Feb 2023 10:55:30 +0000 Subject: [PATCH] update copy to handle pluralisation in the case of joint purchase for previous ownership, with associated testing changes --- .../form/sales/pages/previous_ownership.rb | 9 ++++--- app/models/form/sales/questions/prevown.rb | 8 +++--- .../income_benefits_and_savings.rb | 3 ++- .../sales/pages/previous_ownership_spec.rb | 19 +++++++++++--- .../form/sales/questions/prevown_spec.rb | 25 +++++++++++++++---- .../income_benefits_and_savings_spec.rb | 6 +++-- 6 files changed, 51 insertions(+), 19 deletions(-) diff --git a/app/models/form/sales/pages/previous_ownership.rb b/app/models/form/sales/pages/previous_ownership.rb index 88b438e07..f1e2edc68 100644 --- a/app/models/form/sales/pages/previous_ownership.rb +++ b/app/models/form/sales/pages/previous_ownership.rb @@ -1,12 +1,13 @@ class Form::Sales::Pages::PreviousOwnership < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "previous_ownership" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase + @depends_on = [{ "joint_purchase?" => @joint_purchase}] end def questions @questions ||= [ - Form::Sales::Questions::Prevown.new(nil, nil, self), + Form::Sales::Questions::Prevown.new(nil, nil, self, joint_purchase: @joint_purchase), ] end end diff --git a/app/models/form/sales/questions/prevown.rb b/app/models/form/sales/questions/prevown.rb index a9a3b086b..50e6f081e 100644 --- a/app/models/form/sales/questions/prevown.rb +++ b/app/models/form/sales/questions/prevown.rb @@ -1,9 +1,9 @@ class Form::Sales::Questions::Prevown < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "prevown" - @check_answer_label = "Buyers previously owned a property" - @header = "Has the buyer previously owned a property?" + @check_answer_label = "Buyer#{'s' if joint_purchase} previously owned a property" + @header = "#{joint_purchase ? 'Have any of the buyers' : 'Has the buyer'} previously owned a property?" @type = "radio" @answer_options = ANSWER_OPTIONS end diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index 9ff584d47..502b87fc9 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -23,7 +23,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection Form::Sales::Pages::Savings.new(nil, nil, self), Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self), Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self), - Form::Sales::Pages::PreviousOwnership.new(nil, nil, self), + Form::Sales::Pages::PreviousOwnership.new("previous_ownership_joint_purchase", nil, self, joint_purchase: true), + Form::Sales::Pages::PreviousOwnership.new("previous_ownership_not_joint_purchase", nil, self, joint_purchase: false), previous_shared_page, ].compact end diff --git a/spec/models/form/sales/pages/previous_ownership_spec.rb b/spec/models/form/sales/pages/previous_ownership_spec.rb index 7fe0d2795..69c93fefa 100644 --- a/spec/models/form/sales/pages/previous_ownership_spec.rb +++ b/spec/models/form/sales/pages/previous_ownership_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::PreviousOwnership, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase:) } - let(:page_id) { nil } + let(:page_id) { "example_id" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:joint_purchase) { true } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -16,7 +17,7 @@ RSpec.describe Form::Sales::Pages::PreviousOwnership, type: :model do end it "has the correct id" do - expect(page.id).to eq("previous_ownership") + expect(page.id).to eq("example_id") end it "has the correct header" do @@ -26,4 +27,16 @@ RSpec.describe Form::Sales::Pages::PreviousOwnership, type: :model do it "has the correct description" do expect(page.description).to be_nil end + + it "when sale is a joint purchase has the correct depends on" do + expect(page.depends_on).to eq([{ "joint_purchase?" => true }]) + end + + context "when sale is not a joint purchase" do + let(:joint_purchase) { false } + + it "has the correct depends on" do + expect(page.depends_on).to eq([{ "joint_purchase?" => false }]) + end + end end diff --git a/spec/models/form/sales/questions/prevown_spec.rb b/spec/models/form/sales/questions/prevown_spec.rb index dda2b7c70..d7b101c99 100644 --- a/spec/models/form/sales/questions/prevown_spec.rb +++ b/spec/models/form/sales/questions/prevown_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::Prevown, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase:) } let(:question_id) { nil } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:joint_purchase) { false } it "has correct page" do expect(question.page).to eq(page) @@ -15,12 +16,26 @@ RSpec.describe Form::Sales::Questions::Prevown, type: :model do expect(question.id).to eq("prevown") end - it "has the correct header" do - expect(question.header).to eq("Has the buyer previously owned a property?") + context "when sale is not a joint purchase" do + it "has the correct header" do + expect(question.header).to eq("Has the buyer previously owned a property?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer previously owned a property") + end end - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Buyers previously owned a property") + context "when sale is a joint purchase" do + let(:joint_purchase) { true } + + it "has the correct header" do + expect(question.header).to eq("Have any of the buyers previously owned a property?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyers previously owned a property") + end end it "has the correct type" do diff --git a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb index 6c0997fd2..aef451878 100644 --- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb +++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb @@ -35,7 +35,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model savings savings_value_check savings_deposit_value_check - previous_ownership + previous_ownership_joint_purchase + previous_ownership_not_joint_purchase ], ) end @@ -62,7 +63,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model savings savings_value_check savings_deposit_value_check - previous_ownership + previous_ownership_joint_purchase + previous_ownership_not_joint_purchase previous_shared ], )