mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[UnitTests][Filter] Change to use course_id instead of course_code
This commit is contained in:
@@ -7,19 +7,28 @@ import { createCourse, createStudent } from '@oodikone/shared/test/utils'
|
||||
|
||||
const { courseFilter } = await import('@/components/FilterView/filters/courses')
|
||||
|
||||
const TKT001_GROUP = 'group-tkt001'
|
||||
const TKT002_ID = 'course-tkt002'
|
||||
const TKT002_GROUP = 'group-tkt002'
|
||||
const TKT003_ID = 'course-tkt003'
|
||||
const TKT003_GROUP = 'group-tkt003'
|
||||
|
||||
const baseOptions = () => ({
|
||||
courseFilters: {},
|
||||
courses: {},
|
||||
substitutedBy: {},
|
||||
includeSubstitutions: true,
|
||||
idToGroupIdMap: {},
|
||||
})
|
||||
|
||||
const baseArgs = () => ({ courses: [], idToGroupIdMap: {} })
|
||||
|
||||
void describe('courseFilter', () => {
|
||||
void it('should keep every student when no course filters are selected', () => {
|
||||
const student = createStudent()
|
||||
|
||||
const result = courseFilter().filter(student, {
|
||||
args: { courses: [] },
|
||||
args: baseArgs(),
|
||||
options: baseOptions(),
|
||||
precomputed: undefined,
|
||||
})
|
||||
@@ -28,11 +37,15 @@ void describe('courseFilter', () => {
|
||||
})
|
||||
|
||||
void it('should include a student who passed the course when filtering for PASSED', () => {
|
||||
const student = createStudent({ courses: [createCourse({ course_code: 'TKT002', passed: true })] })
|
||||
const student = createStudent({ courses: [createCourse({ course_id: TKT002_ID, passed: true })] })
|
||||
|
||||
const result = courseFilter().filter(student, {
|
||||
args: { courses: [] },
|
||||
options: { ...baseOptions(), courseFilters: { TKT002: FilterType.PASSED } },
|
||||
args: baseArgs(),
|
||||
options: {
|
||||
...baseOptions(),
|
||||
courseFilters: { [TKT002_GROUP]: FilterType.PASSED },
|
||||
idToGroupIdMap: { [TKT002_ID]: TKT002_GROUP },
|
||||
},
|
||||
precomputed: undefined,
|
||||
})
|
||||
|
||||
@@ -43,8 +56,8 @@ void describe('courseFilter', () => {
|
||||
const student = createStudent({ courses: [] })
|
||||
|
||||
const result = courseFilter().filter(student, {
|
||||
args: { courses: [] },
|
||||
options: { ...baseOptions(), courseFilters: { TKT002: FilterType.PASSED } },
|
||||
args: baseArgs(),
|
||||
options: { ...baseOptions(), courseFilters: { [TKT002_GROUP]: FilterType.PASSED } },
|
||||
precomputed: undefined,
|
||||
})
|
||||
|
||||
@@ -53,12 +66,16 @@ void describe('courseFilter', () => {
|
||||
|
||||
void it('should include a student who failed the course when filtering for FAILED', () => {
|
||||
const student = createStudent({
|
||||
courses: [createCourse({ course_code: 'TKT002', passed: false, credittypecode: CreditTypeCode.FAILED })],
|
||||
courses: [createCourse({ course_id: TKT002_ID, passed: false, credittypecode: CreditTypeCode.FAILED })],
|
||||
})
|
||||
|
||||
const result = courseFilter().filter(student, {
|
||||
args: { courses: [] },
|
||||
options: { ...baseOptions(), courseFilters: { TKT002: FilterType.FAILED } },
|
||||
args: baseArgs(),
|
||||
options: {
|
||||
...baseOptions(),
|
||||
courseFilters: { [TKT002_GROUP]: FilterType.FAILED },
|
||||
idToGroupIdMap: { [TKT002_ID]: TKT002_GROUP },
|
||||
},
|
||||
precomputed: undefined,
|
||||
})
|
||||
|
||||
@@ -68,14 +85,18 @@ void describe('courseFilter', () => {
|
||||
void it('should include a student who failed and passed the course when filtering for PASSED', () => {
|
||||
const student = createStudent({
|
||||
courses: [
|
||||
createCourse({ course_code: 'TKT002', passed: false, credittypecode: CreditTypeCode.FAILED }),
|
||||
createCourse({ course_code: 'TKT003', passed: true, credittypecode: CreditTypeCode.PASSED }),
|
||||
createCourse({ course_id: TKT002_ID, passed: false, credittypecode: CreditTypeCode.FAILED }),
|
||||
createCourse({ course_id: TKT003_ID, passed: true, credittypecode: CreditTypeCode.PASSED }),
|
||||
],
|
||||
})
|
||||
|
||||
const result = courseFilter().filter(student, {
|
||||
args: { courses: [] },
|
||||
options: { ...baseOptions(), courseFilters: { TKT003: FilterType.PASSED } },
|
||||
args: baseArgs(),
|
||||
options: {
|
||||
...baseOptions(),
|
||||
courseFilters: { [TKT003_GROUP]: FilterType.PASSED },
|
||||
idToGroupIdMap: { [TKT002_ID]: TKT002_GROUP, [TKT003_ID]: TKT003_GROUP },
|
||||
},
|
||||
precomputed: undefined,
|
||||
})
|
||||
|
||||
@@ -85,14 +106,18 @@ void describe('courseFilter', () => {
|
||||
void it('should exclude a student who failed and passed the course when filtering for FAILED', () => {
|
||||
const student = createStudent({
|
||||
courses: [
|
||||
createCourse({ course_code: 'TKT002', passed: false, credittypecode: CreditTypeCode.FAILED }),
|
||||
createCourse({ course_code: 'TKT003', passed: true, credittypecode: CreditTypeCode.PASSED }),
|
||||
createCourse({ course_id: TKT002_ID, passed: false, credittypecode: CreditTypeCode.FAILED }),
|
||||
createCourse({ course_id: TKT003_ID, passed: true, credittypecode: CreditTypeCode.PASSED }),
|
||||
],
|
||||
})
|
||||
|
||||
const result = courseFilter().filter(student, {
|
||||
args: { courses: [] },
|
||||
options: { ...baseOptions(), courseFilters: { TKT002: FilterType.FAILED } },
|
||||
args: baseArgs(),
|
||||
options: {
|
||||
...baseOptions(),
|
||||
courseFilters: { [TKT002_GROUP]: FilterType.FAILED },
|
||||
idToGroupIdMap: { [TKT002_ID]: TKT002_GROUP, [TKT003_ID]: TKT003_GROUP },
|
||||
},
|
||||
precomputed: undefined,
|
||||
})
|
||||
|
||||
@@ -103,28 +128,30 @@ void describe('courseFilter', () => {
|
||||
const args = {
|
||||
courses: [
|
||||
{
|
||||
id: TKT002_ID,
|
||||
code: 'TKT002',
|
||||
groupId: TKT002_GROUP,
|
||||
name: { fi: 'Testi' },
|
||||
is_study_module: false,
|
||||
substitutions: [],
|
||||
substitution_groups: [['TKT001', 'TKT003']],
|
||||
isStudyModule: false,
|
||||
substitutionGroups: [[TKT001_GROUP, TKT003_GROUP]],
|
||||
},
|
||||
],
|
||||
includeSubstitutions: false,
|
||||
idToGroupIdMap: { [TKT002_ID]: TKT002_GROUP },
|
||||
}
|
||||
const options = baseOptions()
|
||||
|
||||
// Modifies passed options
|
||||
courseFilter().precompute!({ students: [], options, args })
|
||||
|
||||
assert.deepStrictEqual(Object.keys(options.courses), ['TKT002'])
|
||||
assert.deepStrictEqual(Object.keys(options.courses), [TKT002_GROUP])
|
||||
assert.strictEqual(options.includeSubstitutions, false)
|
||||
assert.deepStrictEqual(options.substitutedBy, { TKT002: [['TKT001', 'TKT003']] })
|
||||
assert.deepStrictEqual(options.substitutedBy, { [TKT002_GROUP]: [[TKT001_GROUP, TKT003_GROUP]] })
|
||||
})
|
||||
|
||||
void it('isActive should match filter state', () => {
|
||||
assert.strictEqual(
|
||||
courseFilter().isActive({ ...baseOptions(), courseFilters: { TKT002: FilterType.ALL } }, undefined),
|
||||
courseFilter().isActive({ ...baseOptions(), courseFilters: { [TKT002_GROUP]: FilterType.ALL } }, undefined),
|
||||
true
|
||||
)
|
||||
assert.strictEqual(courseFilter().isActive(baseOptions(), undefined), false)
|
||||
|
||||
@@ -21,8 +21,8 @@ void describe('creditDateFilter', () => {
|
||||
void it('should keep only courses within the selected date range when mutating', () => {
|
||||
const student = createStudent({
|
||||
courses: [
|
||||
createCourse({ course_code: 'TKT-IN', date: new Date('2024-06-01') }),
|
||||
createCourse({ course_code: 'TKT-OUT', date: new Date('2023-01-01') }),
|
||||
createCourse({ course_id: 'TKT-IN', date: new Date('2024-06-01') }),
|
||||
createCourse({ course_id: 'TKT-OUT', date: new Date('2023-01-01') }),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -33,7 +33,7 @@ void describe('creditDateFilter', () => {
|
||||
})
|
||||
|
||||
assert.deepStrictEqual(
|
||||
result.courses.map(({ course_code }) => course_code),
|
||||
result.courses.map(({ course_id }) => course_id),
|
||||
['TKT-IN']
|
||||
)
|
||||
})
|
||||
@@ -41,8 +41,8 @@ void describe('creditDateFilter', () => {
|
||||
void it('should keep only enrollments within the selected date range when mutating', () => {
|
||||
const student = createStudent({
|
||||
enrollments: [
|
||||
createEnrollment({ course_code: 'TKT-IN', enrollment_date_time: new Date('2024-06-01') }),
|
||||
createEnrollment({ course_code: 'TKT-OUT', enrollment_date_time: new Date('2023-01-01') }),
|
||||
createEnrollment({ course_id: 'TKT-IN', enrollment_date_time: new Date('2024-06-01') }),
|
||||
createEnrollment({ course_id: 'TKT-OUT', enrollment_date_time: new Date('2023-01-01') }),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -53,7 +53,7 @@ void describe('creditDateFilter', () => {
|
||||
})
|
||||
|
||||
assert.deepStrictEqual(
|
||||
result.enrollments.map(({ course_code }) => course_code),
|
||||
result.enrollments.map(({ course_id }) => course_id),
|
||||
['TKT-IN']
|
||||
)
|
||||
})
|
||||
|
||||
@@ -4,15 +4,12 @@ import { gradeFilter } from '@/components/FilterView/filters/grade'
|
||||
|
||||
import { createCourse, createStudent } from '@oodikone/shared/test/utils'
|
||||
|
||||
const ARGS = { courseCodes: ['TKT002'], from: '2024-01-01', to: '2024-12-31' }
|
||||
const ARGS = { courseIds: ['TKT002'], from: '2024-01-01', to: '2024-12-31' }
|
||||
|
||||
void describe('gradeFilter', () => {
|
||||
void it('should group student numbers by their highest grade for the given courses', () => {
|
||||
const student = createStudent({
|
||||
courses: [
|
||||
createCourse({ course_code: 'TKT002', grade: '5' }),
|
||||
createCourse({ course_code: 'TKT002', grade: '3' }),
|
||||
],
|
||||
courses: [createCourse({ course_id: 'TKT002', grade: '5' }), createCourse({ course_id: 'TKT002', grade: '3' })],
|
||||
})
|
||||
|
||||
const precomputed = gradeFilter().precompute!({ students: [student], options: { selected: [] }, args: ARGS })
|
||||
@@ -22,7 +19,7 @@ void describe('gradeFilter', () => {
|
||||
|
||||
void it('should ignore courses outside the requested date range', () => {
|
||||
const student = createStudent({
|
||||
courses: [createCourse({ course_code: 'TKT002', grade: '5', date: new Date('2023-01-01') })],
|
||||
courses: [createCourse({ course_id: 'TKT002', grade: '5', date: new Date('2023-01-01') })],
|
||||
})
|
||||
|
||||
const precomputed = gradeFilter().precompute!({ students: [student], options: { selected: [] }, args: ARGS })
|
||||
@@ -43,7 +40,7 @@ void describe('gradeFilter', () => {
|
||||
})
|
||||
|
||||
void it('should exclude a student whose grade is not selected', () => {
|
||||
const student = createStudent({ courses: [createCourse({ course_code: 'TKT002', grade: '3' })] })
|
||||
const student = createStudent({ courses: [createCourse({ course_id: 'TKT002', grade: '3' })] })
|
||||
|
||||
const result = gradeFilter().filter(student, {
|
||||
args: ARGS,
|
||||
|
||||
Reference in New Issue
Block a user