Browse Source
* use separate question text for shared and discounted mscharge from 2025 * refactor and rename copy variables * Revert "refactor and rename copy variables" This reverts commitpull/3026/head v0.5.62d7eadef5a
. * separate out shared ownership leasehold charge into separate service charge question * Revert "separate out shared ownership leasehold charge into separate service charge question" This reverts commit13a930dcb6
. * separate out shared ownership leasehold charge into separate question but same variable --------- Co-authored-by: Carolyn <carolyn.barker@softwire.com>
11 changed files with 192 additions and 9 deletions
@ -0,0 +1,13 @@ |
|||||||
|
class Form::Sales::Pages::ServiceCharge < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@copy_key = "sales.sale_information.servicecharges" |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [ |
||||||
|
Form::Sales::Questions::HasServiceCharge.new(nil, nil, self), |
||||||
|
Form::Sales::Questions::ServiceCharge.new(nil, nil, self), |
||||||
|
] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,27 @@ |
|||||||
|
class Form::Sales::Questions::HasServiceCharge < ::Form::Question |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "has_mscharge" |
||||||
|
@type = "radio" |
||||||
|
@answer_options = ANSWER_OPTIONS |
||||||
|
@conditional_for = { |
||||||
|
"mscharge" => [1], |
||||||
|
} |
||||||
|
@hidden_in_check_answers = { |
||||||
|
"depends_on" => [ |
||||||
|
{ |
||||||
|
"has_mscharge" => 1, |
||||||
|
}, |
||||||
|
], |
||||||
|
} |
||||||
|
@copy_key = "sales.sale_information.servicecharges.has_servicecharge" |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
ANSWER_OPTIONS = { |
||||||
|
"1" => { "value" => "Yes" }, |
||||||
|
"0" => { "value" => "No" }, |
||||||
|
}.freeze |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze |
||||||
|
end |
@ -0,0 +1,15 @@ |
|||||||
|
class Form::Sales::Questions::ServiceCharge < ::Form::Question |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "mscharge" |
||||||
|
@type = "numeric" |
||||||
|
@min = 1 |
||||||
|
@step = 0.01 |
||||||
|
@width = 5 |
||||||
|
@prefix = "£" |
||||||
|
@copy_key = "sales.sale_information.servicecharges.servicecharge" |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze |
||||||
|
end |
@ -0,0 +1,29 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Form::Sales::Pages::ServiceCharge, 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[has_mscharge mscharge]) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct id" do |
||||||
|
expect(page.id).to eq(nil) |
||||||
|
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 |
@ -0,0 +1,49 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Form::Sales::Questions::HasServiceCharge, type: :model do |
||||||
|
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||||
|
|
||||||
|
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 4)) } |
||||||
|
let(:question_id) { nil } |
||||||
|
let(:question_definition) { nil } |
||||||
|
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership", form:)) } |
||||||
|
|
||||||
|
it "has correct page" do |
||||||
|
expect(question.page).to eq(page) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct id" do |
||||||
|
expect(question.id).to eq("has_mscharge") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct type" do |
||||||
|
expect(question.type).to eq("radio") |
||||||
|
end |
||||||
|
|
||||||
|
it "is not marked as derived" do |
||||||
|
expect(question.derived?(nil)).to be false |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct answer_options" do |
||||||
|
expect(question.answer_options).to eq({ |
||||||
|
"0" => { "value" => "No" }, |
||||||
|
"1" => { "value" => "Yes" }, |
||||||
|
}) |
||||||
|
end |
||||||
|
|
||||||
|
it "has correct conditional for" do |
||||||
|
expect(question.conditional_for).to eq({ |
||||||
|
"mscharge" => [1], |
||||||
|
}) |
||||||
|
end |
||||||
|
|
||||||
|
it "has correct hidden_in_check_answers for" do |
||||||
|
expect(question.hidden_in_check_answers).to eq({ |
||||||
|
"depends_on" => [ |
||||||
|
{ |
||||||
|
"has_mscharge" => 1, |
||||||
|
}, |
||||||
|
], |
||||||
|
}) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,37 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Form::Sales::Questions::ServiceCharge, 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, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } |
||||||
|
|
||||||
|
it "has correct page" do |
||||||
|
expect(question.page).to eq(page) |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct id" do |
||||||
|
expect(question.id).to eq("mscharge") |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct type" do |
||||||
|
expect(question.type).to eq("numeric") |
||||||
|
end |
||||||
|
|
||||||
|
it "is not marked as derived" do |
||||||
|
expect(question.derived?(nil)).to be false |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct width" do |
||||||
|
expect(question.width).to be 5 |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct min" do |
||||||
|
expect(question.min).to be 1 |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct prefix" do |
||||||
|
expect(question.prefix).to eq("£") |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue