Browse Source
* Split questions * Update the error message * Add guidance * Add back the headers * Refactor depends_on * Refactor furtherpull/2582/head
26 changed files with 371 additions and 142 deletions
@ -1,26 +0,0 @@
|
||||
class Form::Sales::Pages::AboutDepositWithoutDiscount < ::Form::Page |
||||
def initialize(id, hsh, subsection, ownershipsch:, optional:) |
||||
super(id, hsh, subsection) |
||||
@header = "About the deposit" |
||||
@ownershipsch = ownershipsch |
||||
@optional = optional |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch, optional: @optional), |
||||
] |
||||
end |
||||
|
||||
def depends_on |
||||
if form.start_year_after_2024? |
||||
[{ "social_homebuy?" => false, "ownershipsch" => 1, "stairowned_100?" => @optional }, |
||||
{ "ownershipsch" => 2 }, |
||||
{ "ownershipsch" => 3, "mortgageused" => 1 }] |
||||
else |
||||
[{ "social_homebuy?" => false, "ownershipsch" => 1 }, |
||||
{ "ownershipsch" => 2 }, |
||||
{ "ownershipsch" => 3, "mortgageused" => 1 }] |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,21 @@
|
||||
class Form::Sales::Pages::Deposit < ::Form::Page |
||||
def initialize(id, hsh, subsection, ownershipsch:, optional:) |
||||
super(id, hsh, subsection) |
||||
@ownershipsch = ownershipsch |
||||
@optional = optional |
||||
@header = "About the deposit" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch, optional: @optional), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(log, _user) |
||||
return true if log.ownershipsch == 2 || (log.ownershipsch == 3 && log.mortgageused == 1) |
||||
return false if log.stairowned_100? != @optional && form.start_year_after_2024? |
||||
|
||||
log.ownershipsch == 1 |
||||
end |
||||
end |
||||
@ -1,13 +1,12 @@
|
||||
class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page |
||||
class Form::Sales::Pages::Discount < ::Form::Page |
||||
def initialize(id, hsh, subsection, optional:) |
||||
super(id, hsh, subsection) |
||||
@header = "About the deposit" |
||||
@optional = optional |
||||
@header = "About the deposit" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1, optional: @optional), |
||||
Form::Sales::Questions::DepositDiscount.new(nil, nil, self), |
||||
] |
||||
end |
||||
@ -1,13 +1,12 @@
|
||||
class Form::Sales::Pages::AboutPriceSharedOwnership < ::Form::Page |
||||
class Form::Sales::Pages::Equity < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "about_price_shared_ownership" |
||||
@id = "equity" |
||||
@header = "About the price of the property" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::Value.new(nil, nil, self), |
||||
Form::Sales::Questions::Equity.new(nil, nil, self), |
||||
] |
||||
end |
||||
@ -0,0 +1,13 @@
|
||||
class Form::Sales::Pages::ValueSharedOwnership < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "value_shared_ownership" |
||||
@header = "About the price of the property" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::Value.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
||||
@ -0,0 +1,10 @@
|
||||
<%= govuk_details(summary_text: "How the financial values are calculated’") do %> |
||||
<p class="govuk-body"> |
||||
The mortgage amount (<%= govuk_link_to "Q92", send("#{log.class.name.underscore}_#{log.form.get_question('mortgage', log).page.id}_path", log) %>), |
||||
cash deposit (<%= govuk_link_to "Q95", send("#{log.class.name.underscore}_#{log.form.get_question('deposit', log).page.id}_path", log) %>) |
||||
and cash discount (<%= govuk_link_to "Q97", send("#{log.class.name.underscore}_#{log.form.get_question('cashdis', log).page.id}_path", log) %>) |
||||
added together must equal |
||||
the purchase price (<%= govuk_link_to "Q88", send("#{log.class.name.underscore}_#{log.form.get_question('value', log).page.id}_path", log) %>) |
||||
multiplied by the percentage equity stake (<%= govuk_link_to "Q89", send("#{log.class.name.underscore}_#{log.form.get_question('equity', log).page.id}_path", log) %>) |
||||
</p> |
||||
<% end %> |
||||
@ -1,79 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::AboutDepositWithoutDiscount, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: false) } |
||||
|
||||
let(:page_id) { nil } |
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
|
||||
before do |
||||
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1))) |
||||
end |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[deposit]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("About the deposit") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq( |
||||
[{ "social_homebuy?" => false, "ownershipsch" => 1 }, |
||||
{ "ownershipsch" => 2 }, |
||||
{ "ownershipsch" => 3, "mortgageused" => 1 }], |
||||
) |
||||
end |
||||
|
||||
context "when optional is true" do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: true) } |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq( |
||||
[{ "social_homebuy?" => false, "ownershipsch" => 1 }, |
||||
{ "ownershipsch" => 2 }, |
||||
{ "ownershipsch" => 3, "mortgageused" => 1 }], |
||||
) |
||||
end |
||||
end |
||||
|
||||
context "when it's a 2024 form" do |
||||
before do |
||||
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: true, start_date: Time.zone.local(2024, 4, 1))) |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq( |
||||
[{ "social_homebuy?" => false, "ownershipsch" => 1, "stairowned_100?" => false }, |
||||
{ "ownershipsch" => 2 }, |
||||
{ "ownershipsch" => 3, "mortgageused" => 1 }], |
||||
) |
||||
end |
||||
|
||||
context "and optional is true" do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: true) } |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq( |
||||
[{ "social_homebuy?" => false, "ownershipsch" => 1, "stairowned_100?" => true }, |
||||
{ "ownershipsch" => 2 }, |
||||
{ "ownershipsch" => 3, "mortgageused" => 1 }], |
||||
) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,235 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Deposit, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional:) } |
||||
|
||||
let(:page_id) { nil } |
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection, enabled?: true) } |
||||
let(:form) { instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1)) } |
||||
let(:optional) { false } |
||||
|
||||
before do |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[deposit]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("About the deposit") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be_nil |
||||
end |
||||
|
||||
context "when routing with start year after 2024" do |
||||
before do |
||||
allow(form).to receive(:start_year_after_2024?).and_return(true) |
||||
end |
||||
|
||||
context "and optional is false" do |
||||
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, not social homembuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } |
||||
|
||||
it "does not route to the page" do |
||||
expect(page).not_to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } |
||||
|
||||
it "does not route to the page" do |
||||
expect(page).not_to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is discounted ownership" do |
||||
let(:log) { build(:sales_log, ownershipsch: 2, type: 18) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is outright ownership and mortgage used is yes" do |
||||
let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 1) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and ownership is outright sale and mortgage used is not yes" do |
||||
let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 2) } |
||||
|
||||
it "doesn't route to the page" do |
||||
expect(page).not_to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "and optional is true" do |
||||
let(:optional) { true } |
||||
|
||||
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } |
||||
|
||||
it "does not route to the page" do |
||||
expect(page).not_to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, not social homembuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } |
||||
|
||||
it "does not route to the page" do |
||||
expect(page).not_to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when routing with start year before 2024" do |
||||
before do |
||||
allow(form).to receive(:start_year_after_2024?).and_return(false) |
||||
end |
||||
|
||||
context "and optional is false" do |
||||
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, not social homembuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is discounted ownership" do |
||||
let(:log) { build(:sales_log, ownershipsch: 2, type: 18) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is outright ownership and mortgage used is yes" do |
||||
let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 1) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and ownership is outright sale and mortgage used is not yes" do |
||||
let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 2) } |
||||
|
||||
it "doesn't route to the page" do |
||||
expect(page).not_to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "and optional is true" do |
||||
let(:optional) { true } |
||||
|
||||
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) } |
||||
|
||||
it "does routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, not social homembuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is not 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) } |
||||
|
||||
it "does routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
|
||||
context "and the log is shared ownership, social homebuy and stairowned is 100" do |
||||
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) } |
||||
|
||||
it "routes to the page" do |
||||
expect(page).to be_routed_to(log, nil) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,33 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::ValueSharedOwnership, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection) } |
||||
|
||||
let(:page_id) { nil } |
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[value]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("value_shared_ownership") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("About the price of the property") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to be_nil |
||||
end |
||||
end |
||||
Loading…
Reference in new issue