From 502d038e9e0e93dc72d9ab5a2791d7f89f869bfe Mon Sep 17 00:00:00 2001
From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
Date: Wed, 20 Nov 2024 14:24:37 +0000
Subject: [PATCH] CLDC-3752: Sales - Hide questions if a staircasing
transaction (25/26) (#2780)
* Do not ask questions from these sections when it's a staircase transaction
* Hide section/subsections from task list
* Add tests
* Fix lint
* Move logic to section model
---
.../sales/subsections/household_situation.rb | 15 ++++-
.../income_benefits_and_savings.rb | 15 ++++-
.../other_household_information.rb | 15 ++++-
app/models/form/section.rb | 4 ++
app/views/logs/_tasklist.html.erb | 5 +-
.../subsections/household_situation_spec.rb | 22 +++----
.../income_benefits_and_savings_spec.rb | 29 ++++++---
.../other_household_information_spec.rb | 62 +++++++++++--------
8 files changed, 116 insertions(+), 51 deletions(-)
diff --git a/app/models/form/sales/subsections/household_situation.rb b/app/models/form/sales/subsections/household_situation.rb
index 2e496908b..d5b8ab7e2 100644
--- a/app/models/form/sales/subsections/household_situation.rb
+++ b/app/models/form/sales/subsections/household_situation.rb
@@ -3,7 +3,14 @@ class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection
super
@id = "household_situation"
@label = "Household situation"
- @depends_on = [{ "setup_completed?" => true }]
+ end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [{ "setup_completed?" => true, "is_staircase?" => false }]
+ else
+ [{ "setup_completed?" => true }]
+ end
end
def pages
@@ -16,4 +23,10 @@ class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection
Form::Sales::Pages::Buyer2PreviousHousingSituation.new(nil, nil, self),
].flatten.compact
end
+
+ def displayed_in_tasklist?(log)
+ return true unless form.start_year_2025_or_later?
+
+ log.staircase != 1
+ end
end
diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb
index 19b6e7e03..9244267b9 100644
--- a/app/models/form/sales/subsections/income_benefits_and_savings.rb
+++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb
@@ -3,7 +3,14 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
super
@id = "income_benefits_and_savings"
@label = "Income, benefits and savings"
- @depends_on = [{ "setup_completed?" => true }]
+ end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [{ "setup_completed?" => true, "is_staircase?" => false }]
+ else
+ [{ "setup_completed?" => true }]
+ end
end
def pages
@@ -36,6 +43,12 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
].compact
end
+ def displayed_in_tasklist?(log)
+ return true unless form.start_year_2025_or_later?
+
+ log.staircase != 1
+ end
+
private
def previous_shared_page
diff --git a/app/models/form/sales/subsections/other_household_information.rb b/app/models/form/sales/subsections/other_household_information.rb
index 3acc9ffd5..e30afddc1 100644
--- a/app/models/form/sales/subsections/other_household_information.rb
+++ b/app/models/form/sales/subsections/other_household_information.rb
@@ -3,7 +3,14 @@ class Form::Sales::Subsections::OtherHouseholdInformation < ::Form::Subsection
super
@id = "other_household_information"
@label = "Other household information"
- @depends_on = [{ "setup_completed?" => true }]
+ end
+
+ def depends_on
+ if form.start_year_2025_or_later?
+ [{ "setup_completed?" => true, "is_staircase?" => false }]
+ else
+ [{ "setup_completed?" => true }]
+ end
end
def pages
@@ -17,4 +24,10 @@ class Form::Sales::Subsections::OtherHouseholdInformation < ::Form::Subsection
Form::Sales::Pages::HouseholdWheelchairCheck.new("wheelchair_check", nil, self),
]
end
+
+ def displayed_in_tasklist?(log)
+ return true unless form.start_year_2025_or_later?
+
+ log.staircase != 1
+ end
end
diff --git a/app/models/form/section.rb b/app/models/form/section.rb
index 97a128f74..a836bd45a 100644
--- a/app/models/form/section.rb
+++ b/app/models/form/section.rb
@@ -10,4 +10,8 @@ class Form::Section
@subsections = hsh["subsections"].map { |s_id, s| Form::Subsection.new(s_id, s, self) }
end
end
+
+ def displayed_in_tasklist?(log)
+ subsections.any? { |subsection| subsection.displayed_in_tasklist?(log) }
+ end
end
diff --git a/app/views/logs/_tasklist.html.erb b/app/views/logs/_tasklist.html.erb
index df8a3afad..e2f977a70 100644
--- a/app/views/logs/_tasklist.html.erb
+++ b/app/views/logs/_tasklist.html.erb
@@ -1,5 +1,6 @@
- <% @log.form.sections.map do |section| %>
+ <% @log.form.sections.each do |section| %>
+ <% next unless section.displayed_in_tasklist?(@log) %>
-
<%= section.label %>
@@ -8,7 +9,7 @@
<%= section.description.html_safe %>
<% end %>
- <% section.subsections.map do |subsection| %>
+ <% section.subsections.each do |subsection| %>
<% if subsection.displayed_in_tasklist?(@log) && (subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log)) %>
<% subsection_status = subsection.status(@log) %>
-
diff --git a/spec/models/form/sales/subsections/household_situation_spec.rb b/spec/models/form/sales/subsections/household_situation_spec.rb
index 903960a8d..821847d9e 100644
--- a/spec/models/form/sales/subsections/household_situation_spec.rb
+++ b/spec/models/form/sales/subsections/household_situation_spec.rb
@@ -25,6 +25,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
],
)
end
+
+ it "has the correct id" do
+ expect(household_characteristics.id).to eq("household_situation")
+ end
+
+ it "has the correct label" do
+ expect(household_characteristics.label).to eq("Household situation")
+ end
end
context "when the start year is 2025" do
@@ -41,17 +49,9 @@ RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
],
)
end
- end
- it "has the correct id" do
- expect(household_characteristics.id).to eq("household_situation")
- end
-
- it "has the correct label" do
- expect(household_characteristics.label).to eq("Household situation")
- end
-
- it "has correct depends on" do
- expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
+ it "has correct depends on" do
+ expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true, "is_staircase?" => false }])
+ end
end
end
diff --git a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
index 22a84f2a9..557155758 100644
--- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
+++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
@@ -11,8 +11,16 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.section).to eq(section)
end
+ it "has the correct id" do
+ expect(subsection.id).to eq("income_benefits_and_savings")
+ end
+
+ it "has the correct label" do
+ expect(subsection.label).to eq("Income, benefits and savings")
+ end
+
describe "pages" do
- let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:)) }
+ let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:, start_year_2025_or_later?: false)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
@@ -83,18 +91,19 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
],
)
end
- end
- end
- it "has the correct id" do
- expect(subsection.id).to eq("income_benefits_and_savings")
+ it "has correct depends on" do
+ expect(subsection.depends_on).to eq([{ "setup_completed?" => true }])
+ end
+ end
end
- it "has the correct label" do
- expect(subsection.label).to eq("Income, benefits and savings")
- end
+ context "when 2025" do
+ let(:start_date) { Time.utc(2025, 2, 8) }
+ let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:, start_year_2025_or_later?: true)) }
- it "has correct depends on" do
- expect(subsection.depends_on).to eq([{ "setup_completed?" => true }])
+ it "has correct depends on" do
+ expect(subsection.depends_on).to eq([{ "setup_completed?" => true, "is_staircase?" => false }])
+ end
end
end
diff --git a/spec/models/form/sales/subsections/other_household_information_spec.rb b/spec/models/form/sales/subsections/other_household_information_spec.rb
index 461ad2cc9..836540b5b 100644
--- a/spec/models/form/sales/subsections/other_household_information_spec.rb
+++ b/spec/models/form/sales/subsections/other_household_information_spec.rb
@@ -5,36 +5,48 @@ RSpec.describe Form::Sales::Subsections::OtherHouseholdInformation, type: :model
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
- let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
- let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
- it "has correct section" do
- expect(household_characteristics.section).to eq(section)
- end
+ context "when 2024" do
+ let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) }
+ let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
- it "has correct pages" do
- expect(household_characteristics.pages.map(&:id)).to eq(
- %w[
- armed_forces
- buyer_still_serving
- armed_forces_spouse
- household_disability
- disability_wheelchair_check
- household_wheelchair
- wheelchair_check
- ],
- )
- end
+ it "has correct section" do
+ expect(household_characteristics.section).to eq(section)
+ end
- it "has the correct id" do
- expect(household_characteristics.id).to eq("other_household_information")
- end
+ it "has correct pages" do
+ expect(household_characteristics.pages.map(&:id)).to eq(
+ %w[
+ armed_forces
+ buyer_still_serving
+ armed_forces_spouse
+ household_disability
+ disability_wheelchair_check
+ household_wheelchair
+ wheelchair_check
+ ],
+ )
+ end
- it "has the correct label" do
- expect(household_characteristics.label).to eq("Other household information")
+ it "has the correct id" do
+ expect(household_characteristics.id).to eq("other_household_information")
+ end
+
+ it "has the correct label" do
+ expect(household_characteristics.label).to eq("Other household information")
+ end
+
+ it "has correct depends on" do
+ expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
+ end
end
- it "has correct depends on" do
- expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
+ context "when 2025" do
+ let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) }
+ let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
+
+ it "has correct depends on" do
+ expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true, "is_staircase?" => false }])
+ end
end
end