Browse Source

update copy to handle pluralisation in the case of joint purchase for previous ownership, with associated testing changes

pull/1326/head
Arthur Campbell 3 years ago
parent
commit
724b199db1
  1. 9
      app/models/form/sales/pages/previous_ownership.rb
  2. 8
      app/models/form/sales/questions/prevown.rb
  3. 3
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  4. 19
      spec/models/form/sales/pages/previous_ownership_spec.rb
  5. 25
      spec/models/form/sales/questions/prevown_spec.rb
  6. 6
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

9
app/models/form/sales/pages/previous_ownership.rb

@ -1,12 +1,13 @@
class Form::Sales::Pages::PreviousOwnership < ::Form::Page class Form::Sales::Pages::PreviousOwnership < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection, joint_purchase:)
super super(id, hsh, subsection)
@id = "previous_ownership" @joint_purchase = joint_purchase
@depends_on = [{ "joint_purchase?" => @joint_purchase}]
end end
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::Prevown.new(nil, nil, self), Form::Sales::Questions::Prevown.new(nil, nil, self, joint_purchase: @joint_purchase),
] ]
end end
end end

8
app/models/form/sales/questions/prevown.rb

@ -1,9 +1,9 @@
class Form::Sales::Questions::Prevown < ::Form::Question class Form::Sales::Questions::Prevown < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page, joint_purchase:)
super super(id, hsh, page)
@id = "prevown" @id = "prevown"
@check_answer_label = "Buyers previously owned a property" @check_answer_label = "Buyer#{'s' if joint_purchase} previously owned a property"
@header = "Has the buyer previously owned a property?" @header = "#{joint_purchase ? 'Have any of the buyers' : 'Has the buyer'} previously owned a property?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
end end

3
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::Savings.new(nil, nil, self),
Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", 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::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, previous_shared_page,
].compact ].compact
end end

19
spec/models/form/sales/pages/previous_ownership_spec.rb

@ -1,11 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Pages::PreviousOwnership, type: :model do 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(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:joint_purchase) { true }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
@ -16,7 +17,7 @@ RSpec.describe Form::Sales::Pages::PreviousOwnership, type: :model do
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("previous_ownership") expect(page.id).to eq("example_id")
end end
it "has the correct header" do 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 it "has the correct description" do
expect(page.description).to be_nil expect(page.description).to be_nil
end 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 end

25
spec/models/form/sales/questions/prevown_spec.rb

@ -1,11 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Prevown, type: :model do 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_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:joint_purchase) { false }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) 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") expect(question.id).to eq("prevown")
end end
it "has the correct header" do context "when sale is not a joint purchase" do
expect(question.header).to eq("Has the buyer previously owned a property?") 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 end
it "has the correct check_answer_label" do context "when sale is a joint purchase" do
expect(question.check_answer_label).to eq("Buyers previously owned a property") 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 end
it "has the correct type" do it "has the correct type" do

6
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
savings_value_check savings_value_check
savings_deposit_value_check savings_deposit_value_check
previous_ownership previous_ownership_joint_purchase
previous_ownership_not_joint_purchase
], ],
) )
end end
@ -62,7 +63,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
savings savings
savings_value_check savings_value_check
savings_deposit_value_check savings_deposit_value_check
previous_ownership previous_ownership_joint_purchase
previous_ownership_not_joint_purchase
previous_shared previous_shared
], ],
) )

Loading…
Cancel
Save