Browse Source

CLDC-2075: Page and questions tests for each for all 3 questions

pull/1707/head
Aaron Spencer 3 years ago
parent
commit
3c21ef3df5
  1. 8
      app/models/form/sales/pages/shared_ownership_type.rb
  2. 25
      spec/models/form/sales/pages/discounted_ownership_type_spec.rb
  3. 25
      spec/models/form/sales/pages/outright_ownership_type_spec.rb
  4. 26
      spec/models/form/sales/pages/shared_ownership_type_spec.rb
  5. 27
      spec/models/form/sales/questions/discounted_ownership_type_spec.rb
  6. 37
      spec/models/form/sales/questions/outright_ownership_type_spec.rb
  7. 8
      spec/models/form/sales/questions/shared_ownership_type_spec.rb

8
app/models/form/sales/pages/shared_ownership_type.rb

@ -8,13 +8,13 @@ class Form::Sales::Pages::SharedOwnershipType < ::Form::Page
}] }]
end end
def header
"Shared ownership type" if form.start_date.year >= 2023
end
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::SharedOwnershipType.new(nil, nil, self), Form::Sales::Questions::SharedOwnershipType.new(nil, nil, self),
] ]
end end
def header
"Shared ownership type" if form.start_date.year >= 2023
end
end end

25
spec/models/form/sales/pages/discounted_ownership_type_spec.rb

@ -5,7 +5,26 @@ RSpec.describe Form::Sales::Pages::DiscountedOwnershipType, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:start_date) { Time.zone.today }
describe "headers" do
context "when form year is for 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has the correct header" do
expect(page.header).to eq("Discounted ownership type")
end
end
context "when form year is for before 2023" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "does not have a page header" do
expect(page.header).to eq(nil)
end
end
end
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
@ -19,10 +38,6 @@ RSpec.describe Form::Sales::Pages::DiscountedOwnershipType, type: :model do
expect(page.id).to eq("discounted_ownership_type") expect(page.id).to eq("discounted_ownership_type")
end end
it "has the correct header" do
expect(page.header).to eq("Discounted ownership type")
end
it "has the correct description" do it "has the correct description" do
expect(page.description).to be_nil expect(page.description).to be_nil
end end

25
spec/models/form/sales/pages/outright_ownership_type_spec.rb

@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::OutrightOwnershipType, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:start_date) { Time.zone.today }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
@ -19,10 +20,6 @@ RSpec.describe Form::Sales::Pages::OutrightOwnershipType, type: :model do
expect(page.id).to eq("outright_ownership_type") expect(page.id).to eq("outright_ownership_type")
end end
it "has the correct header" do
expect(page.header).to eq("Outright ownership type")
end
it "has the correct description" do it "has the correct description" do
expect(page.description).to be_nil expect(page.description).to be_nil
end end
@ -32,4 +29,22 @@ RSpec.describe Form::Sales::Pages::OutrightOwnershipType, type: :model do
"ownershipsch" => 3, "ownershipsch" => 3,
}]) }])
end end
describe "headers" do
context "when the form year is 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has the correct header" do
expect(page.header).to eq("Outright ownership type")
end
end
context "when the form is before the year 2023" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "does not have a page header" do
expect(page.header).to eq(nil)
end
end
end
end end

26
spec/models/form/sales/pages/shared_ownership_type_spec.rb

@ -1,14 +1,30 @@
require "rails_helper" require "rails_hel\per"
RSpec.describe Form::Sales::Pages::SharedOwnershipType, type: :model do RSpec.describe Form::Sales::Pages::SharedOwnershipType, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:start_date) { Time.utc(2022, 4, 1) } let(:start_date) { Time.utc(2022, 4, 1) }
let(:form) { instance_double(Form, start_date:) }
let(:subsection) { instance_double(Form::Subsection, form:) }
describe "headers" do
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has the correct header" do
expect(page.header).to eq("Shared ownership type")
end
end
context "when before 2023" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has the correct header" do
expect(page.header).to eq(nil)
end
end
end
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end end
@ -21,10 +37,6 @@ RSpec.describe Form::Sales::Pages::SharedOwnershipType, type: :model do
expect(page.id).to eq("shared_ownership_type") expect(page.id).to eq("shared_ownership_type")
end end
it "has the correct header" do
expect(page.header).to eq("Shared Ownership")
end
it "has the correct description" do it "has the correct description" do
expect(page.description).to be_nil expect(page.description).to be_nil
end end

27
spec/models/form/sales/questions/discounted_ownership_type_spec.rb

@ -5,7 +5,9 @@ RSpec.describe Form::Sales::Questions::DiscountedOwnershipType, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page, subsection:) }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:start_date) { Time.zone.today }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -42,4 +44,27 @@ RSpec.describe Form::Sales::Questions::DiscountedOwnershipType, type: :model do
"22" => { "value" => "Any other equity loan scheme" }, "22" => { "value" => "Any other equity loan scheme" },
}) })
end end
describe "partial guidance" do
context "when the form is for 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "shows shows correct guidance_partial" do
expect(question.guidance_partial).to eq("discounted_ownership_type_definitions")
end
it "is at the top" do
expect(question.top_guidance?).to eq(true)
expect(question.bottom_guidance?).to eq(false)
end
end
context "when the form is for before 2023" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "does not show a guidance_partial" do
expect(question.guidance_partial).to eq(nil)
end
end
end
end end

37
spec/models/form/sales/questions/outright_ownership_type_spec.rb

@ -5,7 +5,9 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page, subsection:) }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
let(:start_date) { Time.zone.today }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -15,10 +17,6 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do
expect(question.id).to eq("type") expect(question.id).to eq("type")
end end
it "has the correct header" do
expect(question.header).to eq("What is the type of outright sale?")
end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Type of outright sale") expect(question.check_answer_label).to eq("Type of outright sale")
end end
@ -43,4 +41,33 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do
"othtype" => [12], "othtype" => [12],
}) })
end end
it "has the correct header" do
expect(question.header).to eq("What is the type of outright sale?")
end
describe "partial guidance" do
context "when the form is for year 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has the correct guidance_partial" do
expect(question.guidance_partial).to eq("outright_sale_type_definitions")
end
it "is at the top" do
expect(question.top_guidance?).to eq(true)
expect(question.bottom_guidance?).to eq(false)
end
end
context "when the form is for before year 2023" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "does not display a guidance partial" do
expect(question.guidance_partial).to eq(nil);
end
end
end
end end

8
spec/models/form/sales/questions/shared_ownership_type_spec.rb

@ -50,6 +50,10 @@ RSpec.describe Form::Sales::Questions::SharedOwnershipType, type: :model do
"30" => { "value" => "Shared Ownership - 2021 model lease" }, "30" => { "value" => "Shared Ownership - 2021 model lease" },
}) })
end end
it "does not show a guidance_partial" do
expect(question.guidance_partial).to eq(nil)
end
end end
context "when form start date is 2023" do context "when form start date is 2023" do
@ -67,5 +71,9 @@ RSpec.describe Form::Sales::Questions::SharedOwnershipType, type: :model do
"32" => { "value" => "London Living Rent — Shared Ownership" }, "32" => { "value" => "London Living Rent — Shared Ownership" },
}) })
end end
it "shows shows correct guidance_partial" do
expect(question.guidance_partial).to eq("shared_ownership_type_definitions")
end
end end
end end

Loading…
Cancel
Save