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

consider academic year filter when tallying up search results by school. #7711

Merged
merged 1 commit into from
Mar 13, 2024
Merged
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
4 changes: 2 additions & 2 deletions packages/frontend/app/components/global-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class GlobalSearchComponent extends Component {
}

get schoolOptions() {
if (this.results.length && this.schools.length) {
if (this.yearFilteredResults.length && this.schools.length) {
const emptySchools = sortBy(
this.schools.map(({ id, title }) => {
return {
Expand All @@ -74,7 +74,7 @@ export default class GlobalSearchComponent extends Component {
}),
'title',
);
const options = this.results.reduce((set, course) => {
const options = this.yearFilteredResults.reduce((set, course) => {
const schoolOption = findBy(set, 'title', course.school);
schoolOption.results++;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ module('Integration | Component | global-search', function (hooks) {
});

test('academic year filter works properly', async function (assert) {
assert.expect(16);

assert.expect(28);
this.server.create('school', { title: 'Medicine' });
this.server.create('school', { title: 'Pharmacy' });
this.server.get('api/search/v1/curriculum', () => {
return {
results: {
Expand All @@ -82,21 +83,25 @@ module('Integration | Component | global-search', function (hooks) {
title: 'Course 1',
year: 2019,
sessions: [],
school: 'Medicine',
},
{
title: 'Course 2',
year: 2020,
sessions: [],
school: 'Pharmacy',
},
{
title: 'Course 3',
year: 2021,
sessions: [],
school: 'Pharmacy',
},
{
title: 'Course 4',
year: 2021,
sessions: [],
school: 'Medicine',
},
],
},
Expand All @@ -123,18 +128,30 @@ module('Integration | Component | global-search', function (hooks) {
assert.strictEqual(component.searchResults[1].courseTitle, '2020 Course 2');
assert.strictEqual(component.searchResults[2].courseTitle, '2021 Course 3');
assert.strictEqual(component.searchResults[3].courseTitle, '2021 Course 4');
assert.strictEqual(component.schoolFilters.length, 2);
assert.strictEqual(component.schoolFilters[0].school, 'Medicine (2)');
assert.strictEqual(component.schoolFilters[1].school, 'Pharmacy (2)');
await component.selectAcademicYear('2021');
assert.strictEqual(component.searchResults.length, 2);
assert.strictEqual(component.searchResults[0].courseTitle, '2021 Course 3');
assert.strictEqual(component.searchResults[1].courseTitle, '2021 Course 4');
assert.strictEqual(component.schoolFilters.length, 2);
assert.strictEqual(component.schoolFilters[0].school, 'Medicine (1)');
assert.strictEqual(component.schoolFilters[1].school, 'Pharmacy (1)');
await component.selectAcademicYear('2020');
assert.strictEqual(component.academicYear, '2020');
assert.strictEqual(component.searchResults.length, 1);
assert.strictEqual(component.searchResults[0].courseTitle, '2020 Course 2');
assert.strictEqual(component.schoolFilters.length, 2);
assert.strictEqual(component.schoolFilters[0].school, 'Medicine (0)');
assert.strictEqual(component.schoolFilters[1].school, 'Pharmacy (1)');
await component.selectAcademicYear('2019');
assert.strictEqual(component.academicYear, '2019');
assert.strictEqual(component.searchResults.length, 1);
assert.strictEqual(component.searchResults[0].courseTitle, '2019 Course 1');
assert.strictEqual(component.schoolFilters.length, 2);
assert.strictEqual(component.schoolFilters[0].school, 'Medicine (1)');
assert.strictEqual(component.schoolFilters[1].school, 'Pharmacy (0)');
});

test('school filter works properly', async function (assert) {
Expand Down