From bf6a4837df358730ae96348252530c9abfc4b0e5 Mon Sep 17 00:00:00 2001 From: Aaro Koivukangas Date: Thu, 20 Aug 2026 09:58:36 +0300 Subject: [PATCH] [UnitTests] Add studyRightTypeFilter tests --- .../tests/unit/filters/studyRightType.test.ts | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 services/frontend/tests/unit/filters/studyRightType.test.ts diff --git a/services/frontend/tests/unit/filters/studyRightType.test.ts b/services/frontend/tests/unit/filters/studyRightType.test.ts new file mode 100644 index 000000000..d4dfce072 --- /dev/null +++ b/services/frontend/tests/unit/filters/studyRightType.test.ts @@ -0,0 +1,88 @@ +import { assert, describe, it } from 'vitest' + +import { studyRightTypeFilter } from '@/components/FilterView/filters/studyRightType' +import { ExtentCode } from '@oodikone/shared/types' +import { StudentStudyRight } from '@oodikone/shared/types/studentData' + +import { createStudent, createStudyRight as createBaseStudyRight, createStudyRightElement } from './helpers' + +const createStudyRight = (overrides: Partial = {}): StudentStudyRight => + createBaseStudyRight({ studyRightElements: [createStudyRightElement({ code: 'KH50' })], ...overrides }) + +const ARGS = { programme: 'KH50' } + +enum StudyRightMode { + ALL = '0', + BACHELOR_AND_MASTER = '1', + MASTER = '2', +} + +void describe('studyRightTypeFilter', () => { + void it('should include all students when mode is All', () => { + const student = createStudent({ studyRights: [createStudyRight({ extentCode: ExtentCode.MASTER })] }) + + const result = studyRightTypeFilter().filter(student, { + args: ARGS, + options: { mode: StudyRightMode.ALL }, + precomputed: undefined, + }) + + assert.strictEqual(result, true) + }) + + void it('should exclude student when the student has no matching study right', () => { + const student = createStudent({ studyRights: [] }) + + const result = studyRightTypeFilter().filter(student, { + args: ARGS, + options: { mode: StudyRightMode.BACHELOR_AND_MASTER }, + precomputed: undefined, + }) + + assert.strictEqual(result, false) + }) + + void it('should include student with Bachelor + master study right when the filter state is bachelor + master', () => { + const student = createStudent({ + studyRights: [createStudyRight({ extentCode: ExtentCode.BACHELOR_AND_MASTER })], + }) + + const result = studyRightTypeFilter().filter(student, { + args: ARGS, + options: { mode: '1' }, + precomputed: undefined, + }) + + assert.strictEqual(result, true) + }) + + void it('should include student with Master study right when the filter state is master only', () => { + const student = createStudent({ studyRights: [createStudyRight({ extentCode: ExtentCode.MASTER })] }) + + const result = studyRightTypeFilter().filter(student, { + args: ARGS, + options: { mode: StudyRightMode.MASTER }, + precomputed: undefined, + }) + + assert.strictEqual(result, true) + }) + + void it('should exclude student with only Bachelor + master study right when the study right is master only', () => { + const student = createStudent({ studyRights: [createStudyRight({ extentCode: ExtentCode.BACHELOR_AND_MASTER })] }) + + const result = studyRightTypeFilter().filter(student, { + args: ARGS, + options: { mode: StudyRightMode.MASTER }, + precomputed: undefined, + }) + + assert.strictEqual(result, false) + }) + + void it('isActive should match the filter state', () => { + assert.strictEqual(studyRightTypeFilter().isActive({ mode: StudyRightMode.ALL }, undefined), false) + assert.strictEqual(studyRightTypeFilter().isActive({ mode: StudyRightMode.BACHELOR_AND_MASTER }, undefined), true) + assert.strictEqual(studyRightTypeFilter().isActive({ mode: StudyRightMode.MASTER }, undefined), true) + }) +})