| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- import { expect, test } from "@playwright/test"
- test("completed research appears in inbox until opened", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?completed")
- await page.getByLabel("API Key", { exact: true }).fill("inbox-test")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- const inbox = page.getByRole("button", { name: /^通知:/ })
- await expect(inbox).toBeVisible()
- await page.getByRole("button", { name: "平台任务", exact: true }).click()
- await expect(page.getByRole("heading", { name: "平台任务", exact: true })).toBeVisible()
- await expect(page.getByRole("heading", { name: "研究计划", exact: true })).not.toBeVisible()
- await inbox.click()
- await page
- .getByRole("dialog", { name: "任务通知" })
- .getByRole("button", { name: /已有研究/ })
- .click()
- await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: /^通知:/ })).toHaveCount(0)
- })
- test("inbox panel closes on Escape inside it and on an outside pointer click", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?completed")
- await page.getByLabel("API Key", { exact: true }).fill("inbox-escape")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- const inbox = page.getByRole("button", { name: /^通知:/ })
- const panel = page.getByRole("dialog", { name: "任务通知" })
- await inbox.click()
- await expect(panel).toBeVisible()
- await page.getByRole("textbox", { name: "消息", exact: true }).focus()
- await page.keyboard.press("Escape")
- await expect(panel).toBeVisible()
- await inbox.focus()
- await page.keyboard.press("Escape")
- await expect(panel).toHaveCount(0)
- await expect(inbox).toBeFocused()
- await inbox.click()
- await expect(panel).toBeVisible()
- await page.locator(".paas-conversation").click({ position: { x: 8, y: 8 } })
- await expect(panel).toHaveCount(0)
- })
- test("non-active completed chat is recovered from the task index after reload", async ({ page }) => {
- const connect = async (apiKey: string) => {
- await page.getByLabel("API Key", { exact: true }).fill(apiKey)
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.getByRole("textbox", { name: "消息", exact: true }).waitFor()
- }
- await page.goto("/e2e/paas/index.html?completed")
- await connect("inbox-recover")
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: /^通知:/ })).toBeVisible()
- // Switch to another chat with a saved draft so the completed chat is persisted but not active.
- await page.locator(".paas-chat-header-actions").getByRole("button", { name: "新会话", exact: true }).click()
- await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话")
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("让完成会话保持非活动")
- await page.reload()
- await connect("inbox-recover")
- // The completed history is never opened here; its cache loads without messages.
- await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话")
- await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toHaveCount(0)
- await page.locator(".paas-sidebar").getByRole("button", { name: "平台任务", exact: true }).click()
- await expect(page.locator(".paas-task-title")).toHaveText("分析材料")
- const inbox = page.getByRole("button", { name: /^通知:/ })
- await expect(inbox).toBeVisible()
- await inbox.click()
- await expect(page.getByRole("dialog", { name: "任务通知" }).getByRole("button", { name: /已有研究/ })).toBeVisible()
- })
- test("opening an approval keeps it listed in inbox", async ({ page }) => {
- await page.goto("/e2e/paas/index.html")
- await page.getByLabel("API Key", { exact: true }).fill("inbox-approval")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- await page.getByRole("button", { name: /^通知:/ }).click()
- const panel = page.getByRole("dialog", { name: "任务通知" })
- await panel.getByRole("button", { name: /已有研究/ }).click()
- await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
- await expect(page.getByRole("dialog", { name: "任务通知" })).toHaveCount(0)
- await expect(page.getByRole("button", { name: /^通知:/ })).toBeVisible()
- })
- test("completed unread stays read after a reload", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?completed")
- await page.getByLabel("API Key", { exact: true }).fill("inbox-reload")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- const inbox = page.getByRole("button", { name: /^通知:/ })
- await expect(inbox).toBeVisible()
- await inbox.click()
- await page
- .getByRole("dialog", { name: "任务通知" })
- .getByRole("button", { name: /已有研究/ })
- .click()
- await expect(page.getByRole("button", { name: /^通知:/ })).toHaveCount(0)
- await page.reload()
- await page.getByLabel("API Key", { exact: true }).fill("inbox-reload")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: /^通知:/ })).toHaveCount(0)
- })
- for (const width of [360, 520]) {
- test(`inbox stays within a ${width}px window and restores focus when closed`, async ({ page }) => {
- await page.goto("/e2e/paas/index.html?completed")
- await page.getByLabel("API Key", { exact: true }).fill(`inbox-width-${width}`)
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page
- .getByRole("button", { name: /已有研究/ })
- .first()
- .click()
- await page.setViewportSize({ width, height: 650 })
- const toggle = page.getByRole("button", { name: /^通知:/ })
- await toggle.click()
- const panel = page.getByRole("dialog", { name: "任务通知" })
- const bounds = await panel.boundingBox()
- expect(bounds!.x).toBeGreaterThanOrEqual(0)
- expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width)
- expect(bounds!.y + bounds!.height).toBeLessThanOrEqual(650)
- await page.getByRole("button", { name: "关闭任务通知", exact: true }).click()
- await expect(panel).toHaveCount(0)
- await expect(toggle).toBeFocused()
- })
- }
- test("unloaded inbox results stay unread after a failed fetch, then open the exact run on retry", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await page.getByLabel("API Key", { exact: true }).fill("inbox-load")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("最初的研究")
- await page.getByRole("button", { name: "发送消息", exact: true }).click()
- await expect(page.getByRole("button", { name: "暂停", exact: true })).toBeVisible()
- await page.evaluate(() => {
- window.paasUX.update("ux_1", { status: "completed", output: "第一轮研究结果" })
- })
- await page.getByRole("button", { name: "刷新状态", exact: true }).click()
- await expect(page.getByText("第一轮研究结果", { exact: true }).first()).toBeVisible()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("保留的草稿")
- await page.evaluate(() => {
- window.paasUX.add({
- run_id: "external_result",
- agent_id: "research",
- thread_id: "thread_ux_1",
- status: "completed",
- input: "另一轮研究",
- output: "# 新增研究成果\n\n完成证据核验。",
- updated_at: "2026-11-30T12:00:00Z",
- })
- Object.assign(window.paasUX, { threadError: "模拟会话读取失败" })
- })
- await page.getByRole("button", { name: "平台任务", exact: true }).click()
- const toggle = page.getByRole("button", { name: /^通知:/ })
- await expect(toggle).toBeVisible()
- await toggle.click()
- await page
- .getByRole("dialog", { name: "任务通知" })
- .getByRole("button", { name: /另一轮研究/ })
- .click()
- await expect(page.getByRole("alert")).toBeVisible()
- await page.getByText("查看错误详情", { exact: true }).click()
- await expect(page.getByText("模拟会话读取失败", { exact: true })).toBeVisible()
- await expect(toggle).toBeVisible()
- await page.evaluate(() => Object.assign(window.paasUX, { threadError: "" }))
- await toggle.click()
- await page
- .getByRole("dialog", { name: "任务通知" })
- .getByRole("button", { name: /另一轮研究/ })
- .click()
- const target = page.locator('.paas-chat-message[data-run-id="external_result"]')
- await expect(target).toBeFocused()
- await expect(target).toContainText("新增研究成果")
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("保留的草稿")
- await expect(page.getByRole("button", { name: /^通知:/ })).toBeVisible()
- })
|