- Shrimp.ts (875 行) 按类拆分到 Shrimp/(7 文件: Shrimp, ShrimpModule, ShrimpTableModule, ShrimpPower, ShrimpCrud, UserRoleModule, OperationLogModule) - forMongo/: MongoShrimpCrud + MongoShrimp(原 ShrimpServer 的 mongo 装配部分,无 express) - forExpress/: buildShrimpRouter + jwtAuth + types - main/: index(0 依赖核心) + expmon(express+mongo 整合,导出 ShrimpServer) + types(纯协议) - 入口子路径 server → expmon(express+mongo 整合方案命名更准确) - 删除冗余的 index.ts / core.ts(合并为 main/index.ts)
28 lines
1.2 KiB
TypeScript
28 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest"
|
|
import { Shrimp, ShrimpTableModule, MemoryShrimpCrud, UserModule, RoleModule } from "../src/main"
|
|
|
|
describe("Shrimp.getMenuTree", () => {
|
|
it("返回的 label 等于模块注册时声明的 label", () => {
|
|
const shrimp = new Shrimp()
|
|
new ShrimpTableModule(shrimp, "tag", new MemoryShrimpCrud(), [], "标签管理")
|
|
new ShrimpTableModule(shrimp, "product", new MemoryShrimpCrud(), [], { t: "product.menuManage" })
|
|
|
|
const tree = shrimp.getMenuTree()
|
|
|
|
expect(tree).toEqual([
|
|
{ name: "tag", label: "标签管理", moduleKey: "tag" },
|
|
{ name: "product", label: { t: "product.menuManage" }, moduleKey: "product" },
|
|
])
|
|
})
|
|
|
|
it("内置 UserModule / RoleModule 的菜单 label 用 user.menuManage / role.menuManage", () => {
|
|
const shrimp = new Shrimp()
|
|
new UserModule(shrimp, new MemoryShrimpCrud() as any)
|
|
new RoleModule(shrimp, new MemoryShrimpCrud() as any)
|
|
|
|
const tree = shrimp.getMenuTree()
|
|
expect(tree.find(m => m.moduleKey === "user")?.label).toEqual({ t: "user.menuManage" })
|
|
expect(tree.find(m => m.moduleKey === "role")?.label).toEqual({ t: "role.menuManage" })
|
|
})
|
|
})
|