import { expect, test, type Page } from "@playwright/test"; import { mockAgentApi } from "./support/mock-agent-api"; test("temporary Agent analysis windows replace and restore the map workspace", async ({ page }) => { await prepareMainFrame(page); await page.goto("/", { waitUntil: "domcontentloaded" }); const frame = page.getByTestId("workbench-main-frame"); const mapWindow = page.locator("#workspace-map"); const testButton = page.getByRole("button", { name: "测试打开 Agent 多图表窗口" }).first(); await expect(frame).toBeVisible(); await expect(mapWindow).toBeVisible(); await expect(testButton).toBeVisible(); await testButton.click(); await expect(page.getByRole("heading", { name: "北辰分区压力异常诊断", exact: true })).toBeVisible(); await expect(mapWindow).toBeHidden(); await testButton.click(); await expect(page.getByRole("heading", { name: "供水服务分区平衡分析", exact: true })).toBeVisible(); await expect(page.getByText("2 / 6 个临时分析窗")).toBeVisible(); await page.getByRole("button", { name: "最小化供水服务分区平衡分析" }).click(); await expect(page.getByRole("button", { name: "恢复供水服务分区平衡分析" })).toBeVisible(); await page.getByRole("button", { name: "恢复供水服务分区平衡分析" }).click(); await expect(page.getByRole("heading", { name: "供水服务分区平衡分析", exact: true })).toBeVisible(); await page.getByRole("button", { name: "关闭并销毁供水服务分区平衡分析" }).click(); await page.getByRole("button", { name: "关闭并销毁北辰分区压力异常诊断" }).click(); await expect(mapWindow).toBeVisible(); await expect(page.getByRole("heading", { name: "北辰分区压力异常诊断", exact: true })).toHaveCount(0); await expect(page.getByText("0 / 6 个临时分析窗")).toBeVisible(); }); test("the map document floats and minimizes to its taskbar entry", async ({ page }) => { await prepareMainFrame(page); await page.goto("/", { waitUntil: "domcontentloaded" }); const workspace = page.locator("#main-workspace"); const mapWindow = page.locator("#workspace-map"); const dockedBox = await workspace.boundingBox(); expect(dockedBox).not.toBeNull(); await page.getByRole("button", { name: "浮动供水管网地图" }).click(); const floatingBox = await mapWindow.boundingBox(); expect(floatingBox).not.toBeNull(); expect(floatingBox!.width).toBeLessThan(dockedBox!.width); expect(floatingBox!.height).toBeLessThan(dockedBox!.height); await expect(page.getByRole("button", { name: "最大化供水管网地图" })).toBeVisible(); await page.getByRole("button", { name: "最小化供水管网地图" }).click(); await expect(mapWindow).toBeHidden(); const restoreTask = page.getByRole("button", { name: "恢复供水管网地图" }); await expect(restoreTask).toBeVisible(); await restoreTask.click(); await expect(mapWindow).toBeVisible(); await expect(page.getByRole("button", { name: "最大化供水管网地图" })).toBeVisible(); }); test("the test control cycles through three trusted document profiles", async ({ page }) => { await prepareMainFrame(page); await page.goto("/", { waitUntil: "domcontentloaded" }); const testButton = page.getByRole("button", { name: "测试打开 Agent 多图表窗口" }).first(); await testButton.click(); await testButton.click(); await testButton.click(); await expect(page.getByRole("heading", { name: "北辰分区压力异常诊断", exact: true })).toBeAttached(); await expect(page.getByRole("heading", { name: "供水服务分区平衡分析", exact: true })).toBeAttached(); await expect(page.getByRole("heading", { name: "低压事件调度处置流程", exact: true })).toBeVisible(); await expect(page.getByText("3 / 6 个临时分析窗")).toBeVisible(); }); test("temporary documents survive a mobile breakpoint round trip", async ({ page }) => { await prepareMainFrame(page); await page.goto("/", { waitUntil: "domcontentloaded" }); await page.getByRole("button", { name: "测试打开 Agent 多图表窗口" }).first().click(); const analysisHeading = page.locator("h2", { hasText: "北辰分区压力异常诊断" }); await expect(analysisHeading).toBeVisible(); await page.setViewportSize({ width: 390, height: 844 }); await expect(page.locator("#workspace-map")).toBeVisible(); await expect(analysisHeading).toBeAttached(); await expect(analysisHeading).toBeHidden(); await page.setViewportSize({ width: 1440, height: 900 }); await expect(analysisHeading).toBeVisible(); await expect(page.locator("#workspace-map")).toBeHidden(); }); async function prepareMainFrame(page: Page) { await mockAgentApi(page); await page.route("**/runtime-config.js", async (route) => { await route.fulfill({ contentType: "application/javascript", body: `globalThis.__TJWATER_CONFIG__ = { TJWATER_AUTH_MODE: "disabled", TJWATER_MAPBOX_ACCESS_TOKEN: "", TJWATER_MAP_URL: "https://workspace-map.invalid/geoserver", TJWATER_GEOSERVER_WORKSPACE: "tjwater", TJWATER_AGENT_API_BASE_URL: "http://127.0.0.1:8787", TJWATER_ENABLE_DEV_PANEL: "true", TJWATER_ENABLE_MSW: "false" };` }); }); await page.route("https://workspace-map.invalid/**", async (route) => { await route.fulfill({ status: 204 }); }); }