feat: improve admin responsive pages and teacher candidates

This commit is contained in:
2026-07-15 13:56:46 +08:00
parent fb9697bd05
commit d582d641c0
14 changed files with 406 additions and 87 deletions

View File

@@ -0,0 +1,51 @@
import { describe, expect, it } from 'vitest';
import {
buildTeacherCandidateLabel,
buildTeacherCandidateOptions,
isTeacherCandidate,
type TeacherCandidateUser,
} from './teacher-candidate';
const baseUser = (overrides: Partial<TeacherCandidateUser> = {}): TeacherCandidateUser => ({
id: 1,
username: 'teacher',
name: '测试老师',
isActive: true,
isArchived: false,
studentStatus: null,
roles: [{ code: 'teacher', name: '任课老师' }],
profile: { subjects: ['数学', '物理'] },
...overrides,
});
describe('class teacher candidates', () => {
it('keeps non-teacher staff roles because class duty is selected separately', () => {
expect(
isTeacherCandidate(baseUser({ roles: [{ code: 'academic', name: '教务管理员' }] })),
).toBe(true);
});
it('keeps staff-linked accounts so they can serve as head or life teachers', () => {
expect(isTeacherCandidate(baseUser({ studentStatus: 'staff' }))).toBe(true);
});
it('excludes active students, disabled, archived, and super-admin accounts', () => {
const users = [
baseUser({ id: 1, studentStatus: 'active' }),
baseUser({ id: 2, isActive: false }),
baseUser({ id: 3, isArchived: true }),
baseUser({
id: 4,
roles: [{ code: 'super_admin', name: '超级管理员' }],
}),
];
expect(buildTeacherCandidateOptions(users)).toEqual([]);
});
it('shows real name, username, system role, and teaching subjects', () => {
expect(buildTeacherCandidateLabel(baseUser())).toBe(
'测试老师teacher · 任课老师 · 数学/物理',
);
});
});