import { expect, test } from "@playwright/test"; import { mockAgentApi } from "./support/mock-agent-api"; test("the docked Agent collapses and restores the main workspace", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); const agentPanel = page.getByRole("complementary", { name: "Agent 命令面板" }); const workspace = page.locator("#main-workspace"); const expandedWidth = Math.round((await agentPanel.boundingBox())?.width ?? 0); expect(expandedWidth).toBeGreaterThan(400); await expect.poll(async () => Math.round((await workspace.boundingBox())?.x ?? 0)).toBe(expandedWidth); await page.getByRole("button", { name: "折叠 Agent 面板" }).click(); await expect(page.getByLabel("Agent 折叠栏")).toBeVisible(); await expect.poll(async () => Math.round((await workspace.boundingBox())?.x ?? 0)).toBe(72); await page.getByLabel(/展开 Agent 助手面板/).click(); await expect(agentPanel).toBeVisible(); await expect.poll(async () => Math.round((await workspace.boundingBox())?.x ?? 0)).toBe(expandedWidth); }); test("the floating condition feed coordinates with the docked Agent", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); await expect(page.locator('aside[aria-label="Agent 命令面板"]')).toBeVisible(); const prompt = page.getByPlaceholder("输入调度问题,Agent 将通过后端会话流式响应"); await prompt.fill("保留尚未发送的诊断问题"); const conditionToggle = page .locator("header.acrylic-navigation") .getByRole("button", { name: "工况任务", exact: true }); await conditionToggle.click(); const conditionPanel = page.getByRole("region", { name: "工况任务", exact: true }); await expect(conditionPanel).toBeVisible(); await expect(page.locator('aside[aria-label="Agent 命令面板"]')).toBeVisible(); await conditionPanel.getByRole("button", { name: "展开工况任务" }).click(); await expect(page.getByLabel("Agent 折叠栏")).toBeVisible(); await expect(conditionPanel.getByRole("button", { name: "收起工况任务" })).toBeVisible(); await conditionPanel.getByRole("button", { name: "收起工况任务" }).click(); await expect(page.locator('aside[aria-label="Agent 命令面板"]')).toBeVisible(); await expect(prompt).toHaveValue("保留尚未发送的诊断问题"); await conditionToggle.click(); await expect(conditionPanel).toBeHidden(); }); test("Agent resize handle stays hidden in the mobile layout", async ({ page }) => { await page.setViewportSize({ width: 375, height: 812 }); await page.goto("/", { waitUntil: "domcontentloaded" }); await expect(page.getByRole("separator", { name: "调整 Agent 面板宽度" })).toBeHidden(); }); test.describe("mobile touch layout", () => { test.use({ hasTouch: true, isMobile: true, viewport: { width: 375, height: 812 } }); test("mobile Agent toggle opens the conversation panel by touch", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); const openButton = page.getByRole("button", { name: "打开 Agent 面板" }); const buttonBox = await openButton.boundingBox(); expect(buttonBox).not.toBeNull(); await page.touchscreen.tap( buttonBox!.x + buttonBox!.width / 2, buttonBox!.y + buttonBox!.height / 2 ); await expect( page.locator('aside[aria-label="Agent 命令面板"]').filter({ visible: true }) ).toBeVisible(); await expect(page.getByRole("button", { name: "关闭 Agent 面板" })).toBeVisible(); }); }); test("mobile alert summary opens the Agent conversation panel", async ({ page }) => { await mockAgentApi(page); await page.clock.setFixedTime(new Date("2026-07-21T10:40:00+08:00")); await page.setViewportSize({ width: 375, height: 812 }); await page.goto("/", { waitUntil: "domcontentloaded" }); await page.getByRole("button", { name: /查看异常处置面板/ }).click(); await page.getByRole("button", { name: "工况汇总" }).click(); await expect( page.locator('aside[aria-label="Agent 命令面板"]').filter({ visible: true }) ).toBeVisible(); await expect(page.getByRole("button", { name: "关闭 Agent 面板" })).toBeVisible(); await expect(page.getByText("已发起工况汇总", { exact: true })).toBeVisible(); });