| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { expect, test, type Page } from "@playwright/test"
- async function connect(page: Page, suffix = "") {
- await page.goto(`/e2e/paas/index.html?ux${suffix}`)
- await page.getByLabel("API Key", { exact: true }).fill("fullcheck")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
- }
- test("unsent drafts and their attachments remain reachable after switching and reloading", async ({ page }) => {
- await connect(page)
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("尚未提交的研究设想")
- await page.getByRole("button", { name: "添加文件", exact: true }).click()
- await page.locator(".paas-new-session").click()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("另一项研究")
- await page.reload()
- await page.getByLabel("API Key", { exact: true }).fill("fullcheck")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- const drafts = page.getByRole("region", { name: "未发送草稿", exact: true })
- await expect(drafts.getByRole("button")).toHaveCount(2)
- await drafts.getByRole("button", { name: /尚未提交的研究设想/ }).click()
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("尚未提交的研究设想")
- await expect(page.getByRole("button", { name: "移除成功.txt", exact: true })).toBeVisible()
- await expect
- .poll(() =>
- page.evaluate(
- () =>
- (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
- (c) => c.action === "execute",
- ).length,
- ),
- )
- .toBe(0)
- })
- test("title editing keeps Chinese composition open and Escape returns focus", async ({ page }) => {
- await connect(page)
- const title = page.locator(".paas-topbar-chat-title")
- await title.click()
- const input = page.getByRole("textbox", { name: "会话名称", exact: true })
- await input.fill("科研标题")
- await input.dispatchEvent("keydown", { key: "Enter", code: "Enter", isComposing: true, bubbles: true })
- await expect(input).toBeVisible()
- await input.press("Enter")
- await expect(title).toHaveText("科研标题")
- await expect(title).toBeFocused()
- await title.press("Enter")
- await input.fill("不应保存")
- await input.press("Escape")
- await expect(title).toHaveText("科研标题")
- await expect(title).toBeFocused()
- })
- test("Escape closes the more menu and restores keyboard focus", async ({ page }) => {
- await connect(page)
- const more = page.locator(".paas-more-actions")
- await more.locator("summary").click()
- await more.getByRole("button", { name: "重命名会话", exact: true }).focus()
- await page.keyboard.press("Escape")
- await expect(more).not.toHaveAttribute("open", "")
- await expect(more.locator("summary")).toBeFocused()
- })
- for (const os of ["macos", "windows"]) {
- for (const width of [587, 1280]) {
- test(`${os} layout at ${width}px keeps native caption space and toolbar visible`, async ({ page }, testInfo) => {
- await page.setViewportSize({ width, height: 705 })
- await connect(page, `&os=${os}`)
- const toolbar = page.locator(".paas-chat-header-actions")
- await expect(toolbar).toBeInViewport()
- expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(width)
- const box = await toolbar.boundingBox()
- expect(box).not.toBeNull()
- if (os === "windows") expect(box!.y).toBeGreaterThanOrEqual(46)
- if (os === "macos" && width === 587) {
- const toggle = await page.locator(".paas-nav-toggle").boundingBox()
- expect(toggle!.x).toBeGreaterThanOrEqual(80)
- }
- await page.screenshot({ path: testInfo.outputPath(`${os}-${width}.png`) })
- })
- }
- }
- test("narrow windows retain settings and developer actions in the more menu", async ({ page }) => {
- await page.setViewportSize({ width: 520, height: 705 })
- await connect(page)
- await expect(page.locator(".paas-action-settings")).toBeHidden()
- await expect(page.locator(".paas-action-workspace")).toBeHidden()
- const menu = page.locator(".paas-more-actions")
- await menu.locator("summary").click()
- await expect(menu.getByRole("button", { name: "在开发区打开工作区", exact: true })).toBeVisible()
- await menu.getByRole("button", { name: "研究设置", exact: true }).click()
- await expect(page.getByRole("heading", { name: "编辑智能体", exact: true })).toBeVisible()
- })
|