Browse Source

Reuse the same page

CLDC-1530-working-situation
Kat 2 years ago
parent
commit
9e5d404377
  1. 20
      app/models/form/sales/pages/person_working_situation.rb
  2. 24
      app/models/form/sales/pages/person_working_situation_joint_purchase.rb
  3. 8
      app/models/form/sales/subsections/household_characteristics.rb
  4. 85
      spec/models/form/sales/pages/person_working_situation_joint_purchase_spec.rb
  5. 175
      spec/models/form/sales/pages/person_working_situation_spec.rb

20
app/models/form/sales/pages/person_working_situation.rb

@ -5,20 +5,36 @@ class Form::Sales::Pages::PersonWorkingSituation < ::Form::Page
@description = "" @description = ""
@subsection = subsection @subsection = subsection
@depends_on = [ @depends_on = [
{ "details_known_#{PERSON_INDEX[id] - 1}" => 1, "jointpur" => 2 }, { "details_known_#{person_display_number}" => 1, "jointpur" => joint_purchase? ? 1 : 2 },
] ]
end end
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::PersonWorkingSituation.new("ecstat#{PERSON_INDEX[id]}", nil, self), Form::Sales::Questions::PersonWorkingSituation.new("ecstat#{person_database_number}", nil, self),
] ]
end end
def person_database_number
PERSON_INDEX[id]
end
def person_display_number
joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1
end
def joint_purchase?
id.include?("_joint_purchase")
end
PERSON_INDEX = { PERSON_INDEX = {
"person_1_working_situation" => 2, "person_1_working_situation" => 2,
"person_2_working_situation" => 3, "person_2_working_situation" => 3,
"person_3_working_situation" => 4, "person_3_working_situation" => 4,
"person_4_working_situation" => 5, "person_4_working_situation" => 5,
"person_1_working_situation_joint_purchase" => 3,
"person_2_working_situation_joint_purchase" => 4,
"person_3_working_situation_joint_purchase" => 5,
"person_4_working_situation_joint_purchase" => 6,
}.freeze }.freeze
end end

24
app/models/form/sales/pages/person_working_situation_joint_purchase.rb

@ -1,24 +0,0 @@
class Form::Sales::Pages::PersonWorkingSituationJointPurchase < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_#{PERSON_INDEX[id] - 2}" => 1, "jointpur" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::PersonWorkingSituation.new("ecstat#{PERSON_INDEX[id]}", nil, self),
]
end
PERSON_INDEX = {
"person_1_working_situation_joint_purchase" => 3,
"person_2_working_situation_joint_purchase" => 4,
"person_3_working_situation_joint_purchase" => 5,
"person_4_working_situation_joint_purchase" => 6,
}.freeze
end

8
app/models/form/sales/subsections/household_characteristics.rb

@ -34,19 +34,19 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self),
Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self),
Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self),
Form::Sales::Pages::PersonWorkingSituationJointPurchase.new("person_1_working_situation_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self),
Form::Sales::Pages::Person2Known.new(nil, nil, self), Form::Sales::Pages::Person2Known.new(nil, nil, self),
Form::Sales::Pages::Person2Age.new(nil, nil, self), Form::Sales::Pages::Person2Age.new(nil, nil, self),
Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self),
Form::Sales::Pages::PersonWorkingSituationJointPurchase.new("person_2_working_situation_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self),
Form::Sales::Pages::Person3Known.new(nil, nil, self), Form::Sales::Pages::Person3Known.new(nil, nil, self),
Form::Sales::Pages::Person3Age.new(nil, nil, self), Form::Sales::Pages::Person3Age.new(nil, nil, self),
Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self),
Form::Sales::Pages::PersonWorkingSituationJointPurchase.new("person_3_working_situation_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self),
Form::Sales::Pages::Person4Known.new(nil, nil, self), Form::Sales::Pages::Person4Known.new(nil, nil, self),
Form::Sales::Pages::Person4Age.new(nil, nil, self), Form::Sales::Pages::Person4Age.new(nil, nil, self),
Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self),
Form::Sales::Pages::PersonWorkingSituationJointPurchase.new("person_4_working_situation_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation_joint_purchase", nil, self),
] ]
end end
end end

85
spec/models/form/sales/pages/person_working_situation_joint_purchase_spec.rb

@ -1,85 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PersonWorkingSituationJointPurchase, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "person_1_working_situation_joint_purchase" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
context "with person 1" do
let(:page_id) { "person_1_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end
it "has the correct id" do
expect(page.id).to eq("person_1_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end
end
context "with person 2" do
let(:page_id) { "person_2_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
it "has the correct id" do
expect(page.id).to eq("person_2_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 1 }])
end
end
context "with person 3" do
let(:page_id) { "person_3_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end
it "has the correct id" do
expect(page.id).to eq("person_3_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 1 }])
end
end
context "with person 4" do
let(:page_id) { "person_4_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat6])
end
it "has the correct id" do
expect(page.id).to eq("person_4_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }])
end
end
end

175
spec/models/form/sales/pages/person_working_situation_spec.rb

@ -3,83 +3,166 @@ require "rails_helper"
RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do RSpec.describe Form::Sales::Pages::PersonWorkingSituation, 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) { "person_1_working_situation" }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do context "without joint purchase" do
expect(page.subsection).to eq(subsection)
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
context "with person 1" do
let(:page_id) { "person_1_working_situation" } let(:page_id) { "person_1_working_situation" }
it "has correct questions" do it "has correct subsection" do
expect(page.questions.map(&:id)).to eq(%w[ecstat2]) expect(page.subsection).to eq(subsection)
end end
it "has the correct id" do it "has the correct header" do
expect(page.id).to eq("person_1_working_situation") expect(page.header).to eq("")
end end
it "has correct depends_on" do it "has the correct description" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }]) expect(page.description).to eq("")
end end
end
context "with person 2" do context "with person 1" do
let(:page_id) { "person_2_working_situation" } let(:page_id) { "person_1_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat2])
end
it "has the correct id" do
expect(page.id).to eq("person_1_working_situation")
end
it "has correct questions" do it "has correct depends_on" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3]) expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }])
end
end end
it "has the correct id" do context "with person 2" do
expect(page.id).to eq("person_2_working_situation") let(:page_id) { "person_2_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end
it "has the correct id" do
expect(page.id).to eq("person_2_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }])
end
end
context "with person 3" do
let(:page_id) { "person_3_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
it "has the correct id" do
expect(page.id).to eq("person_3_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 2 }])
end
end end
it "has correct depends_on" do context "with person 4" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }]) let(:page_id) { "person_4_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 2 }])
end
end end
end end
context "with person 3" do context "with joint purchase" do
let(:page_id) { "person_3_working_situation" } let(:page_id) { "person_1_working_situation_joint_purchase" }
it "has correct questions" do it "has correct subsection" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4]) expect(page.subsection).to eq(subsection)
end end
it "has the correct id" do it "has the correct header" do
expect(page.id).to eq("person_3_working_situation") expect(page.header).to eq("")
end end
it "has correct depends_on" do it "has the correct description" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 2 }]) expect(page.description).to eq("")
end end
end
context "with person 4" do context "with person 1" do
let(:page_id) { "person_4_working_situation" } let(:page_id) { "person_1_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end
it "has correct questions" do it "has the correct id" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5]) expect(page.id).to eq("person_1_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end
end end
it "has the correct id" do context "with person 2" do
expect(page.id).to eq("person_4_working_situation") let(:page_id) { "person_2_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
it "has the correct id" do
expect(page.id).to eq("person_2_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 1 }])
end
end end
it "has correct depends_on" do context "with person 3" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 2 }]) let(:page_id) { "person_3_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end
it "has the correct id" do
expect(page.id).to eq("person_3_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 1 }])
end
end
context "with person 4" do
let(:page_id) { "person_4_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat6])
end
it "has the correct id" do
expect(page.id).to eq("person_4_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }])
end
end end
end end
end end

Loading…
Cancel
Save