From 248afb8b8a9f6f73b86c2bfd9ec62ffd1183e0f6 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 5 Apr 2023 09:21:31 +0100 Subject: [PATCH] Add percentage discount form elements --- .../pages/percentage_discount_value_check.rb | 15 +++++ .../percentage_discount_value_check.rb | 23 ++++++++ .../discounted_ownership_scheme.rb | 1 + .../sales/subsections/property_information.rb | 1 + .../percentage_discount_value_check_spec.rb | 48 ++++++++++++++++ .../percentage_discount_value_check_spec.rb | 57 +++++++++++++++++++ .../discounted_ownership_scheme_spec.rb | 1 + .../subsections/property_information_spec.rb | 2 + 8 files changed, 148 insertions(+) create mode 100644 app/models/form/sales/pages/percentage_discount_value_check.rb create mode 100644 app/models/form/sales/questions/percentage_discount_value_check.rb create mode 100644 spec/models/form/sales/pages/percentage_discount_value_check_spec.rb create mode 100644 spec/models/form/sales/questions/percentage_discount_value_check_spec.rb diff --git a/app/models/form/sales/pages/percentage_discount_value_check.rb b/app/models/form/sales/pages/percentage_discount_value_check.rb new file mode 100644 index 000000000..1e3beb3e6 --- /dev/null +++ b/app/models/form/sales/pages/percentage_discount_value_check.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::PercentageDiscountValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @title_text = { + "translation" => "soft_validations.percentage_discount_value.title_text", + "arguments" => [{ "key" => "discount", "label" => true, "i18n_template" => "discount" }], + } + @informative_text = {} + @depends_on = [{ "percentage_discount_invalid?" => true }] + end + + def questions + @questions ||= [Form::Sales::Questions::PercentageDiscountValueCheck.new(nil, nil, self)] + end +end diff --git a/app/models/form/sales/questions/percentage_discount_value_check.rb b/app/models/form/sales/questions/percentage_discount_value_check.rb new file mode 100644 index 000000000..9ac5547b4 --- /dev/null +++ b/app/models/form/sales/questions/percentage_discount_value_check.rb @@ -0,0 +1,23 @@ +class Form::Sales::Questions::PercentageDiscountValueCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "percentage_discount_value_check" + @check_answer_label = "Percentage discount confirmation" + @header = "Are you sure this is correct?" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "percentage_discount_value_check" => 0, + }, + { + "percentage_discount_value_check" => 1, + }, + ], + } + end +end diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index 09813339d..52ee9e95c 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -11,6 +11,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self), + Form::Sales::Pages::PercentageDiscountValueCheck.new("percentage_discount_value_check", nil, self), Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), Form::Sales::Pages::GrantValueCheck.new(nil, nil, self), Form::Sales::Pages::PurchasePriceOutrightOwnership.new("purchase_price_discounted_ownership", nil, self, ownershipsch: 2), diff --git a/app/models/form/sales/subsections/property_information.rb b/app/models/form/sales/subsections/property_information.rb index cca34a764..95d8485c8 100644 --- a/app/models/form/sales/subsections/property_information.rb +++ b/app/models/form/sales/subsections/property_information.rb @@ -13,6 +13,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection Form::Sales::Pages::AboutPriceValueCheck.new("about_price_bedrooms_value_check", nil, self), Form::Sales::Pages::PropertyUnitType.new(nil, nil, self), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_property_type_value_check", nil, self), + Form::Sales::Pages::PercentageDiscountValueCheck.new("percentage_discount_proptype_value_check", nil, self), Form::Sales::Pages::PropertyBuildingType.new(nil, nil, self), postcode_and_la_questions, Form::Sales::Pages::AboutPriceValueCheck.new("about_price_la_value_check", nil, self), diff --git a/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb b/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb new file mode 100644 index 000000000..d933e3278 --- /dev/null +++ b/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PercentageDiscountValueCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { "percentage_discount_value_check" } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + 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[percentage_discount_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("percentage_discount_value_check") + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has the correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.percentage_discount_value.title_text", + "arguments" => [{ "key" => "discount", "label" => true, "i18n_template" => "discount" }], + }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq({}) + end + + it "is interruption screen page" do + expect(page.interruption_screen?).to eq(true) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "percentage_discount_invalid?" => true, + }, + ]) + end +end diff --git a/spec/models/form/sales/questions/percentage_discount_value_check_spec.rb b/spec/models/form/sales/questions/percentage_discount_value_check_spec.rb new file mode 100644 index 000000000..72f4f0cbb --- /dev/null +++ b/spec/models/form/sales/questions/percentage_discount_value_check_spec.rb @@ -0,0 +1,57 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PercentageDiscountValueCheck, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("percentage_discount_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure this is correct?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Percentage discount confirmation") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq({ + "depends_on" => [ + { + "percentage_discount_value_check" => 0, + }, + { + "percentage_discount_value_check" => 1, + }, + ], + }) + end +end diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb index 5c0dbfea0..9aa0aa102 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -17,6 +17,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model living_before_purchase_discounted_ownership about_price_rtb extra_borrowing_price_value_check + percentage_discount_value_check about_price_not_rtb grant_value_check purchase_price_discounted_ownership diff --git a/spec/models/form/sales/subsections/property_information_spec.rb b/spec/models/form/sales/subsections/property_information_spec.rb index 1c049ea97..7a0c57448 100644 --- a/spec/models/form/sales/subsections/property_information_spec.rb +++ b/spec/models/form/sales/subsections/property_information_spec.rb @@ -24,6 +24,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do about_price_bedrooms_value_check property_unit_type monthly_charges_property_type_value_check + percentage_discount_proptype_value_check property_building_type property_postcode property_local_authority @@ -49,6 +50,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do about_price_bedrooms_value_check property_unit_type monthly_charges_property_type_value_check + percentage_discount_proptype_value_check property_building_type about_price_la_value_check property_wheelchair_accessible