7 changed files with 176 additions and 0 deletions
@ -0,0 +1,21 @@
|
||||
class Form::Sales::Pages::Buyer1GenderSameAsSex < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "buyer_1_gender_same_as_sex" |
||||
@depends_on = [ |
||||
{ |
||||
"buyer_has_seen_privacy_notice?" => true, |
||||
}, |
||||
{ |
||||
"buyer_not_interviewed?" => true, |
||||
}, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::GenderSameAsSex1.new(nil, nil, self), |
||||
Form::Sales::Questions::GenderDescription1.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
||||
@ -0,0 +1,23 @@
|
||||
class Form::Sales::Pages::Buyer2GenderSameAsSex < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "buyer_2_gender_same_as_sex" |
||||
@depends_on = [ |
||||
{ |
||||
"joint_purchase?" => true, |
||||
"buyer_has_seen_privacy_notice?" => true, |
||||
}, |
||||
{ |
||||
"joint_purchase?" => true, |
||||
"buyer_not_interviewed?" => true, |
||||
}, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::GenderSameAsSex2.new(nil, nil, self), |
||||
Form::Sales::Questions::GenderDescription2.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
||||
@ -0,0 +1,15 @@
|
||||
class Form::Sales::Questions::GenderDescription1 < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "gender_description1" |
||||
@type = "text" |
||||
@check_answers_card_number = 1 |
||||
@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 = { 2026 => 0 }.freeze |
||||
|
||||
def derived?(log) |
||||
log.gender_same_as_sex1 != 2 |
||||
end |
||||
end |
||||
@ -0,0 +1,15 @@
|
||||
class Form::Sales::Questions::GenderDescription2 < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "gender_description2" |
||||
@type = "text" |
||||
@check_answers_card_number = 2 |
||||
@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 = { 2026 => 0 }.freeze |
||||
|
||||
def derived?(log) |
||||
log.gender_same_as_sex2 != 2 |
||||
end |
||||
end |
||||
@ -0,0 +1,32 @@
|
||||
class Form::Sales::Questions::GenderSameAsSex1 < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "gender_same_as_sex1" |
||||
@type = "radio" |
||||
@check_answers_card_number = 1 |
||||
@conditional_for = { "gender_description1" => [2] } |
||||
@inferred_check_answers_value = [{ "condition" => { "gender_same_as_sex1" => 2 }, "value" => "No" }] |
||||
@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" }, |
||||
"2" => { "value" => "No, enter gender identity" }, |
||||
"divider" => { "value" => true }, |
||||
"3" => { "value" => "Buyer prefers not to say" }, |
||||
}.freeze |
||||
|
||||
def answer_options |
||||
ANSWER_OPTIONS |
||||
end |
||||
|
||||
QUESTION_NUMBER_FROM_YEAR = { 2026 => 0 }.freeze |
||||
|
||||
def label_from_value(value, _log = nil, _user = nil) |
||||
return unless value |
||||
|
||||
return "Prefers not to say" if value == 3 |
||||
|
||||
super |
||||
end |
||||
end |
||||
@ -0,0 +1,32 @@
|
||||
class Form::Sales::Questions::GenderSameAsSex2 < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "gender_same_as_sex2" |
||||
@type = "radio" |
||||
@check_answers_card_number = 2 |
||||
@conditional_for = { "gender_description2" => [2] } |
||||
@inferred_check_answers_value = [{ "condition" => { "gender_same_as_sex2" => 2 }, "value" => "No" }] |
||||
@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" }, |
||||
"2" => { "value" => "No, enter gender identity" }, |
||||
"divider" => { "value" => true }, |
||||
"3" => { "value" => "Buyer prefers not to say" }, |
||||
}.freeze |
||||
|
||||
def answer_options |
||||
ANSWER_OPTIONS |
||||
end |
||||
|
||||
QUESTION_NUMBER_FROM_YEAR = { 2026 => 0 }.freeze |
||||
|
||||
def label_from_value(value, _log = nil, _user = nil) |
||||
return unless value |
||||
|
||||
return "Prefers not to say" if value == 3 |
||||
|
||||
super |
||||
end |
||||
end |
||||
@ -0,0 +1,38 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Buyer2GenderSameAsSex, 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(2026, 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[gender_same_as_sex2 gender_description2]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("buyer_2_gender_same_as_sex") |
||||
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 eq([ |
||||
{ |
||||
"joint_purchase?" => true, |
||||
"buyer_has_seen_privacy_notice?" => true, |
||||
}, |
||||
{ |
||||
"joint_purchase?" => true, |
||||
"buyer_not_interviewed?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
end |
||||
Loading…
Reference in new issue