Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PART 1 - Add secondary filter to the v2 results page #4789

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/find/v2/results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def search_courses_params
:applications_open,
:further_education,
:funding,
subjects: [],
study_types: [],
qualifications: [],
funding: []
Expand Down
8 changes: 8 additions & 0 deletions app/forms/search_courses_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SearchCoursesForm < ApplicationForm
include ActiveModel::Attributes

attribute :can_sponsor_visa, :boolean
attribute :subjects
attribute :send_courses, :boolean
attribute :applications_open, :boolean
attribute :study_types
Expand All @@ -14,4 +15,11 @@ class SearchCoursesForm < ApplicationForm
def search_params
attributes.symbolize_keys.compact
end

def secondary_subjects
Subject
.where(type: %w[SecondarySubject ModernLanguagesSubject])
.where.not(subject_name: ['Modern Languages'])
.order(:subject_name)
end
end
9 changes: 9 additions & 0 deletions app/services/courses_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(params:)

def call
@scope = visa_sponsorship_scope
@scope = subjects_scope
@scope = study_modes_scope
@scope = qualifications_scope
@scope = further_education_scope
Expand Down Expand Up @@ -53,6 +54,14 @@ def visa_sponsorship_scope
)
end

def subjects_scope
return @scope if params[:subjects].blank?

@applied_scopes[:subjects] = params[:subjects]

@scope.joins(:subjects).where(subjects: { subject_code: params[:subjects] })
end

def study_modes_scope
return @scope if params[:study_types].blank?

Expand Down
4 changes: 4 additions & 0 deletions app/views/find/v2/results/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<%= form.govuk_check_box :can_sponsor_visa, "true", multiple: false, label: { text: t("helpers.label.courses_query_filters.can_sponsor_visa"), size: "s" } %>
<% end %>

<%= form.govuk_check_boxes_fieldset :subjects, legend: { text: t("helpers.legend.courses_query_filters.secondary_html"), size: "s" }, hint: { text: t("helpers.hint.courses_query_filters.secondary"), class: "govuk-!-font-size-16" }, class: "app-filter__group", hidden: false, multiple: false, form_group: { class: "app-filter__group" } do %>
<%= form.govuk_collection_check_boxes :subjects, form.object.secondary_subjects, :subject_code, :subject_name, legend: nil, include_hidden: false, small: true %>
<% end %>

<%= form.govuk_check_boxes_fieldset :study_types, legend: { text: t("helpers.legend.courses_query_filters.study_type_html"), size: "s" }, class: "app-filter__group govuk-checkboxes--small", multiple: false, form_group: { class: "app-filter__group" } do %>
<%= form.govuk_check_box :study_types, "full_time", label: { text: t("helpers.label.courses_query_filters.study_type_options.full_time"), size: "s" }, include_hidden: false %>
<%= form.govuk_check_box :study_types, "part_time", label: { text: t("helpers.label.courses_query_filters.study_type_options.part_time"), size: "s" }, include_hidden: false %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/find.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ en:
legend:
courses_query_filters:
can_sponsor_visa_html: Visa sponsorship<span class="govuk-visually-hidden"> filter</span>
secondary_html: Secondary<span class="govuk-visually-hidden"> filter</span>
study_type_html: Study type<span class="govuk-visually-hidden"> filter</span>
qualifications_html: Qualification awarded<span class="govuk-visually-hidden"> filter</span>
further_education_html: Further education<span class="govuk-visually-hidden"> filter</span>
Expand All @@ -322,6 +323,7 @@ en:
hint:
courses_query_filters:
further_education: (ages 16 and over)
secondary: (ages 11 to 18)
label:
courses_query_filters:
can_sponsor_visa: Only show courses with visa sponsorship
Expand Down
180 changes: 130 additions & 50 deletions spec/features/find/v2/results/search_results_enabled_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,37 @@
end
end

context 'when filter by secondary subjects' do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nitemaeric I added to the features folder for now. I will move everything to system spec in another PR not this one. And divide the filters also in the future PR.

before do
given_there_are_courses_with_secondary_subjects
end

scenario 'filter by specific secondary subjects' do
when_i_visit_the_find_results_page
and_i_filter_by_mathematics
then_i_see_only_mathematics_courses
and_the_mathematics_secondary_option_is_checked
and_i_see_that_there_is_one_course_found
end

scenario 'filter by many secondary subjects' do
when_i_visit_the_find_results_page
and_i_filter_by_mathematics
and_i_filter_by_chemistry
then_i_see_mathematics_and_chemistry_courses
and_the_mathematics_secondary_option_is_checked
and_the_chemistry_secondary_option_is_checked
and_i_see_that_there_are_two_courses_found
end

scenario 'passing subjects on the parameters' do
when_i_visit_the_find_results_page_passing_mathematics_in_the_params
then_i_see_only_mathematics_courses
and_the_mathematics_secondary_option_is_checked
and_i_see_that_there_is_one_course_found
end
end

scenario 'when no results' do
when_i_visit_the_find_results_page
then_i_see_no_courses_found
Expand All @@ -147,6 +178,13 @@ def given_there_are_courses_containing_all_study_types
create(:course, :with_full_time_or_part_time_sites, study_mode: 'full_time_or_part_time', name: 'Computing', course_code: 'L364')
end

def given_there_are_courses_with_secondary_subjects
create(:course, :with_full_time_sites, :secondary, name: 'Biology', course_code: 'S872', subjects: [find_or_create(:secondary_subject, :biology)])
create(:course, :with_full_time_sites, :secondary, name: 'Chemistry', course_code: 'K592', subjects: [find_or_create(:secondary_subject, :chemistry)])
create(:course, :with_full_time_sites, :secondary, name: 'Computing', course_code: 'L364', subjects: [find_or_create(:secondary_subject, :computing)])
create(:course, :with_full_time_sites, :secondary, name: 'Mathematics', course_code: '4RTU', subjects: [find_or_create(:secondary_subject, :mathematics)])
end

def given_there_are_courses_containing_all_qualifications
create(:course, :with_full_time_sites, qualification: 'qts', name: 'Biology', course_code: 'S872')
create(:course, :with_full_time_sites, qualification: 'pgce_with_qts', name: 'Chemistry', course_code: 'K592')
Expand Down Expand Up @@ -202,11 +240,25 @@ def when_i_visit_the_find_results_page_using_old_salary_parameter
visit(find_v2_results_path(funding: 'salary'))
end

def when_i_visit_the_find_results_page_passing_mathematics_in_the_params
visit(find_v2_results_path(subjects: ['G1']))
end

def and_i_filter_by_courses_that_sponsor_visa
check 'Only show courses with visa sponsorship'
and_i_apply_the_filters
end

def and_i_filter_by_mathematics
check 'Mathematics'
and_i_apply_the_filters
end

def and_i_filter_by_chemistry
check 'Chemistry'
and_i_apply_the_filters
end

def and_i_filter_only_by_part_time_courses
uncheck 'Full time (12 months)'
check 'Part time (18 to 24 months)'
Expand Down Expand Up @@ -266,112 +318,112 @@ def and_i_filter_by_apprenticeship_courses
end

def then_i_see_only_courses_that_sponsor_visa
expect(page).to have_content('Biology (S872')
expect(page).to have_content('Chemistry (K592)')
expect(page).to have_content('Computing (L364)')
expect(page).to have_no_content('Dance (C115)')
expect(results).to have_content('Biology (S872')
expect(results).to have_content('Chemistry (K592)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_no_content('Dance (C115)')
end

def then_i_see_only_part_time_courses
expect(page).to have_content('Chemistry (K592)')
expect(page).to have_content('Computing (L364)')
expect(page).to have_no_content('Biology (S872)')
expect(results).to have_content('Chemistry (K592)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_no_content('Biology (S872)')
end

def and_the_part_time_filter_is_checked
expect(page).to have_checked_field('Part time (18 to 24 months)')
end

def then_i_see_only_full_time_courses
expect(page).to have_content('Biology (S872)')
expect(page).to have_content('Computing (L364)')
expect(page).to have_no_content('Chemistry (K592)')
expect(results).to have_content('Biology (S872)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_no_content('Chemistry (K592)')
end

def and_the_full_time_filter_is_checked
expect(page).to have_checked_field('Full time (12 months)')
end

def then_i_see_all_courses_containing_all_study_types
expect(page).to have_content('Biology (S872)')
expect(page).to have_content('Computing (L364)')
expect(page).to have_content('Chemistry (K592)')
expect(results).to have_content('Biology (S872)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_content('Chemistry (K592)')
end

def then_i_see_only_qts_only_courses
expect(page).to have_content('Biology (S872)')
expect(page).to have_no_content('Chemistry (K592)')
expect(page).to have_no_content('Computing (L364)')
expect(page).to have_no_content('Dance (C115)')
expect(page).to have_no_content('Physics (3CXN)')
expect(page).to have_no_content('Mathemathics (4RTU)')
expect(results).to have_content('Biology (S872)')
expect(results).to have_no_content('Chemistry (K592)')
expect(results).to have_no_content('Computing (L364)')
expect(results).to have_no_content('Dance (C115)')
expect(results).to have_no_content('Physics (3CXN)')
expect(results).to have_no_content('Mathemathics (4RTU)')
end

def and_the_qts_only_filter_is_checked
expect(page).to have_checked_field('QTS only')
end

def then_i_see_only_qts_with_pgce_or_pgde_courses
expect(page).to have_content('Chemistry (K592)')
expect(page).to have_content('Computing (L364)')
expect(page).to have_no_content('Biology (S872)')
expect(page).to have_no_content('Dance (C115)')
expect(page).to have_no_content('Physics (3CXN)')
expect(page).to have_no_content('Mathemathics (4RTU)')
expect(results).to have_content('Chemistry (K592)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_no_content('Biology (S872)')
expect(results).to have_no_content('Dance (C115)')
expect(results).to have_no_content('Physics (3CXN)')
expect(results).to have_no_content('Mathemathics (4RTU)')
end

def and_the_qts_with_pgce_or_pgde_filter_is_checked
expect(page).to have_checked_field('QTS with PGCE or PGDE')
end

def then_i_see_only_further_education__courses
expect(page).to have_content('Further education (K594)')
expect(page).to have_no_content('Biology (S872)')
expect(page).to have_no_content('Chemistry (K592)')
expect(results).to have_content('Further education (K594)')
expect(results).to have_no_content('Biology (S872)')
expect(results).to have_no_content('Chemistry (K592)')
end

def and_the_further_education_filter_is_checked
expect(page).to have_checked_field('Only show further education courses')
end

def then_i_see_only_courses_with_special_education_needs
expect(page).to have_content('Biology SEND (S872')
expect(page).to have_content('Chemistry SEND (K592)')
expect(page).to have_content('Computing SEND (L364)')
expect(page).to have_no_content('Dance (C115)')
expect(page).to have_no_content('Physics (3CXN)')
expect(results).to have_content('Biology SEND (S872')
expect(results).to have_content('Chemistry SEND (K592)')
expect(results).to have_content('Computing SEND (L364)')
expect(results).to have_no_content('Dance (C115)')
expect(results).to have_no_content('Physics (3CXN)')
end

def then_i_see_only_salaried_courses
expect(page).to have_content('Chemistry (K592)')
expect(page).to have_no_content('Biology (S872)')
expect(page).to have_no_content('Computing (L364)')
expect(results).to have_content('Chemistry (K592)')
expect(results).to have_no_content('Biology (S872)')
expect(results).to have_no_content('Computing (L364)')
end

def then_i_see_only_fee_courses
expect(page).to have_content('Biology (S872)')
expect(page).to have_no_content('Chemistry (K592)')
expect(page).to have_no_content('Computing (L364)')
expect(results).to have_content('Biology (S872)')
expect(results).to have_no_content('Chemistry (K592)')
expect(results).to have_no_content('Computing (L364)')
end

def then_i_see_fee_and_salaried_courses
expect(page).to have_content('Biology (S872)')
expect(page).to have_content('Chemistry (K592)')
expect(page).to have_no_content('Computing (L364)')
expect(results).to have_content('Biology (S872)')
expect(results).to have_content('Chemistry (K592)')
expect(results).to have_no_content('Computing (L364)')
end

def then_i_see_only_apprenticeship_courses
expect(page).to have_content('Computing (L364)')
expect(page).to have_no_content('Chemistry (K592)')
expect(page).to have_no_content('Biology (S872)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_no_content('Chemistry (K592)')
expect(results).to have_no_content('Biology (S872)')
end

def then_i_see_only_courses_that_are_open_for_applications
expect(page).to have_content('Biology (S872)')
expect(page).to have_content('Chemistry (K592)')
expect(page).to have_content('Computing (L364)')
expect(page).to have_no_content('Dance (C115)')
expect(page).to have_no_content('Physics (3CXN)')
expect(results).to have_content('Biology (S872)')
expect(results).to have_content('Chemistry (K592)')
expect(results).to have_content('Computing (L364)')
expect(results).to have_no_content('Dance (C115)')
expect(results).to have_no_content('Physics (3CXN)')
end

def and_the_visa_sponsorship_filter_is_checked
Expand Down Expand Up @@ -417,8 +469,36 @@ def and_i_see_that_there_are_three_courses_are_found
expect(page).to have_title('3 courses found')
end

def then_i_see_only_mathematics_courses
expect(results).to have_content('Mathematics (4RTU)')
expect(results).to have_no_content('Biology')
expect(results).to have_no_content('Chemistry')
expect(results).to have_no_content('Computing')
end

def then_i_see_mathematics_and_chemistry_courses
expect(results).to have_content('Mathematics')
expect(results).to have_content('Chemistry')
expect(results).to have_no_content('Biology')
expect(results).to have_no_content('Computing')
end

def and_the_mathematics_secondary_option_is_checked
expect(page).to have_checked_field('Mathematics')
end

def and_the_chemistry_secondary_option_is_checked
expect(page).to have_checked_field('Chemistry')
end

def then_i_see_no_courses_found
expect(page).to have_content('No courses found')
expect(page).to have_title('No courses found')
end

private

def results
page.first('.app-search-results')
end
end
21 changes: 21 additions & 0 deletions spec/services/courses_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@
end
end

context 'when filter by secondary subjects' do
let!(:biology) do
create(:course, :with_full_time_sites, :secondary, name: 'Biology', subjects: [find_or_create(:secondary_subject, :biology)])
end
let!(:chemistry) do
create(:course, :with_full_time_sites, :secondary, name: 'Chemistry', subjects: [find_or_create(:secondary_subject, :chemistry)])
end
let!(:mathematics) do
create(:course, :with_full_time_sites, :secondary, name: 'Mathematics', subjects: [find_or_create(:secondary_subject, :mathematics)])
end

let(:params) { { subjects: %w[C1 F1] } }

it 'returns specific secondary courses' do
expect(results).to match_collection(
[biology, chemistry],
attribute_names: %w[name]
)
end
end

context 'when filter by study mode' do
let!(:full_time_course) do
create(:course, :with_full_time_sites, study_mode: 'full_time', name: 'Biology', course_code: 'S872')
Expand Down
Loading