新增服务端菜单校验与归一化逻辑,完善菜单相关Schema;前端实现条件渲染的菜单编辑器,支持搜索式图标选择器与父级树过滤。新增媒体URL统一处理工具修复管理端本地静态资源路径映射问题,更新全部相关文档、技术决策记录与测试用例。本次变更不影响WonderQ-MiniAPP端。
43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildMenuParentTree, getMenuEditorFields, normalizeMenuEditorInput } from "./system-menu-form";
|
|
import type { SystemMenuItem } from "@/types";
|
|
|
|
describe("system menu editor", () => {
|
|
it("shows only fields supported by each menu type", () => {
|
|
expect(getMenuEditorFields("directory")).toEqual({ path: true, component: false, permission: false, icon: true });
|
|
expect(getMenuEditorFields("page")).toEqual({ path: true, component: true, permission: true, icon: true });
|
|
expect(getMenuEditorFields("button")).toEqual({ path: false, component: false, permission: true, icon: false });
|
|
});
|
|
|
|
it("clears route-only values when saving a button menu", () => {
|
|
expect(normalizeMenuEditorInput({
|
|
type: "button",
|
|
path: "/users",
|
|
componentKey: "SystemUsers",
|
|
permissionCode: "system:user:update",
|
|
icon: "User",
|
|
})).toMatchObject({
|
|
path: null,
|
|
componentKey: null,
|
|
permissionCode: "system:user:update",
|
|
icon: null,
|
|
});
|
|
});
|
|
|
|
it("does not offer buttons or the edited branch as a parent", () => {
|
|
const menus = [
|
|
{ id: "root", name: "系统管理", type: "directory", parentId: null, sortOrder: 0 },
|
|
{ id: "users", name: "用户管理", type: "page", parentId: "root", sortOrder: 1 },
|
|
{ id: "user-edit", name: "编辑用户", type: "button", parentId: "users", sortOrder: 1 },
|
|
{ id: "roles", name: "角色管理", type: "page", parentId: "root", sortOrder: 2 },
|
|
] as SystemMenuItem[];
|
|
|
|
const parentTree = buildMenuParentTree(menus, "root");
|
|
expect(parentTree.map((item) => item.id)).toEqual([]);
|
|
|
|
const editParentTree = buildMenuParentTree(menus, "users");
|
|
expect(editParentTree[0].id).toBe("root");
|
|
expect(editParentTree[0].children?.map((item) => item.id)).toEqual(["roles"]);
|
|
});
|
|
});
|