Skip to content

Commit

Permalink
Merge pull request #7711 from stopfstedt/3226_search_result_filters
Browse files Browse the repository at this point in the history
consider academic year filter when tallying up search results by school.
  • Loading branch information
dartajax authored Mar 13, 2024
2 parents 41551e1 + f5bee11 commit a04ee75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
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

0 comments on commit a04ee75

Please sign in to comment.