Skip to content

Commit

Permalink
[CRIMAPP-286] Add dependants section to app details (#505)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hiboabd authored Jan 4, 2024
1 parent 1b86244 commit 7f1c56d
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/models/crime_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions app/presenters/dependants_presenter.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions app/views/casework/crime_applications/_dependants.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<% if dependants %>
<h2 class="govuk-heading-m">
<%= label_text(:dependants) %>
</h2>
<% if dependants.any? %>
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<% dependants.each do |age_range, count| %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key govuk-!-width-one-half">
<%= label_text(:number_of_dependants, age_range:) %>
</dt>
<dd class="govuk-summary-list__value">
<%= count %>
</dd>
</div>
<%end%>
</dl>
<% else %>
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:has_dependants) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(false, scope: 'values') %>
</dd>
</div>
</dl>
<% end %>
<% end %>
54 changes: 30 additions & 24 deletions app/views/casework/crime_applications/_income.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@
<%= t(income_details.income_above_threshold, scope: 'values') %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:has_frozen_income_or_assets) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(income_details.has_frozen_income_or_assets, scope: 'values') %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:client_owns_property) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(income_details.client_owns_property, scope: 'values') %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:has_savings) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(income_details.has_savings, scope: 'values') %>
</dd>
</div>
<% unless income_details.has_frozen_income_or_assets.nil? %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:has_frozen_income_or_assets) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(income_details.has_frozen_income_or_assets, scope: 'values') %>
</dd>
</div>
<% end %>
<% unless income_details.client_owns_property.nil? %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:client_owns_property) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(income_details.client_owns_property, scope: 'values') %>
</dd>
</div>
<% end %>
<% unless income_details.has_savings.nil? %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= label_text(:has_savings) %>
</dt>
<dd class="govuk-summary-list__value">
<%= t(income_details.has_savings, scope: 'values') %>
</dd>
</div>
<% end %>
</dl>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
<%= t(income_details.manage_without_income, scope: 'values.manage_without_income') %>
</dd>
</div>
<div class="govuk-summary-list__row">
<%# TODO: confirm design for other option %>
<% if income_details.manage_without_income == 'other' %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<% if income_details.manage_without_income == 'other' %>
<%= t('labels.details') %>
<% end %>
<%= t('labels.details') %>
</dt>
<dd class="govuk-summary-list__value">
<%# TODO: confirm design for other option %>
<% if income_details.manage_without_income == 'other' %>
<%= income_details.manage_other_details %>
<% end %>
<%= income_details.manage_other_details %>
</dd>
</div>
<% end %>
</dl>
<% end %>
3 changes: 2 additions & 1 deletion app/views/casework/crime_applications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en/casework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:'
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ feature_flags:
local: true
staging: true
production: false
means_journey:
local: true
staging: true
production: false
29 changes: 29 additions & 0 deletions spec/presenters/dependants_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7f1c56d

Please sign in to comment.