Browse Source

Update discounted ownership guidance (#2582)

* Update discounted ownership guidance

* Add top guidance partial to outright sale

* Update outright sale guidance content

* Update model test
pull/2546/head
kosiakkatrina 2 years ago
parent
commit
1170be2748
  1. 2
      app/models/form/sales/pages/purchase_price_outright_ownership.rb
  2. 1
      app/models/form/sales/questions/mortgageused.rb
  3. 37
      app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb
  4. 15
      app/views/form/guidance/_financial_calculations_outright_sale.html.erb
  5. 2
      spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb
  6. 85
      spec/views/form/guidance/_financial_calculations_discounted_ownership_spec.rb
  7. 45
      spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb

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

@ -4,6 +4,8 @@ class Form::Sales::Pages::PurchasePriceOutrightOwnership < ::Form::Page
@depends_on = [ @depends_on = [
{ "outright_sale_or_discounted_with_full_ownership?" => true }, { "outright_sale_or_discounted_with_full_ownership?" => true },
] ]
@header = "About the price of the property"
@top_guidance_partial = "financial_calculations_outright_sale"
@ownershipsch = ownershipsch @ownershipsch = ownershipsch
end end

1
app/models/form/sales/questions/mortgageused.rb

@ -39,5 +39,6 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question
def top_guidance_partial def top_guidance_partial
return "financial_calculations_shared_ownership" if @ownershipsch == 1 return "financial_calculations_shared_ownership" if @ownershipsch == 1
return "financial_calculations_discounted_ownership" if @ownershipsch == 2 return "financial_calculations_discounted_ownership" if @ownershipsch == 2
return "financial_calculations_outright_sale" if @ownershipsch == 3
end end
end end

37
app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb

@ -2,19 +2,28 @@
<% grant_question_link = question_link("grant", log, current_user) %> <% grant_question_link = question_link("grant", log, current_user) %>
<% value_question_link = question_link("value", log, current_user) %> <% value_question_link = question_link("value", log, current_user) %>
<%= govuk_details(summary_text: "How the financial values are calculated") do %> <%= govuk_details(summary_text: "How the financial values are calculated") do %>
<p class="govuk-body"> <p class="govuk-body">
The mortgage amount <%= question_link("mortgage", log, current_user) %> <% if log.mortgage_used? || log.mortgageused.blank? %>
<% if grant_question_link.blank? %> <% mortgage_question_link = log.mortgageused.blank? ? question_link("mortgageused", log, current_user) : question_link("mortgage", log, current_user) %>
and cash deposit <%= question_link("deposit", log, current_user) %> The mortgage amount <%= mortgage_question_link %><% if grant_question_link.blank? %>
<% else %> and cash deposit <%= question_link("deposit", log, current_user) %>
cash deposit <%= question_link("deposit", log, current_user) %> <% else %>, cash deposit <%= question_link("deposit", log, current_user) %>
and grant <%= grant_question_link %> and grant <%= grant_question_link %>
<% end %> <% end %>
added together must equal added together must equal
the purchase price <%= value_question_link %> <% else %>
<% if discount_question_link.present? %> <% if grant_question_link.blank? %>
subtracted by the sum of the purchase price <%= value_question_link %> Cash deposit <%= question_link("deposit", log, current_user) %> must equal
multiplied by the discount <%= discount_question_link %> <% else %>
<% end %> Cash deposit <%= question_link("deposit", log, current_user) %>
and grant <%= grant_question_link %>
added together must equal
<% end %>
<% end %>
the purchase price <%= value_question_link %>
<% if discount_question_link.present? %>
subtracted by the sum of the purchase price <%= value_question_link %>
multiplied by the discount <%= discount_question_link %>
<% end %>
</p> </p>
<% end %> <% end %>

15
app/views/form/guidance/_financial_calculations_outright_sale.html.erb

@ -1,8 +1,13 @@
<%= govuk_details(summary_text: "How the financial values are calculated") do %> <%= govuk_details(summary_text: "How the financial values are calculated") do %>
<p class="govuk-body"> <p class="govuk-body">
The mortgage amount <%= question_link("mortgage", log, current_user) %> <% if log.mortgage_used? || log.mortgageused.blank? %>
and cash deposit <%= question_link("deposit", log, current_user) %> <% mortgage_question_link = log.mortgageused.blank? ? question_link("mortgageused", log, current_user) : question_link("mortgage", log, current_user) %>
added together must equal The mortgage amount <%= mortgage_question_link %>
the purchase price <%= question_link("value", log, current_user) %> and cash deposit <%= question_link("deposit", log, current_user) %>
</p> added together must equal
<% else %>
Cash deposit <%= question_link("deposit", log, current_user) %> must equal
<% end %>
the purchase price <%= question_link("value", log, current_user) %>
</p>
<% end %> <% end %>

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

@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Pages::PurchasePriceOutrightOwnership, type: :model
end end
it "has the correct header" do it "has the correct header" do
expect(page.header).to be_nil expect(page.header).to eq("About the price of the property")
end end
it "has the correct description" do it "has the correct description" do

85
spec/views/form/guidance/_financial_calculations_discounted_ownership_spec.rb

@ -0,0 +1,85 @@
require "rails_helper"
RSpec.describe "form/guidance/_financial_calculations_discounted_ownership.html.erb" do
let(:log) { create(:sales_log) }
let(:fragment) { Capybara::Node::Simple.new(rendered) }
context "when mortgage used is not answered" do
let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 9, mortgageused: nil, discount: 30) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("The mortgage amount")
expect(fragment).to have_content("and cash deposit")
expect(fragment).to have_content("added together must equal")
expect(fragment).to have_content("the purchase price")
expect(fragment).to have_content("subtracted by the sum of the purchase price")
expect(fragment).to have_content("multiplied by the discount")
end
end
context "when mortgage used is no" do
let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 9, mortgageused: 2, discount: nil) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("Cash deposit")
expect(fragment).to have_content("must equal")
expect(fragment).to have_content("the purchase price")
expect(fragment).to have_content("subtracted by the sum of the purchase price")
expect(fragment).to have_content("multiplied by the discount")
expect(fragment).not_to have_content("The mortgage amount")
expect(fragment).not_to have_content("added together must equal")
end
end
context "when mortgage used is yes" do
let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 9, mortgageused: 1, mortgage: nil, discount: 30) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("The mortgage amount")
expect(fragment).to have_content("and cash deposit")
expect(fragment).to have_content("added together must equal")
expect(fragment).to have_content("the purchase price")
expect(fragment).to have_content("subtracted by the sum of the purchase price")
expect(fragment).to have_content("multiplied by the discount")
end
end
context "when grant is routed to" do
context "and morgage used" do
let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 22, mortgageused: 1, mortgage: nil, discount: 30) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("The mortgage amount")
expect(fragment).to have_content("cash deposit")
expect(fragment).to have_content("and grant")
expect(fragment).to have_content("added together must equal")
expect(fragment).to have_content("the purchase price")
expect(fragment).not_to have_content("subtracted by the sum of the purchase price")
expect(fragment).not_to have_content("multiplied by the discount")
end
end
context "and morgage not used" do
let(:log) { create(:sales_log, :completed, ownershipsch: 2, type: 22, mortgageused: 2, grant: nil) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_discounted_ownership", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("Cash deposit")
expect(fragment).to have_content("and grant")
expect(fragment).to have_content("added together must equal")
expect(fragment).to have_content("the purchase price")
expect(fragment).not_to have_content("The mortgage amount")
expect(fragment).not_to have_content("subtracted by the sum of the purchase price")
expect(fragment).not_to have_content("multiplied by the discount")
end
end
end
end

45
spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb

@ -0,0 +1,45 @@
require "rails_helper"
RSpec.describe "form/guidance/_financial_calculations_outright_sale.html.erb" do
let(:log) { create(:sales_log) }
let(:fragment) { Capybara::Node::Simple.new(rendered) }
context "when mortgage used is not answered" do
let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: nil, discount: 30) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("The mortgage amount")
expect(fragment).to have_content("and cash deposit")
expect(fragment).to have_content("added together must equal")
expect(fragment).to have_content("the purchase price")
end
end
context "when mortgage used is no" do
let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: 2, discount: nil) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("Cash deposit")
expect(fragment).to have_content("must equal")
expect(fragment).to have_content("the purchase price")
expect(fragment).not_to have_content("The mortgage amount")
expect(fragment).not_to have_content("added together must equal")
end
end
context "when mortgage used is yes" do
let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: 1, mortgage: nil, discount: 30) }
it "renders correct content" do
render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to }
expect(fragment).to have_content("The mortgage amount")
expect(fragment).to have_content("and cash deposit")
expect(fragment).to have_content("added together must equal")
expect(fragment).to have_content("the purchase price")
end
end
end
Loading…
Cancel
Save