From 7f1c56db6f4a0190cf9e6dd51f7ad878270fbcc0 Mon Sep 17 00:00:00 2001
From: Hibo Abdilaahi <51047911+hiboabd@users.noreply.github.com>
Date: Thu, 4 Jan 2024 16:23:35 +0000
Subject: [PATCH] [CRIMAPP-286] Add dependants section to app details (#505)
* Add income section to app details
* Display dependants section
* Sort dependants before grouping
Hide details row when there are no additional other income details
* Do not display income details rows if they are not asked
* Fix linting errors
---
Gemfile | 2 +-
Gemfile.lock | 6 +--
app/models/crime_application.rb | 4 ++
app/presenters/dependants_presenter.rb | 47 ++++++++++++++++
.../crime_applications/_dependants.html.erb | 30 +++++++++++
.../crime_applications/_income.html.erb | 54 ++++++++++---------
.../_other_income_details.html.erb | 14 +++--
.../casework/crime_applications/show.html.erb | 3 +-
config/locales/en/casework.yml | 3 ++
config/settings.yml | 4 ++
spec/presenters/dependants_presenter_spec.rb | 29 ++++++++++
.../application_details/dependants_spec.rb | 48 +++++++++++++++++
.../income_details_spec.rb | 25 +++++++++
13 files changed, 232 insertions(+), 37 deletions(-)
create mode 100644 app/presenters/dependants_presenter.rb
create mode 100644 app/views/casework/crime_applications/_dependants.html.erb
create mode 100644 spec/presenters/dependants_presenter_spec.rb
create mode 100644 spec/system/casework/viewing_an_application/application_details/dependants_spec.rb
diff --git a/Gemfile b/Gemfile
index 261232094..fe5646b5b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -23,7 +23,7 @@ gem 'laa-criminal-applications-datastore-api-client',
require: 'datastore_api'
gem 'laa-criminal-legal-aid-schemas',
- github: 'ministryofjustice/laa-criminal-legal-aid-schemas', tag: 'v1.0.20'
+ github: 'ministryofjustice/laa-criminal-legal-aid-schemas', tag: 'v1.0.23'
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'sprockets-rails'
diff --git a/Gemfile.lock b/Gemfile.lock
index bd4a9f870..0e501645c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -9,10 +9,10 @@ GIT
GIT
remote: https://github.com/ministryofjustice/laa-criminal-legal-aid-schemas.git
- revision: ec72e9c9cc930a3c6eee3873fac717d855e7ab2a
- tag: v1.0.20
+ revision: 0e3a390af6311054d94720d3300178db898b6ae4
+ tag: v1.0.23
specs:
- laa-criminal-legal-aid-schemas (1.0.20)
+ laa-criminal-legal-aid-schemas (1.0.23)
dry-schema (~> 1.13)
dry-struct (~> 1.6.0)
json-schema (~> 4.0.0)
diff --git a/app/models/crime_application.rb b/app/models/crime_application.rb
index 40f42e5b1..65b9195f2 100644
--- a/app/models/crime_application.rb
+++ b/app/models/crime_application.rb
@@ -114,4 +114,8 @@ def case_details
def applicant
@applicant ||= ApplicantPresenter.present(self[:client_details][:applicant])
end
+
+ def dependants
+ @dependants ||= DependantsPresenter.present(self[:means_details].income_details&.dependants)
+ end
end
diff --git a/app/presenters/dependants_presenter.rb b/app/presenters/dependants_presenter.rb
new file mode 100644
index 000000000..d37fc4cd3
--- /dev/null
+++ b/app/presenters/dependants_presenter.rb
@@ -0,0 +1,47 @@
+class DependantsPresenter < BasePresenter
+ def initialize(dependants)
+ super(
+ @dependants = dependants
+ )
+ end
+
+ def formatted_dependants
+ return unless @dependants
+
+ dependants_by_age_range
+ end
+
+ private
+
+ # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
+ def dependants_by_age_range
+ grouped_dependants = Hash.new(0)
+
+ sorted_dependants.each do |dependant|
+ case dependant[:age]
+ when 0, 1
+ grouped_dependants['0 to 1'] += 1
+ when 2, 3, 4
+ grouped_dependants['2 to 4'] += 1
+ when 5, 6, 7
+ grouped_dependants['5 to 7'] += 1
+ when 8, 9, 10
+ grouped_dependants['8 to 10'] += 1
+ when 11, 12
+ grouped_dependants['11 to 12'] += 1
+ when 13, 14, 15
+ grouped_dependants['13 to 15'] += 1
+ else
+ grouped_dependants['16 to 18'] += 1
+ end
+ end
+
+ grouped_dependants
+ end
+ # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
+
+ def sorted_dependants
+ # Sorts ages so the ranking is ordered
+ @dependants.sort_by { |d| d[:age] }
+ end
+end
diff --git a/app/views/casework/crime_applications/_dependants.html.erb b/app/views/casework/crime_applications/_dependants.html.erb
new file mode 100644
index 000000000..dd1957241
--- /dev/null
+++ b/app/views/casework/crime_applications/_dependants.html.erb
@@ -0,0 +1,30 @@
+<% if dependants %>
+
+ <%= label_text(:dependants) %>
+
+ <% if dependants.any? %>
+
+ <% dependants.each do |age_range, count| %>
+
+
-
+ <%= label_text(:number_of_dependants, age_range:) %>
+
+ -
+ <%= count %>
+
+
+ <%end%>
+
+ <% else %>
+
+
+
-
+ <%= label_text(:has_dependants) %>
+
+ -
+ <%= t(false, scope: 'values') %>
+
+
+
+ <% end %>
+<% end %>
diff --git a/app/views/casework/crime_applications/_income.html.erb b/app/views/casework/crime_applications/_income.html.erb
index a5a2020c7..4e66869dc 100644
--- a/app/views/casework/crime_applications/_income.html.erb
+++ b/app/views/casework/crime_applications/_income.html.erb
@@ -12,29 +12,35 @@
<%= t(income_details.income_above_threshold, scope: 'values') %>
-
-
- <%= label_text(:has_frozen_income_or_assets) %>
-
-
- <%= t(income_details.has_frozen_income_or_assets, scope: 'values') %>
-
-
-
-
- <%= label_text(:client_owns_property) %>
-
-
- <%= t(income_details.client_owns_property, scope: 'values') %>
-
-
-
-
- <%= label_text(:has_savings) %>
-
-
- <%= t(income_details.has_savings, scope: 'values') %>
-
-
+ <% unless income_details.has_frozen_income_or_assets.nil? %>
+
+
+ <%= label_text(:has_frozen_income_or_assets) %>
+
+
+ <%= t(income_details.has_frozen_income_or_assets, scope: 'values') %>
+
+
+ <% end %>
+ <% unless income_details.client_owns_property.nil? %>
+
+
+ <%= label_text(:client_owns_property) %>
+
+
+ <%= t(income_details.client_owns_property, scope: 'values') %>
+
+
+ <% end %>
+ <% unless income_details.has_savings.nil? %>
+
+
+ <%= label_text(:has_savings) %>
+
+
+ <%= t(income_details.has_savings, scope: 'values') %>
+
+
+ <% end %>
<% end %>
diff --git a/app/views/casework/crime_applications/_other_income_details.html.erb b/app/views/casework/crime_applications/_other_income_details.html.erb
index 65feb48ba..bd8ea4787 100644
--- a/app/views/casework/crime_applications/_other_income_details.html.erb
+++ b/app/views/casework/crime_applications/_other_income_details.html.erb
@@ -12,18 +12,16 @@
<%= t(income_details.manage_without_income, scope: 'values.manage_without_income') %>
-
+ <%# TODO: confirm design for other option %>
+ <% if income_details.manage_without_income == 'other' %>
+
- <% if income_details.manage_without_income == 'other' %>
- <%= t('labels.details') %>
- <% end %>
+ <%= t('labels.details') %>
- <%# TODO: confirm design for other option %>
- <% if income_details.manage_without_income == 'other' %>
- <%= income_details.manage_other_details %>
- <% end %>
+ <%= income_details.manage_other_details %>
+ <% end %>
<% end %>
diff --git a/app/views/casework/crime_applications/show.html.erb b/app/views/casework/crime_applications/show.html.erb
index 751978fcf..7d3f2d83d 100644
--- a/app/views/casework/crime_applications/show.html.erb
+++ b/app/views/casework/crime_applications/show.html.erb
@@ -18,8 +18,9 @@
<%= render partial: 'supporting_evidence', locals: { crime_application: @crime_application } %>
<% if FeatureFlags.means_journey.enabled? %>
<%= render partial: 'income', locals: { income_details: @crime_application.means_details.income_details } %>
+ <%= render partial: 'dependants', locals: { dependants: @crime_application.dependants.formatted_dependants } %>
<%= render partial: 'other_income_details', locals: { income_details: @crime_application.means_details.income_details } %>
- <% end %>
+ <% end %>
<%= render partial: 'provider_details', object: @crime_application.provider_details %>
diff --git a/config/locales/en/casework.yml b/config/locales/en/casework.yml
index 75cbbb6e2..2168fc568 100644
--- a/config/locales/en/casework.yml
+++ b/config/locales/en/casework.yml
@@ -77,6 +77,7 @@ en:
correspondence_address: Correspondence address
criminal_applications_team: CAT 1
criminal_applications_team_2: CAT 2
+ dependants: Dependants who live with the client
date:
sent_back: 'Date closed:'
completed: 'Date closed:'
@@ -90,6 +91,7 @@ en:
financial_change_details: Changes in the client’s financial circumstances
first_name: First name
first_court_hearing: First court hearing the case
+ has_dependants: Has dependants?
has_frozen_income_or_assets: Has income, savings or assets under a restraint or freezing order?
has_savings: Has savings or investments?
hearing_date: Date of next hearing
@@ -107,6 +109,7 @@ en:
national_crime_team: CAT 2
national_insurance_number: National Insurance number
next_court_hearing: Next court hearing the case
+ number_of_dependants: Number of dependants aged %{age_range} on next birthday
offence: Offence
offence_date: Offence date
offence_details: Offence details
diff --git a/config/settings.yml b/config/settings.yml
index 866b1ce55..07cf74531 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -11,3 +11,7 @@ feature_flags:
local: true
staging: true
production: false
+ means_journey:
+ local: true
+ staging: true
+ production: false
diff --git a/spec/presenters/dependants_presenter_spec.rb b/spec/presenters/dependants_presenter_spec.rb
new file mode 100644
index 000000000..6dfc51ac2
--- /dev/null
+++ b/spec/presenters/dependants_presenter_spec.rb
@@ -0,0 +1,29 @@
+require 'rails_helper'
+
+RSpec.describe DependantsPresenter do
+ subject(:dependants_presenter) { described_class.new(dependants) }
+
+ let(:dependants) do
+ [{ age: 1 }, { age: 5 }, { age: 12 }, { age: 15 }, { age: 4 }, { age: 7 }, { age: 8 }, { age: 18 }]
+ end
+
+ describe '#formatted_dependants' do
+ subject(:formatted_dependants) { dependants_presenter.formatted_dependants }
+
+ it {
+ expect(formatted_dependants).to eq({ '0 to 1' => 1,
+ '2 to 4' => 1,
+ '5 to 7' => 2,
+ '8 to 10' => 1,
+ '11 to 12' => 1,
+ '13 to 15' => 1,
+ '16 to 18' => 1 })
+ }
+
+ context 'with no dependants' do
+ let(:dependants) { nil }
+
+ it { expect(formatted_dependants).to be_nil }
+ end
+ end
+end
diff --git a/spec/system/casework/viewing_an_application/application_details/dependants_spec.rb b/spec/system/casework/viewing_an_application/application_details/dependants_spec.rb
new file mode 100644
index 000000000..f2dd51cb8
--- /dev/null
+++ b/spec/system/casework/viewing_an_application/application_details/dependants_spec.rb
@@ -0,0 +1,48 @@
+require 'rails_helper'
+
+RSpec.describe 'Viewing the dependants details of an application' do
+ include_context 'with stubbed application'
+
+ before do
+ visit crime_application_path(application_id)
+ end
+
+ context 'with dependants' do
+ let(:application_data) do
+ super().deep_merge('means_details' => { 'income_details' => { 'dependants' => [{ age: 1 }, { age: 5 }] } })
+ end
+
+ it 'shows dependants heading' do
+ expect(page).to have_content('Dependants who live with the client')
+ end
+
+ it 'shows dependants grouped by age range' do
+ expect(page).to have_content('Number of dependants aged 0 to 1 on next birthday 1')
+ expect(page).to have_content('Number of dependants aged 5 to 7 on next birthday 1')
+ end
+ end
+
+ context 'with no dependants' do
+ let(:application_data) do
+ super().deep_merge('means_details' => { 'income_details' => { 'dependants' => [] } })
+ end
+
+ it 'shows dependants heading' do
+ expect(page).to have_content('Dependants who live with the client')
+ end
+
+ it 'shows no dependants' do
+ expect(page).to have_content('Has dependants? No')
+ end
+ end
+
+ context 'with not shown dependants screen' do
+ let(:application_data) do
+ super().deep_merge('means_details' => { 'income_details' => { 'dependants' => nil } })
+ end
+
+ it 'does not show dependants section' do
+ expect(page).not_to have_content('Dependants who live with the client')
+ end
+ end
+end
diff --git a/spec/system/casework/viewing_an_application/application_details/income_details_spec.rb b/spec/system/casework/viewing_an_application/application_details/income_details_spec.rb
index 65bdb5bd6..fe2b3e7fc 100644
--- a/spec/system/casework/viewing_an_application/application_details/income_details_spec.rb
+++ b/spec/system/casework/viewing_an_application/application_details/income_details_spec.rb
@@ -34,4 +34,29 @@
expect(page).not_to have_content('Income')
end
end
+
+ context 'with nil income details' do
+ let(:application_data) do
+ super().deep_merge('means_details' => { 'income_details' => { 'income_above_threshold' => 'yes',
+ 'has_frozen_income_or_assets' => nil,
+ 'client_owns_property' => nil,
+ 'has_savings' => nil, } })
+ end
+
+ it 'shows income above threshold' do
+ expect(page).to have_content('Income more than £12,475? Yes')
+ end
+
+ it 'shows has income savings assets' do
+ expect(page).not_to have_content('Has income, savings or assets under a restraint or freezing order?')
+ end
+
+ it 'shows land or property' do
+ expect(page).not_to have_content('Has land or property?')
+ end
+
+ it 'shows savings or investments' do
+ expect(page).not_to have_content('Has savings or investments?')
+ end
+ end
end