9 changed files with 620 additions and 0 deletions
@ -0,0 +1,29 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Buyer1GenderSameAsSex, 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_sex1 gender_description1]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("buyer_1_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([{ "buyer_has_seen_privacy_notice?" => true }, { "buyer_not_interviewed?" => true }]) |
||||
end |
||||
end |
||||
@ -0,0 +1,103 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::PersonGenderSameAsSex, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } |
||||
|
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2026, 4, 1))) } |
||||
let(:person_index) { 2 } |
||||
let(:page_id) { "person_2_gender_same_as_sex" } |
||||
|
||||
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 |
||||
let(:person_index) { 2 } |
||||
let(:page_id) { "person_2_gender_same_as_sex" } |
||||
|
||||
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("person_2_gender_same_as_sex") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "details_known_2" => 1 }]) |
||||
end |
||||
end |
||||
|
||||
context "with person 3" do |
||||
let(:person_index) { 3 } |
||||
let(:page_id) { "person_3_gender_same_as_sex" } |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex3 gender_description3]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("person_3_gender_same_as_sex") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "details_known_3" => 1 }]) |
||||
end |
||||
end |
||||
|
||||
context "with person 4" do |
||||
let(:person_index) { 4 } |
||||
let(:page_id) { "person_4_gender_same_as_sex" } |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex4 gender_description4]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("person_4_gender_same_as_sex") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "details_known_4" => 1 }]) |
||||
end |
||||
end |
||||
|
||||
context "with person 5" do |
||||
let(:person_index) { 5 } |
||||
let(:page_id) { "person_5_gender_same_as_sex" } |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex5 gender_description5]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("person_5_gender_same_as_sex") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "details_known_5" => 1 }]) |
||||
end |
||||
end |
||||
|
||||
context "with person 6" do |
||||
let(:person_index) { 6 } |
||||
let(:page_id) { "person_6_gender_same_as_sex" } |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex6 gender_description6]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("person_6_gender_same_as_sex") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "details_known_6" => 1 }]) |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,52 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::GenderDescription2, 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) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } |
||||
|
||||
before do |
||||
allow(page).to receive(:subsection).and_return(subsection) |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description2") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(2) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
context "when gender_same_as_sex2 is 'Yes'" do |
||||
let(:log) { build(:sales_log, gender_same_as_sex2: 1) } |
||||
|
||||
it "is marked as derived" do |
||||
expect(question.derived?(log)).to be true |
||||
end |
||||
end |
||||
|
||||
context "when gender_same_as_sex2 is 'No'" do |
||||
let(:log) { build(:sales_log, gender_same_as_sex2: 2) } |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?(log)).to be false |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,60 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::GenderDescription1, 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) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } |
||||
|
||||
before do |
||||
allow(page).to receive(:subsection).and_return(subsection) |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description1") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(1) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
context "when gender_same_as_sex1 is 'Yes'" do |
||||
let(:log) { build(:sales_log, gender_same_as_sex1: 1) } |
||||
|
||||
it "is marked as derived" do |
||||
expect(question.derived?(log)).to be true |
||||
end |
||||
end |
||||
|
||||
context "when gender_same_as_sex1 is 'No'" do |
||||
let(:log) { build(:sales_log, gender_same_as_sex1: 2) } |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?(log)).to be false |
||||
end |
||||
end |
||||
|
||||
context "when gender_same_as_sex1 is 'Prefers not to say'" do |
||||
let(:log) { build(:sales_log, gender_same_as_sex1: 3) } |
||||
|
||||
it "is marked as derived" do |
||||
expect(question.derived?(log)).to be true |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,57 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::GenderSameAsSex2, 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) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } |
||||
|
||||
before do |
||||
allow(page).to receive(:subsection).and_return(subsection) |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex2") |
||||
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 expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(2) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description2" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex2" => 2 }, "value" => "No" }]) |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No, enter gender identity" }, |
||||
"divider" => { "value" => true }, |
||||
"3" => { "value" => "Buyer prefers not to say" }, |
||||
}) |
||||
end |
||||
|
||||
it "returns correct label_from_value for 'Prefers not to say'" do |
||||
expect(question.label_from_value(3)).to eq("Prefers not to say") |
||||
end |
||||
end |
||||
@ -0,0 +1,65 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::GenderSameAsSex1, 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) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } |
||||
|
||||
before do |
||||
allow(page).to receive(:subsection).and_return(subsection) |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex1") |
||||
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 expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(1) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description1" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex1" => 2 }, "value" => "No" }]) |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No, enter gender identity" }, |
||||
"divider" => { "value" => true }, |
||||
"3" => { "value" => "Buyer prefers not to say" }, |
||||
}) |
||||
end |
||||
|
||||
it "returns correct label_from_value for 'No'" do |
||||
expect(question.label_from_value(2)).to eq("No, enter gender identity") |
||||
end |
||||
|
||||
it "returns correct label_from_value for 'Prefers not to say'" do |
||||
expect(question.label_from_value(3)).to eq("Prefers not to say") |
||||
end |
||||
|
||||
it "returns nil label_from_value for nil" do |
||||
expect(question.label_from_value(nil)).to be_nil |
||||
end |
||||
end |
||||
@ -0,0 +1,105 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::PersonGenderDescription, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:person_index) { 2 } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } |
||||
|
||||
before do |
||||
allow(page).to receive(:subsection).and_return(subsection) |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
context "when person 2" do |
||||
let(:person_index) { 2 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description2") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(2) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
end |
||||
|
||||
context "when person 3" do |
||||
let(:person_index) { 3 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description3") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(3) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
end |
||||
|
||||
context "when person 4" do |
||||
let(:person_index) { 4 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description4") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(4) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
end |
||||
|
||||
context "when person 5" do |
||||
let(:person_index) { 5 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description5") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(5) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
end |
||||
|
||||
context "when person 6" do |
||||
let(:person_index) { 6 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_description6") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(6) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,142 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::PersonGenderSameAsSex, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:person_index) { 2 } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } |
||||
|
||||
before do |
||||
allow(page).to receive(:subsection).and_return(subsection) |
||||
allow(subsection).to receive(:form).and_return(form) |
||||
end |
||||
|
||||
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({ |
||||
"1" => { "value" => "Yes" }, |
||||
"2" => { "value" => "No, enter gender identity" }, |
||||
"divider" => { "value" => true }, |
||||
"3" => { "value" => "Person prefers not to say" }, |
||||
}) |
||||
end |
||||
|
||||
it "returns correct label_from_value for 'Prefers not to say'" do |
||||
expect(question.label_from_value(3)).to eq("Prefers not to say") |
||||
end |
||||
|
||||
context "when person 2" do |
||||
let(:person_index) { 2 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex2") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(2) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description2" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex2" => 2 }, "value" => "No" }]) |
||||
end |
||||
end |
||||
|
||||
context "when person 3" do |
||||
let(:person_index) { 3 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex3") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(3) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description3" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex3" => 2 }, "value" => "No" }]) |
||||
end |
||||
end |
||||
|
||||
context "when person 4" do |
||||
let(:person_index) { 4 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex4") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(4) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description4" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex4" => 2 }, "value" => "No" }]) |
||||
end |
||||
end |
||||
|
||||
context "when person 5" do |
||||
let(:person_index) { 5 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex5") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(5) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description5" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex5" => 2 }, "value" => "No" }]) |
||||
end |
||||
end |
||||
|
||||
context "when person 6" do |
||||
let(:person_index) { 6 } |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("gender_same_as_sex6") |
||||
end |
||||
|
||||
it "has expected check answers card number" do |
||||
expect(question.check_answers_card_number).to eq(6) |
||||
end |
||||
|
||||
it "has the correct conditional_for" do |
||||
expect(question.conditional_for).to eq({ "gender_description6" => [2] }) |
||||
end |
||||
|
||||
it "has the correct inferred_check_answers_value" do |
||||
expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex6" => 2 }, "value" => "No" }]) |
||||
end |
||||
end |
||||
end |
||||
Loading…
Reference in new issue