[UnitTests] Add studyTrackFilter tests

This commit is contained in:
Aaro Koivukangas
2026-08-20 10:01:10 +03:00
parent bf6a4837df
commit d904afd07c
@@ -0,0 +1,63 @@
import { assert, describe, it } from 'vitest'
import { StudentStudyRight } from '@oodikone/shared/types/studentData'
import { createStudent, createStudyRight as createBaseStudyRight, createStudyRightElement } from './helpers'
const { studyTrackFilter } = await import('@/components/FilterView/filters/studyTrack')
const createStudyRight = (overrides: Partial<StudentStudyRight> = {}): StudentStudyRight =>
createBaseStudyRight({
studyRightElements: [
createStudyRightElement({
code: 'KH50_001',
studyTrack: { code: 'track-1', name: { fi: 'Testisuuntautuminen' } },
}),
],
...overrides,
})
const ARGS = { code: 'KH50_001' }
void describe('studyTrackFilter', () => {
void it('should include student when the student is in one of the selected study tracks', () => {
const student = createStudent({ studyRights: [createStudyRight()] })
const result = studyTrackFilter().filter(student, {
args: ARGS,
options: { selected: ['track-1'], studyTracks: [] },
precomputed: undefined,
})
assert.strictEqual(result, true)
})
void it('should exclude student when the student is not in any of the selected study tracks', () => {
const student = createStudent({ studyRights: [createStudyRight()] })
const result = studyTrackFilter().filter(student, {
args: ARGS,
options: { selected: ['track-2'], studyTracks: [] },
precomputed: undefined,
})
assert.strictEqual(result, false)
})
void it('should exclude student when the study right does not match the given programme code', () => {
const student = createStudent({ studyRights: [createStudyRight()] })
const result = studyTrackFilter().filter(student, {
args: { code: 'OTHER' },
options: { selected: ['track-1'], studyTracks: [] },
precomputed: undefined,
})
assert.strictEqual(result, false)
})
void it('isActive should match the filter state', () => {
assert.strictEqual(studyTrackFilter().isActive({ selected: [], studyTracks: [] }, undefined), false)
assert.strictEqual(studyTrackFilter().isActive({ selected: ['track-1'], studyTracks: [] }, undefined), true)
})
})