kosiakkatrina
6 days ago
committed by
GitHub
7 changed files with 335 additions and 21 deletions
@ -0,0 +1,12 @@
|
||||
class Form::Lettings::Pages::PersonLeadPartner < ::Form::Page |
||||
def initialize(id, hsh, subsection, person_index:) |
||||
super(id, hsh, subsection) |
||||
@id = "person_#{person_index}_lead_partner" |
||||
@depends_on = [{ "details_known_#{person_index}" => 0 }] |
||||
@person_index = person_index |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [Form::Lettings::Questions::PersonPartner.new(nil, nil, self, person_index: @person_index)] |
||||
end |
||||
end |
@ -0,0 +1,30 @@
|
||||
class Form::Lettings::Questions::PersonPartner < ::Form::Question |
||||
def initialize(id, hsh, page, person_index:) |
||||
super(id, hsh, page) |
||||
@id = "relat#{person_index}" |
||||
@type = "radio" |
||||
@check_answers_card_number = person_index |
||||
@answer_options = answer_options |
||||
@person_index = person_index |
||||
@question_number = question_number |
||||
end |
||||
|
||||
def answer_options |
||||
{ |
||||
"P" => { "value" => "Yes" }, |
||||
"X" => { "value" => "No" }, |
||||
"R" => { "value" => "Tenant prefers not to say" }, |
||||
} |
||||
end |
||||
|
||||
def question_number |
||||
base_question_number = case form.start_date.year |
||||
when 2023 |
||||
30 |
||||
else |
||||
29 |
||||
end |
||||
|
||||
base_question_number + (4 * @person_index) |
||||
end |
||||
end |
@ -0,0 +1,51 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do |
||||
subject(:page) { described_class.new(nil, page_definition, subsection, person_index:) } |
||||
|
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: true)) } |
||||
let(:person_index) { 2 } |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be nil |
||||
end |
||||
|
||||
context "with person 2" do |
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[relat2]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("person_2_lead_partner") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq( |
||||
[{ "details_known_2" => 0 }], |
||||
) |
||||
end |
||||
end |
||||
|
||||
context "with person 3" do |
||||
let(:person_index) { 3 } |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[relat3]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("person_3_lead_partner") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq( |
||||
[{ "details_known_3" => 0 }], |
||||
) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,57 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do |
||||
subject(:question) { described_class.new(nil, question_definition, page, person_index:) } |
||||
|
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 4), start_year_2025_or_later?: true))) } |
||||
let(:person_index) { 2 } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
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("P" => { "value" => "Yes" }, |
||||
"X" => { "value" => "No" }, |
||||
"R" => { "value" => "Tenant prefers not to say" }) |
||||
end |
||||
|
||||
it "has correct conditional for" do |
||||
expect(question.conditional_for).to be nil |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to be nil |
||||
end |
||||
|
||||
context "with person 2" do |
||||
it "has the correct id" do |
||||
expect(question.id).to eq("relat2") |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to eq(2) |
||||
end |
||||
end |
||||
|
||||
context "with person 3" do |
||||
let(:person_index) { 3 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("relat3") |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to eq(3) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue