Files
agent-desktop/console/src/os/useElementWidth.test.ts
T
Pine ae3ab5feb5 阶段5: 完整引入上游 OS Shell + Hub + Mailbox
- os/ 67 文件(DesktopOS/Dock/Launcher/MenuBar/MissionControl/NotificationCenter/AppStore/Window 系统 + os*Store/hooks)
- pages/Hub + api/modules/hub.ts + ImportHubModal(已有)
- Inbox 采用上游 Mailbox(approvals/messages 双 Tab + MailAccessControlDrawer/useMailPendingCount/mailDetail),保留云超服 Harvest 组件
- App.tsx 引入 OS Shell 分支(isOsPath→DesktopOSPage, Router 外)+ /hub/admin 路由 + BackendModeRouter + RuntimeAvailabilityGuard,保留云超服 AuthGuard/chatSocket/OPC 主题/vi-th-my-lo
- 双改合并:usePluginLoader(loadPawApp)/pluginMarket(isMarketPluginApp)/registry store(removeBySource)/hostExternals(removePlugin)/LanguageSwitcher(persistRemotely+ja-ru-pt-id)/BackendLoadingPage(override props)/ApprovalCard(reasoning)/auth.ts(mode)/auth/gate.ts
- SidebarSettingsPanel 加 Desktop Mode 入口(OS Shell 切换)
- locales 合并 os/hub/projectDirectory/inbox/account(zh/en/vi 用上游,lo/my/th 用 en 占位)
- 验证:tsc 0 错误、build 通过(1m23s)、阶段5 新增 35 文件 271 测试全过;全量回归 30 失败均预存在(stash 验证)
2026-09-04 10:36:41 +08:00

54 lines
1.4 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { useElementWidth } from "./useElementWidth";
type ROCallback = (entries: { contentRect: { width: number } }[]) => void;
let lastCallback: ROCallback | null = null;
const observe = vi.fn();
const disconnect = vi.fn();
beforeEach(() => {
lastCallback = null;
observe.mockClear();
disconnect.mockClear();
vi.stubGlobal(
"ResizeObserver",
class {
constructor(cb: ROCallback) {
lastCallback = cb;
}
observe = observe;
disconnect = disconnect;
},
);
});
afterEach(() => {
vi.unstubAllGlobals();
});
describe("useElementWidth", () => {
it("returns null before any measurement", () => {
const { result } = renderHook(() => useElementWidth(null));
expect(result.current).toBeNull();
});
it("observes the element and reports rounded widths", () => {
const el = document.createElement("div");
const { result } = renderHook(() => useElementWidth(el));
expect(observe).toHaveBeenCalledWith(el);
act(() => {
lastCallback?.([{ contentRect: { width: 733.6 } }]);
});
expect(result.current).toBe(734);
});
it("disconnects on unmount", () => {
const el = document.createElement("div");
const { unmount } = renderHook(() => useElementWidth(el));
unmount();
expect(disconnect).toHaveBeenCalled();
});
});