| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- import { expect, test, type Page } from "@playwright/test"
- import type { PaasRequest } from "../../src/paas"
- async function open(page: Page, extra = "") {
- await page.goto(`/e2e/paas/index.html?completed&unified&sidenotes${extra}`)
- await page.getByLabel("API Key", { exact: true }).fill("sidenote-test")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- }
- async function send(page: Page) {
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("更新搜索")
- await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
- await expect(page.locator(".lambda-sidenote-toggle")).toHaveAttribute("aria-expanded", "false")
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(5)
- }
- async function calls(page: Page) {
- return page.evaluate(() => (window as Window & { paasTestCalls: PaasRequest[] }).paasTestCalls)
- }
- for (const theme of ["light", "dark"] as const) {
- test(`SideNote readable layout, navigation, follow-up and export in ${theme}`, async ({ page }) => {
- await page.emulateMedia({ colorScheme: theme })
- await page.setViewportSize({ width: 1600, height: 1000 })
- await open(page)
- await send(page)
- await expect(page.getByRole("region", { name: "回答正文" })).toBeVisible()
- await expect(page.locator(".lambda-sidenote-answer")).toHaveCSS("border-top-style", "solid")
- await expect(page.locator(".lambda-sidenote-panel")).toHaveCSS("border-top-style", "solid")
- const body = page.locator(".lambda-sidenote-body")
- const panel = page.getByRole("dialog", { name: "回答侧注", exact: true })
- await expect(body).not.toContainText("sidenotes")
- await expect(body).not.toContainText("默认使用系统")
- await expect(panel).toContainText("1 项存疑")
- await expect(panel.getByRole("button", { name: "定位原文" })).toHaveCount(5)
- await expect.poll(() => page.evaluate(() => CSS.highlights.size)).toBe(5)
- const box = await body.boundingBox(),
- notes = await panel.boundingBox()
- expect(notes!.x).toBeGreaterThan(box!.x + box!.width)
- await page.getByLabel("筛选侧注类型").selectOption("risk")
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(1)
- await expect(panel).toContainText("尚未运行浏览器端到端测试")
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("保留的草稿")
- await panel.getByRole("button", { name: "追问", exact: true }).click()
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue(
- /保留的草稿[\s\S]*尚未运行浏览器/,
- )
- expect((await calls(page)).filter((c) => c.action === "execute")).toHaveLength(1)
- await expect(panel).toHaveCount(0)
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(0)
- await expect(page.locator(".lambda-sidenote-toggle")).toContainText("1 项存疑")
- await page.getByRole("button", { name: "导出报告", exact: true }).click()
- const exported = (await calls(page)).find((c) => c.action === "export-report")
- expect(exported && "text" in exported && exported.text).toContain("**存疑**")
- const receipt = await page.locator(".paas-export-receipt").boundingBox()
- const composer = await page.locator(".paas-composer").boundingBox()
- expect(Math.abs(receipt!.x - composer!.x)).toBeLessThan(2)
- expect(Math.abs(receipt!.width - composer!.width)).toBeLessThan(2)
- await page.getByRole("button", { name: "关闭导出提示" }).click()
- await expect(page.locator(".paas-export-receipt")).toHaveCount(0)
- await page.locator(".lambda-sidenote-toggle").click()
- await page.getByLabel("筛选侧注类型").selectOption("all")
- await page.locator(".lambda-sidenote-answer").scrollIntoViewIfNeeded()
- await page.screenshot({ path: `/private/tmp/lambda-sidenotes-${theme}.png`, fullPage: true })
- await page.setViewportSize({ width: 620, height: 900 })
- await expect(panel).toHaveAttribute("data-narrow", "true")
- expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
- await page.screenshot({ path: `/private/tmp/lambda-sidenotes-${theme}-narrow.png`, fullPage: true })
- await page.keyboard.press("Escape")
- await expect(panel).toHaveCount(0)
- await expect(page.locator(".lambda-sidenote-toggle")).toBeFocused()
- })
- }
- test("extension preference persists and is sent with each new task; existing notes remain accessible", async ({
- page,
- }) => {
- await open(page)
- await page.getByRole("button", { name: "应用与插件", exact: true }).click()
- await page.getByRole("tab", { name: "界面扩展" }).click()
- await page.getByRole("button", { name: "停用插件", exact: true }).click()
- await page.reload()
- if (await page.getByLabel("API Key", { exact: true }).isVisible()) {
- await page.getByLabel("API Key", { exact: true }).fill("sidenote-test")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- }
- await page.getByRole("button", { name: "会话", exact: true }).click()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("下一项任务")
- await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
- await expect(page.locator(".lambda-sidenote-toggle")).toBeVisible()
- await expect(page.locator(".lambda-sidenote-toggle")).toHaveAttribute("aria-expanded", "false")
- expect((await calls(page)).find((c) => c.action === "execute")).toMatchObject({ sideNotes: false })
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(5)
- })
- test("malformed annotations remain available without contaminating the main answer", async ({ page }) => {
- await open(page, "&malformed-notes")
- await send(page)
- await page.getByText("1 行侧注格式未识别,查看原文").click()
- await expect(page.locator(".lambda-sidenote-unparsed pre")).toContainText("保留这段未知格式")
- await expect(page.locator(".lambda-sidenote-body")).not.toContainText("unknown")
- })
- test("partial run snapshots buffer incomplete notes and completed snapshots become navigable", async ({ page }) => {
- await open(page, "&ux")
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("逐步处理")
- await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
- await expect.poll(async () => (await calls(page)).filter((c) => c.action === "execute").length).toBe(1)
- await page.evaluate(() => {
- const ux = (window as Window & { paasUX: { update: (id: string, value: object) => void } }).paasUX
- ux.update("ux_1", { output: "已经处理正文\n```sidenotes\n- 做法 | 正文 | 已完成扫描\n- 存疑 | 正文 | 尚未" })
- })
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(1, { timeout: 10000 })
- await expect(page.locator(".lambda-sidenote-body")).toHaveText("已经处理正文")
- await expect(page.getByText("侧注生成中…", { exact: true })).toBeVisible()
- await expect(page.getByRole("button", { name: "定位原文", exact: true })).toHaveCount(0)
- await page.evaluate(() => {
- const ux = (window as Window & { paasUX: { update: (id: string, value: object) => void } }).paasUX
- ux.update("ux_1", {
- status: "completed",
- output: "已经处理正文\n```sidenotes\n- 做法 | 正文 | 已完成扫描\n- 存疑 | 正文 | 尚未验证结果\n```",
- })
- })
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(2, { timeout: 10000 })
- await expect(page.getByRole("button", { name: "定位原文", exact: true })).toHaveCount(2)
- await expect(page.getByText("侧注生成中…", { exact: true })).toHaveCount(0)
- await page.reload()
- await page.getByLabel("API Key", { exact: true }).fill("sidenote-test")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(2)
- })
- test("source click selects the linked note and copy includes hidden limitations", async ({ page, context }) => {
- await context.grantPermissions(["clipboard-read", "clipboard-write"])
- await open(page)
- await send(page)
- await page.getByRole("button", { name: "关闭侧注" }).click()
- await page.locator(".lambda-sidenote-body code").click()
- await expect(page.locator('.lambda-sidenote-card[data-note-index="0"]')).toHaveAttribute("data-selected", "true")
- await page.getByRole("button", { name: "关闭侧注" }).click()
- await page.getByRole("button", { name: "复制报告", exact: true }).click()
- expect(await page.evaluate(() => navigator.clipboard.readText())).toContain("**存疑**(界面交互尚未验证)")
- })
- test("native code-workspace text parts use the same adapter during streaming and copy", async ({ page, context }) => {
- await context.grantPermissions(["clipboard-read", "clipboard-write"])
- await page.goto("/e2e/paas/index.html?native-sidenote")
- await expect(page.locator('[data-slot="text-part-body"]')).toContainText("已更新搜索")
- await page.evaluate(() => {
- const control = (window as Window & { nativeSideNotes: { update: (value: object) => void } }).nativeSideNotes
- control.update({ text: "已更新搜索\n```sidenotes\n- 存疑 | 已更新搜索 | 尚未实测\n" })
- })
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(1)
- await expect(page.locator(".lambda-sidenote-body")).toHaveText("已更新搜索")
- await page.evaluate(() => {
- const control = (window as Window & { nativeSideNotes: { update: (value: object) => void } }).nativeSideNotes
- control.update({ text: "已更新搜索\n```sidenotes\n- 存疑 | 已更新搜索 | 尚未实测\n```", completed: true })
- })
- await expect(page.getByRole("button", { name: "定位原文" })).toBeVisible()
- await page.getByRole("button", { name: "关闭侧注" }).click()
- await page.locator('[data-component="text-part"]').hover()
- await page.getByRole("button", { name: /复制回复|Copy response/ }).click()
- expect(await page.evaluate(() => navigator.clipboard.readText())).toContain("**存疑**")
- })
- test("leaving a conversation closes its inspector and restores the full conversation width", async ({ page }) => {
- await page.setViewportSize({ width: 1600, height: 1000 })
- await open(page)
- await send(page)
- await expect(page.locator(".paas-conversation[data-ui-plugin-panel-open]")).toHaveCount(1)
- await page.getByRole("button", { name: "应用与插件", exact: true }).click()
- await expect(page.locator(".lambda-sidenote-panel")).toHaveCount(0)
- await expect(page.locator(".paas-conversation[data-ui-plugin-panel-open]")).toHaveCount(0)
- await page.getByRole("button", { name: "会话", exact: true }).click()
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-card")).toHaveCount(5)
- })
- test("opening another answer replaces the inspector rather than stacking panels", async ({ page }) => {
- await page.setViewportSize({ width: 1600, height: 1000 })
- await open(page)
- await send(page)
- await page.getByRole("button", { name: "关闭侧注" }).click()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("继续更新搜索")
- await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
- const toggles = page.locator(".lambda-sidenote-toggle")
- await expect(toggles).toHaveCount(2)
- await toggles.first().click()
- await expect(toggles.first()).toHaveAttribute("aria-expanded", "true")
- await toggles.last().click()
- await expect(toggles.first()).toHaveAttribute("aria-expanded", "false")
- await expect(toggles.last()).toHaveAttribute("aria-expanded", "true")
- await expect(page.locator(".lambda-sidenote-panel")).toHaveCount(1)
- })
|