- 移除所有废弃的旧首页配置模块,包括destinationHero、demand相关、HomeExperience、vehicleService等表结构与代码,新增数据库迁移删除遗留表 - 重构管理端后台布局为标准RuoYi风格,新增Sidebar、Navbar、SettingsDrawer等组件,替换旧的过渡菜单实现 - 调整移动端响应断点为768px,更新布局相关测试用例,新增布局组件测试 - 删除OperationsTools发布/重置页面,移除/tools菜单入口,清理对应的API调用与测试代码 - 重构玩法模块编辑器:替换旧的图片手动输入框为图片上传组件,移除冗余的取消按钮 - 新增线索查询offset参数支持,完善查询参数处理逻辑 - 优化rbac菜单构建逻辑,新增可见性控制参数 - 修正管家编辑器提示文案,优化系统资源编辑器表单初始化逻辑 - 清理小程序端废弃的体验推荐组件与相关测试代码 - 更新文档与种子脚本,匹配新的API契约与使用说明
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { createPinia, setActivePinia } from "pinia";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { useLayoutStore } from "./layout";
|
|
|
|
describe("layout store", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it.each([
|
|
[767, "mobile"],
|
|
[768, "desktop"],
|
|
[769, "desktop"],
|
|
] as const)("uses the strict mobile breakpoint at %spx", (width, expectedDevice) => {
|
|
setActivePinia(createPinia());
|
|
const store = useLayoutStore();
|
|
|
|
store.syncViewport(width);
|
|
|
|
expect(store.device).toBe(expectedDevice);
|
|
expect(store.sidebarOpened).toBe(expectedDevice === "desktop");
|
|
});
|
|
|
|
it("is safe to use without window", () => {
|
|
setActivePinia(createPinia());
|
|
const store = useLayoutStore();
|
|
|
|
expect(() => store.syncViewport()).not.toThrow();
|
|
expect(() => store.startViewportWatcher()).not.toThrow();
|
|
expect(store.device).toBe("desktop");
|
|
});
|
|
|
|
it("registers one resize watcher, updates on resize, and unsubscribes idempotently", () => {
|
|
const addEventListener = vi.fn();
|
|
const removeEventListener = vi.fn();
|
|
const browserWindow = { innerWidth: 993, addEventListener, removeEventListener };
|
|
vi.stubGlobal("window", browserWindow);
|
|
setActivePinia(createPinia());
|
|
const store = useLayoutStore();
|
|
|
|
const stop = store.startViewportWatcher();
|
|
const sameStop = store.startViewportWatcher();
|
|
const resizeHandler = addEventListener.mock.calls[0][1] as () => void;
|
|
|
|
expect(sameStop).toBe(stop);
|
|
expect(addEventListener).toHaveBeenCalledTimes(1);
|
|
expect(store.device).toBe("desktop");
|
|
|
|
browserWindow.innerWidth = 767;
|
|
resizeHandler();
|
|
expect(store.device).toBe("mobile");
|
|
expect(store.sidebarOpened).toBe(false);
|
|
|
|
stop();
|
|
stop();
|
|
expect(removeEventListener).toHaveBeenCalledTimes(1);
|
|
|
|
browserWindow.innerWidth = 993;
|
|
resizeHandler();
|
|
expect(store.device).toBe("mobile");
|
|
});
|
|
|
|
it("controls the sidebar and animation flag independently", () => {
|
|
setActivePinia(createPinia());
|
|
const store = useLayoutStore();
|
|
|
|
store.toggleSidebar({ withoutAnimation: true });
|
|
expect(store.sidebarOpened).toBe(false);
|
|
expect(store.withoutAnimation).toBe(true);
|
|
|
|
store.openSidebar({ withoutAnimation: false });
|
|
expect(store.sidebarOpened).toBe(true);
|
|
expect(store.withoutAnimation).toBe(false);
|
|
|
|
store.closeSidebar();
|
|
expect(store.sidebarOpened).toBe(false);
|
|
expect(store.withoutAnimation).toBe(false);
|
|
});
|
|
});
|