-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2078 from nickdip/all-applicants-filter
All applicants filter
- Loading branch information
Showing
11 changed files
with
180 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Filters | ||
class ShowAllApplications < Base | ||
def apply | ||
unless show_all? | ||
ninety_days_ago = 90.days.ago | ||
return( | ||
scope.where( | ||
"(awarded_at >= :ninety_days OR awarded_at IS NULL) | ||
AND (declined_at >= :ninety_days OR declined_at IS NULL) | ||
AND (withdrawn_at >= :ninety_days OR withdrawn_at IS NULL)", | ||
ninety_days: ninety_days_ago, | ||
) | ||
) | ||
end | ||
|
||
scope | ||
end | ||
|
||
private | ||
|
||
def show_all? | ||
ActiveModel::Type::Boolean.new.cast(params[:show_all]) | ||
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
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,70 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Filters::ShowAllApplications do | ||
subject(:filtered_scope) { described_class.apply(scope:, params:) } | ||
|
||
let!(:application_awarded_recently) do | ||
create(:application_form, awarded_at: 2.days.ago) | ||
end | ||
let!(:application_declined_recently) do | ||
create(:application_form, declined_at: 30.days.ago) | ||
end | ||
let!(:application_withdrawn_recently) do | ||
create(:application_form, withdrawn_at: 89.days.ago) | ||
end | ||
|
||
let!(:application_awarded_old) do | ||
create(:application_form, awarded_at: 100.days.ago) | ||
end | ||
let!(:application_declined_old) do | ||
create(:application_form, declined_at: 100.days.ago) | ||
end | ||
let!(:application_withdrawn_old) do | ||
create(:application_form, withdrawn_at: 100.days.ago) | ||
end | ||
|
||
context "the params does not include display" do | ||
let(:params) { {} } | ||
let(:scope) { ApplicationForm.all } | ||
|
||
it "includes recent applications and excludes old ones" do | ||
expect(filtered_scope).to include( | ||
application_awarded_recently, | ||
application_declined_recently, | ||
application_withdrawn_recently, | ||
) | ||
|
||
expect(filtered_scope).not_to include( | ||
application_awarded_old, | ||
application_declined_old, | ||
application_withdrawn_old, | ||
) | ||
end | ||
end | ||
|
||
context "the params does not include 'show_all' under display" do | ||
let(:params) { { show_all: nil } } | ||
let(:scope) { ApplicationForm.all } | ||
|
||
it "includes recent applications and excludes old ones" do | ||
expect(filtered_scope).to include( | ||
application_awarded_recently, | ||
application_declined_recently, | ||
application_withdrawn_recently, | ||
) | ||
|
||
expect(filtered_scope).not_to include( | ||
application_awarded_old, | ||
application_declined_old, | ||
application_withdrawn_old, | ||
) | ||
end | ||
end | ||
|
||
context "the params does include 'show_all' but not true under display" do | ||
let(:params) { { show_all: "true" } } | ||
let(:scope) { double } | ||
|
||
it { is_expected.to eq(scope) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
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 | ||
|
@@ -12,6 +13,9 @@ | |
it "applies the filters" do | ||
when_i_visit_the(:assessor_applications_page) | ||
|
||
when_i_clear_the_filters | ||
then_i_see_applications_in_the_last_90_days | ||
|
||
when_i_clear_the_filters | ||
and_i_apply_the_assessor_filter | ||
then_i_see_a_list_of_applications_filtered_by_assessor | ||
|
@@ -43,6 +47,10 @@ | |
when_i_clear_the_filters | ||
and_i_apply_the_stage_filter | ||
then_i_see_a_list_of_applications_filtered_by_stage | ||
|
||
when_i_clear_the_filters | ||
and_i_apply_the_show_all_filter | ||
then_i_see_a_list_of_all_applications | ||
end | ||
|
||
private | ||
|
@@ -59,6 +67,10 @@ def when_i_clear_the_filters | |
assessor_applications_page.clear_filters.click | ||
end | ||
|
||
def then_i_see_applications_in_the_last_90_days | ||
expect(assessor_applications_page.search_results.count).to eq(4) | ||
end | ||
|
||
def and_i_apply_the_assessor_filter | ||
expect(assessor_applications_page.assessor_filter.assessors.count).to eq(3) | ||
assessor_applications_page.assessor_filter.assessors.first.checkbox.click | ||
|
@@ -121,9 +133,16 @@ def then_i_see_a_list_of_applications_filtered_by_email | |
end | ||
|
||
def and_i_apply_the_submitted_at_filter | ||
assessor_applications_page.submitted_at_filter.start_day.set(1) | ||
assessor_applications_page.submitted_at_filter.start_month.set(1) | ||
assessor_applications_page.submitted_at_filter.start_year.set(2020) | ||
ten_days_ago = 10.days.ago | ||
assessor_applications_page.submitted_at_filter.start_day.set( | ||
ten_days_ago.day, | ||
) | ||
assessor_applications_page.submitted_at_filter.start_month.set( | ||
ten_days_ago.month, | ||
) | ||
assessor_applications_page.submitted_at_filter.start_year.set( | ||
ten_days_ago.year, | ||
) | ||
assessor_applications_page.apply_filters.click | ||
end | ||
|
||
|
@@ -170,6 +189,21 @@ def then_i_see_a_list_of_applications_filtered_by_stage | |
) | ||
end | ||
|
||
def and_i_apply_the_show_all_filter | ||
show_all = | ||
assessor_applications_page.show_all_filter.items.find do |item| | ||
item.label.text == "Show applications completed older than 90 days ago" | ||
rescue Capybara::ElementNotFound | ||
false | ||
end | ||
show_all.checkbox.click | ||
assessor_applications_page.apply_filters.click | ||
end | ||
|
||
def then_i_see_a_list_of_all_applications | ||
expect(assessor_applications_page.search_results.count).to eq(5) | ||
end | ||
|
||
def application_forms | ||
@application_forms ||= [ | ||
create( | ||
|
@@ -179,7 +213,7 @@ def application_forms | |
given_names: "Cher", | ||
family_name: "Bert", | ||
assessor: assessors.second, | ||
submitted_at: Date.new(2019, 12, 1), | ||
submitted_at: 2.months.ago, | ||
reference: "CHERBERT", | ||
), | ||
create( | ||
|
@@ -190,7 +224,7 @@ def application_forms | |
given_names: "Emma", | ||
family_name: "Dubois", | ||
assessor: assessors.second, | ||
submitted_at: Date.new(2019, 12, 1), | ||
submitted_at: 2.months.ago, | ||
teacher: create(:teacher, email: "[email protected]"), | ||
), | ||
create( | ||
|
@@ -201,18 +235,30 @@ def application_forms | |
given_names: "Arnold", | ||
family_name: "Drummond", | ||
assessor: assessors.first, | ||
submitted_at: Date.new(2019, 12, 1), | ||
submitted_at: 2.months.ago, | ||
), | ||
create( | ||
:application_form, | ||
:awarded, | ||
awarded_at: 2.days.ago, | ||
region: create(:region, country: create(:country, code: "PT")), | ||
given_names: "John", | ||
family_name: "Smith", | ||
assessor: assessors.second, | ||
submitted_at: Date.new(2020, 1, 1), | ||
submitted_at: 10.days.ago, | ||
), | ||
create( | ||
:application_form, | ||
:awarded, | ||
awarded_at: 6.months.ago, | ||
region: create(:region, country: create(:country, code: "DE")), | ||
given_names: "Nick", | ||
family_name: "Johnson", | ||
assessor: assessors.second, | ||
submitted_at: 7.months.ago, | ||
), | ||
] | ||
@application_forms | ||
end | ||
|
||
def assessors | ||
|
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