From 4323e464d2ab289e2bde33d3b6f9acbb19362162 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 11 Jul 2024 09:39:26 +0100 Subject: [PATCH] Refactored methods into Filters View --- .../find/result_filters/filters_view.rb | 4 ++++ .../find/result_filters/_radius.html.erb | 4 ++-- config/locales/find.yml | 11 ++++----- .../find/result_filters/filters_view_spec.rb | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/view_objects/find/result_filters/filters_view.rb b/app/view_objects/find/result_filters/filters_view.rb index 2d23e2d8e4..d61829816e 100644 --- a/app/view_objects/find/result_filters/filters_view.rb +++ b/app/view_objects/find/result_filters/filters_view.rb @@ -9,6 +9,10 @@ def initialize(params:) def radius_options = [1, 5, 10, 15, 20, 25, 50, 100, 200] + def radius_options_for_select + radius_options.map { |r| [I18n.t('find.result_filters_filters_view.radius_options_for_select.label', count: r), r] } + end + def radius params[:radius] end diff --git a/app/views/find/result_filters/_radius.html.erb b/app/views/find/result_filters/_radius.html.erb index 96aa340cd9..c16c1c4af2 100644 --- a/app/views/find/result_filters/_radius.html.erb +++ b/app/views/find/result_filters/_radius.html.erb @@ -1,11 +1,11 @@ -<% if @filters_view.radius.present? %> +<% if @filters_view.location_query? %>
<%= form.label :radius, "Search radius", class: "govuk-label govuk-fieldset__legend govuk-fieldset__legend--s" %>
- <%= form.select :radius, options_for_select(@filters_view.radius_options.map { |r| [t(".radius_select.label", count: r), r] }, @filters_view.radius), {}, class: "govuk-select" %> + <%= form.select :radius, options_for_select(@filters_view.radius_options_for_select, @filters_view.radius), {}, class: "govuk-select" %>
diff --git a/config/locales/find.yml b/config/locales/find.yml index eb55dfc8e6..f4023322d1 100644 --- a/config/locales/find.yml +++ b/config/locales/find.yml @@ -200,12 +200,11 @@ en: html: PGDE without QTS links: national_pay_scales: https://www.gov.uk/government/publications/national-pay-scales-for-eligible-teaching-and-education-jobs/national-pay-scales-for-eligible-teaching-and-education-leadership-occupation-codes - result_filters: - radius: - radius_select: - label: - one: '%{count} mile' - other: '%{count} miles' + result_filters_filters_view: + radius_options_for_select: + label: + one: '%{count} mile' + other: '%{count} miles' activemodel: errors: models: diff --git a/spec/view_objects/find/result_filters/filters_view_spec.rb b/spec/view_objects/find/result_filters/filters_view_spec.rb index e1e689f277..9116627af7 100644 --- a/spec/view_objects/find/result_filters/filters_view_spec.rb +++ b/spec/view_objects/find/result_filters/filters_view_spec.rb @@ -354,6 +354,30 @@ module ResultFilters it { is_expected.to be(false) } end end + + describe '#radius' do + subject { described_class.new(params: { radius: 10 }).radius } + + it { is_expected.to eq(10) } + end + + describe '#radius_options_for_select' do + subject { described_class.new(params: {}).radius_options_for_select } + + it 'returns an array of arrays' do + expect(subject).to eq([ + ['1 mile', 1], + ['5 miles', 5], + ['10 miles', 10], + ['15 miles', 15], + ['20 miles', 20], + ['25 miles', 25], + ['50 miles', 50], + ['100 miles', 100], + ['200 miles', 200] + ]) + end + end end end end