Skip to content

Commit

Permalink
Refactor show all filter
Browse files Browse the repository at this point in the history
This makes a number of small changes to the code to improve the
readability.
  • Loading branch information
thomasleese committed Mar 21, 2024
1 parent 8b65e2c commit 2240a62
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/forms/assessor_interface/filter_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class AssessorInterface::FilterForm
:location,
:name,
:reference,
:show_all,
:stage,
:submitted_at_after,
:submitted_at_before,
:show_all
:submitted_at_before
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module Filters
class ShowAllApplications < Base
class ShowAll < Base
def apply
unless show_all?
ninety_days_ago = 90.days.ago
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def filter_form

def assessor_filter_options
ApplicationForm
.submitted
.joins(:assessor)
.pluck(Arel.sql("DISTINCT ON(assessor_id) assessor_id"), "staff.name")
.sort_by { |_id, name| name }
Expand Down Expand Up @@ -74,7 +75,7 @@ def application_forms_without_counted_filters
::Filters::Email,
::Filters::Reference,
::Filters::SubmittedAt,
::Filters::ShowAllApplications,
::Filters::ShowAll,
]
filters.reduce(
ApplicationForm.includes(region: :country).submitted,
Expand Down
6 changes: 3 additions & 3 deletions app/views/assessor_interface/application_forms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
<% end %>
<% end %>
</section>
<% if FeatureFlags::FeatureFlag.active?(:show_all_applicants_filter) %>

<% if FeatureFlags::FeatureFlag.active?(:show_all_applications_filter) %>
<section id="app-applications-show-all-applicants">
<%= f.govuk_check_boxes_fieldset :show_all, legend: nil, multiple: false, small: true do %>
<%= f.govuk_check_box :show_all, :true, multiple: false, label: { text: "Show applications completed older than 90 days ago" }, checked: @view_object.filter_form.show_all == "true" %>
<%= f.govuk_check_box :show_all, :true, multiple: false, label: { text: "Show applications completed over 90 days ago" }, checked: @view_object.filter_form.show_all == "true" %>
<% end %>
</section>
<% end %>
Expand Down
11 changes: 6 additions & 5 deletions config/feature_flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ feature_flags:
When service_open is deactivated, and this flag is enabled, the user will
have full access to the service. Should be inactive on production.
show_all_applications_filter:
author: Nick Diplos
description: >
Adds a filter that allows assessors to view applications that are older
than 90 days old.
teacher_applications:
author: Thomas Leese
description: >
Allow starting an application on this service directly after completing
an eligibility check.
show_all_applicants_filter:
author: Nick Diplos
description: >
Adds a filter that allows assessors to view applications that are older than 90 days old.
parent_controller: SupportInterface::FeatureFlagsController
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Filters::ShowAllApplications do
RSpec.describe Filters::ShowAll do
subject(:filtered_scope) { described_class.apply(scope:, params:) }

let!(:application_awarded_recently) do
Expand Down
19 changes: 14 additions & 5 deletions spec/system/assessor_interface/filtering_application_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

RSpec.describe "Assessor filtering application forms", type: :system do
before do
FeatureFlags::FeatureFlag.activate(:show_all_applicants_filter)
given_the_service_is_open
given_there_are_application_forms
given_i_am_authorized_as_an_assessor_user
given_show_all_applications_is_activated
end

after { given_show_all_applications_is_deactivated }

it "applies the filters" do
when_i_visit_the(:assessor_applications_page)

Expand Down Expand Up @@ -59,6 +61,14 @@ def given_there_are_application_forms
application_forms
end

def given_show_all_applications_is_activated
FeatureFlags::FeatureFlag.activate(:show_all_applications_filter)
end

def given_show_all_applications_is_deactivated
FeatureFlags::FeatureFlag.deactivate(:show_all_applications_filter)
end

def when_i_visit_the_applications_page
visit assessor_interface_application_forms_path
end
Expand Down Expand Up @@ -190,13 +200,13 @@ def then_i_see_a_list_of_applications_filtered_by_stage
end

def and_i_apply_the_show_all_filter
show_all =
show_all_item =
assessor_applications_page.show_all_filter.items.find do |item|
item.label.text == "Show applications completed older than 90 days ago"
item.label.text == "Show applications completed over 90 days ago"
rescue Capybara::ElementNotFound
false
end
show_all.checkbox.click
show_all_item.checkbox.click
assessor_applications_page.apply_filters.click
end

Expand Down Expand Up @@ -258,7 +268,6 @@ def application_forms
submitted_at: 7.months.ago,
),
]
@application_forms
end

def assessors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

context "with a stage filter" do
before do
expect_any_instance_of(Filters::ShowAllApplications).to receive(
expect_any_instance_of(Filters::ShowAll).to receive(
:apply,
).and_return(ApplicationForm.none)
end
Expand Down Expand Up @@ -160,6 +160,7 @@

describe "#country_filter_options" do
subject(:country_filter_options) { view_object.country_filter_options }

it do
is_expected.to include(
'<option value="country:US">United States</option>',
Expand Down

0 comments on commit 2240a62

Please sign in to comment.