-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
13 changed files
with
232 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
app/views/casework/crime_applications/_dependants.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
48 changes: 48 additions & 0 deletions
48
spec/system/casework/viewing_an_application/application_details/dependants_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters