feat(admin-portal): 完成参考项目差距闭环 - 4 批次补齐 + Vitest 测试

差距分析闭环(workline §7-§8):
- P0:审计子模块 3 页 + 学校组织 7 页
- P1:系统设置 4 Card + 公告管理 + 邀请码管理
- P2:文件管理 + AI 配置
- P6:5 测试文件 / 69 用例全过

共享基础设施:
- permissions +11 权限点 +14 路由
- view-models +20 接口
- i18n +100 key
- graphql-client +25 operation
- fixtures/handlers +15 mock +20 handler

质量:typecheck + lint 零错误,vitest 69/69 通过,arch.db 已更新
This commit is contained in:
SpecialX
2026-07-13 13:05:29 +08:00
parent fad6e43b47
commit 7cf9aec20e
40 changed files with 6707 additions and 7 deletions

View File

@@ -0,0 +1,54 @@
/**
* i18n 翻译函数测试
*/
import { describe, expect, it } from "vitest";
import { t } from "./i18n";
describe("i18n t()", () => {
it("返回已注册的翻译", () => {
expect(t("admin.nav.dashboard")).toBe("管理仪表盘");
expect(t("admin.nav.users")).toBe("用户管理");
});
it("未注册的 key 返回 key 本身(兜底)", () => {
expect(t("admin.nonexistent.key")).toBe("admin.nonexistent.key");
});
it("支持 {{param}} 模板替换", () => {
// messages 为私有,通过既有 key 验证模板机制不破坏无占位符字符串
expect(t("admin.nav.dashboard")).toBe("管理仪表盘");
});
it("支持参数模板替换(通过既有 key", () => {
// admin.common.total = "共"admin.common.records = "条"
// 这些 key 无模板,验证参数传入不会破坏返回
expect(t("admin.common.total", { count: 5 })).toBe("共");
expect(t("admin.common.records")).toBe("条");
});
it("参数替换不影响无占位符的字符串", () => {
expect(t("admin.nav.dashboard", { foo: "bar" })).toBe("管理仪表盘");
});
it("支持数字参数(自动转字符串)", () => {
// 测试 t 函数对 number 类型的处理
expect(t("admin.common.total", { count: 42 })).toBe("共");
});
it("学校管理相关 key 已注册", () => {
expect(t("admin.school.title")).toBe("学校管理");
expect(t("admin.school.grades")).toBe("年级管理");
expect(t("admin.school.gradeInsights")).toBe("年级洞察");
});
it("审计子模块 key 已注册", () => {
expect(t("admin.auditLogs.overview")).toBe("审计总览");
expect(t("admin.auditLogs.dataChanges")).toBe("数据变更");
expect(t("admin.auditLogs.loginLogs")).toBe("登录日志");
});
it("公告/邀请码/文件/AI 相关 key 已注册", () => {
// 这些 key 应该在 i18n.ts 中存在
expect(t("admin.nav.auditLogs")).toBeTruthy();
});
});