Skip to content

Commit

Permalink
Refactored methods into Filters View
Browse files Browse the repository at this point in the history
  • Loading branch information
dcyoung-dev committed Jul 11, 2024
1 parent 9406b90 commit 4323e46
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/view_objects/find/result_filters/filters_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/find/result_filters/_radius.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<% if @filters_view.radius.present? %>
<% if @filters_view.location_query? %>
<fieldset class="govuk-fieldset app-filter__group" data-qa="filters__radius">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s">
<%= form.label :radius, "Search radius", class: "govuk-label govuk-fieldset__legend govuk-fieldset__legend--s" %>
</legend>
<div class="govuk-checkboxes govuk-checkboxes--small">
<div class="govuk-checkboxes__item" data-qa="radius-select">
<%= 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" %>
</div>
</div>
</fieldset>
Expand Down
11 changes: 5 additions & 6 deletions config/locales/find.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,11 @@ en:
html: <abbr title='Postgraduate diploma in education'>PGDE</abbr> without <abbr title='Qualified teacher status'>QTS</abbr>
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:
Expand Down
24 changes: 24 additions & 0 deletions spec/view_objects/find/result_filters/filters_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4323e46

Please sign in to comment.