Browse Source

feat: conditional year behaviour and test

pull/1286/head
natdeanlewissoftwire 3 years ago
parent
commit
0f2ae232d3
  1. 10
      app/models/form/sales/pages/about_staircase.rb
  2. 20
      spec/models/form/sales/pages/about_staircase_spec.rb
  3. 53
      spec/models/form/sales/questions/staircase_sale_spec.rb

10
app/models/form/sales/pages/about_staircase.rb

@ -12,7 +12,13 @@ class Form::Sales::Pages::AboutStaircase < ::Form::Page
@questions ||= [
Form::Sales::Questions::StaircaseBought.new(nil, nil, self),
Form::Sales::Questions::StaircaseOwned.new(nil, nil, self),
Form::Sales::Questions::StaircaseSale.new(nil, nil, self),
]
staircase_sale_question,
].compact
end
def staircase_sale_question
if form.start_date.year >= 2023
Form::Sales::Questions::StaircaseSale.new(nil, nil, self)
end
end
end

20
spec/models/form/sales/pages/about_staircase_spec.rb

@ -11,8 +11,24 @@ RSpec.describe Form::Sales::Pages::AboutStaircase, type: :model do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned])
describe "questions" do
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned])
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned staircasesale])
end
end
end
it "has the correct id" do

53
spec/models/form/sales/questions/staircase_sale_spec.rb

@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::StaircaseSale, 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("staircasesale")
end
it "has the correct header" do
expect(question.header).to eq("Is this transaction part of a back-to-back staircasing transaction to facilitate sale of the home on the open market?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Part of a back-to-back staircasing transaction")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don't know" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
end
Loading…
Cancel
Save