diff --git a/app/models/form/sales/pages/about_staircase.rb b/app/models/form/sales/pages/about_staircase.rb index 2d1a17db4..de07aa98c 100644 --- a/app/models/form/sales/pages/about_staircase.rb +++ b/app/models/form/sales/pages/about_staircase.rb @@ -1,17 +1,18 @@ class Form::Sales::Pages::AboutStaircase < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "about_staircasing" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase @header = "About the staircasing transaction" @depends_on = [{ "staircase" => 1, + "joint_purchase?" => joint_purchase }] end def questions @questions ||= [ Form::Sales::Questions::StaircaseBought.new(nil, nil, self), - Form::Sales::Questions::StaircaseOwned.new(nil, nil, self), + Form::Sales::Questions::StaircaseOwned.new(nil, nil, self, joint_purchase: @joint_purchase), staircase_sale_question, ].compact end diff --git a/app/models/form/sales/pages/previous_ownership.rb b/app/models/form/sales/pages/previous_ownership.rb index f1e2edc68..50711baf7 100644 --- a/app/models/form/sales/pages/previous_ownership.rb +++ b/app/models/form/sales/pages/previous_ownership.rb @@ -2,7 +2,7 @@ class Form::Sales::Pages::PreviousOwnership < ::Form::Page def initialize(id, hsh, subsection, joint_purchase:) super(id, hsh, subsection) @joint_purchase = joint_purchase - @depends_on = [{ "joint_purchase?" => @joint_purchase}] + @depends_on = [{ "joint_purchase?" => @joint_purchase }] end def questions diff --git a/app/models/form/sales/questions/staircase_owned.rb b/app/models/form/sales/questions/staircase_owned.rb index 7e6dab5d6..3f10b0920 100644 --- a/app/models/form/sales/questions/staircase_owned.rb +++ b/app/models/form/sales/questions/staircase_owned.rb @@ -1,9 +1,9 @@ class Form::Sales::Questions::StaircaseOwned < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "stairowned" - @check_answer_label = "Percentage the buyer now owns in total" - @header = "What percentage of the property does the buyer now own in total?" + @check_answer_label = "Percentage the buyer#{'s' if joint_purchase} now own#{'s' if !joint_purchase} in total" + @header = "What percentage of the property #{joint_purchase ? 'do the buyers' : 'does the buyer'} now own in total?" @type = "numeric" @width = 5 @min = 0 diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 1f0cd6450..40bca11be 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -10,7 +10,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection @pages ||= [ Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership", nil, self), Form::Sales::Pages::Staircase.new(nil, nil, self), - Form::Sales::Pages::AboutStaircase.new(nil, nil, self), + Form::Sales::Pages::AboutStaircase.new("about_staircasing_joint_purchase", nil, self, joint_purchase: true), + Form::Sales::Pages::AboutStaircase.new("about_staircasing_not_joint_purchase", nil, self, joint_purchase: false), Form::Sales::Pages::StaircaseBoughtValueCheck.new(nil, nil, self), Form::Sales::Pages::Resale.new(nil, nil, self), Form::Sales::Pages::ExchangeDate.new(nil, nil, self), diff --git a/spec/models/form/sales/pages/about_staircase_spec.rb b/spec/models/form/sales/pages/about_staircase_spec.rb index 3828f52e4..48aa82acf 100644 --- a/spec/models/form/sales/pages/about_staircase_spec.rb +++ b/spec/models/form/sales/pages/about_staircase_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::AboutStaircase, 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) { "an_id" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:joint_purchase) { false } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -32,7 +33,7 @@ RSpec.describe Form::Sales::Pages::AboutStaircase, type: :model do end it "has the correct id" do - expect(page.id).to eq("about_staircasing") + expect(page.id).to eq("an_id") end it "has the correct header" do @@ -43,9 +44,23 @@ RSpec.describe Form::Sales::Pages::AboutStaircase, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([{ - "staircase" => 1, - }]) + context "when not a joint purchase" do + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "staircase" => 1, + "joint_purchase?" => false, + }]) + end + end + + context "when a joint purchase" do + let(:joint_purchase) { true } + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "staircase" => 1, + "joint_purchase?" => true, + }]) + end end end diff --git a/spec/models/form/sales/questions/staircase_owned_spec.rb b/spec/models/form/sales/questions/staircase_owned_spec.rb index cbd577784..8e78d540a 100644 --- a/spec/models/form/sales/questions/staircase_owned_spec.rb +++ b/spec/models/form/sales/questions/staircase_owned_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::StaircaseOwned, 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::StaircaseOwned, type: :model do expect(question.id).to eq("stairowned") end - it "has the correct header" do - expect(question.header).to eq("What percentage of the property does the buyer now own in total?") + context "when a joint purchase" do + let(:joint_purchase) { true } + + it "has the correct header" do + expect(question.header).to eq("What percentage of the property do the buyers now own in total?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Percentage the buyers now own in total") + end end - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Percentage the buyer now owns in total") + context "when not a joint purchase" do + it "has the correct header" do + expect(question.header).to eq("What percentage of the property does the buyer now own in total?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Percentage the buyer now owns in total") + end end it "has the correct type" do diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index ee9f624aa..ef85e5ed2 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -16,7 +16,8 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do %w[ living_before_purchase_shared_ownership staircasing - about_staircasing + about_staircasing_joint_purchase + about_staircasing_not_joint_purchase staircase_bought_value_check resale exchange_contracts