| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import { test, expect } from "@playwright/test"
- test("desktop appearance, compact navigation, and project naming", async ({ page }) => {
- await page.setViewportSize({ width: 1180, height: 720 })
- await page.goto("/e2e/paas/index.html?ux")
- await page.getByLabel("API Key", { exact: true }).fill("synthetic")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
- await page.getByLabel("外观模式").selectOption("light")
- await expect(page.locator("html")).toHaveAttribute("data-color-scheme", "light")
- await page.getByLabel("外观模式").selectOption("dark")
- await expect(page.locator("html")).toHaveAttribute("data-color-scheme", "dark")
- await page.getByRole("button", { name: "功能导航", exact: true }).click()
- await expect(page.getByRole("button", { name: "平台任务", exact: true })).toBeHidden()
- expect(
- await page.locator(".paas-nav-history").evaluate((el) => el.getBoundingClientRect().height),
- ).toBeGreaterThanOrEqual(150)
- await page.getByRole("button", { name: "新建项目", exact: true }).click()
- await page.getByRole("button", { name: "选择主文件夹", exact: true }).click()
- await expect(page.getByRole("textbox", { name: "项目名称", exact: true })).not.toHaveValue("")
- 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("button", { name: "保存名称", exact: true }).click()
- await page.getByRole("button", { name: "完成", exact: true }).click()
- await expect(page.getByRole("combobox", { name: "切换项目", exact: true }).locator("option:checked")).toHaveText(
- "跨目录项目",
- )
- await page.screenshot({ path: "/private/tmp/lambda-project-settings.png" })
- })
- test("fresh model setup distinguishes a local service from saved credentials", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?setup&ux&unified&fresh-models")
- await page.getByRole("button", { name: "准备本机服务并连接", exact: true }).click()
- await page.getByRole("button", { name: "平台设置", exact: true }).click()
- await page.getByRole("button", { name: "检查与配置资源", exact: true }).click()
- const select = page.getByRole("region", { name: "模型与应用配置" }).getByLabel("模型服务", { exact: true })
- await expect(select.locator('option[value="anthropic"]')).toHaveText("Anthropic · 未配置")
- await expect(select.locator('option[value="ollama"]')).toHaveText("Ollama · 本地服务(待测试)")
- await expect(select).not.toContainText("已配置")
- })
- test("multiple folders are shown before submission and forwarded to execution", async ({ page }) => {
- await page.setViewportSize({ width: 1180, height: 720 })
- await page.goto("/e2e/paas/index.html?ux&workspace")
- await page.getByLabel("API Key", { exact: true }).fill("synthetic")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.evaluate(() =>
- Object.assign(Reflect.get(window, "paasUX"), { directories: ["D:/Project/main", "D:/Project/data"] }),
- )
- await page.getByRole("button", { name: "新建项目", exact: true }).click()
- await page.getByRole("button", { name: "选择主文件夹", exact: true }).click()
- await page.getByRole("button", { name: "创建项目", exact: true }).click()
- await page.getByRole("button", { name: "项目设置", exact: true }).click()
- await page.getByRole("button", { name: "添加工作文件夹", exact: true }).click()
- await page.getByRole("button", { name: "完成", exact: true }).click()
- const scope = page.locator(".paas-task-scope")
- await scope.locator(":scope > summary").click()
- await expect(scope).toContainText("D:/Project/main")
- await expect(scope).toContainText("D:/Project/data")
- await expect(scope).toContainText("读取文件")
- await expect(scope).toContainText("当前使用应用默认工具配置")
- const composer = page.locator("form.paas-composer")
- const bounds = await composer.boundingBox()
- const send = await page.getByRole("button", { name: "发送消息", exact: true }).boundingBox()
- expect(send!.y + send!.height).toBeLessThanOrEqual(bounds!.y + bounds!.height)
- expect(send!.y + send!.height).toBeLessThanOrEqual(720)
- await page.getByRole("button", { name: "功能导航", exact: true }).click()
- await page.getByLabel("外观模式").selectOption("dark")
- await page.screenshot({ path: "/private/tmp/lambda-task-scope-dark.png" })
- await page.getByLabel("外观模式").selectOption("light")
- await page.screenshot({ path: "/private/tmp/lambda-task-scope-light.png" })
- await page.setViewportSize({ width: 600, height: 800 })
- await expect(scope).toBeVisible()
- expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(600)
- await page.screenshot({ path: "/private/tmp/lambda-task-scope-narrow.png" })
- await scope.locator(":scope > summary").click()
- await page.screenshot({ path: "/private/tmp/lambda-task-scope-collapsed.png" })
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("请在工作文件夹中读取项目代码并整理")
- await page.getByRole("button", { name: "发送消息", exact: true }).click()
- await expect
- .poll(() =>
- page.evaluate(
- () =>
- Reflect.get(window, "paasTestCalls")
- .filter((call: { action: string }) => call.action === "execute")
- .at(-1)?.workDirs,
- ),
- )
- .toEqual(["D:/Project/main", "D:/Project/data"])
- })
- test("scope loading failure stays recoverable and does not block ordinary tasks", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await page.getByLabel("API Key", { exact: true }).fill("synthetic")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { scopeError: true }))
- const scope = page.locator(".paas-task-scope")
- await scope.locator(":scope > summary").click()
- await expect(scope).toContainText("工具范围暂未加载")
- await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { scopeError: false }))
- await scope.getByRole("button", { name: "刷新范围" }).click()
- await expect(scope).toContainText("读取文件")
- await scope.locator(":scope > summary").click()
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("分析材料")
- await expect(page.getByRole("button", { name: "发送消息", exact: true })).toBeEnabled()
- })
- for (const theme of ["light", "dark"] as const) {
- test(`project dialog preserves sidebar space and manages folders in ${theme}`, async ({ page }) => {
- await page.setViewportSize({ width: 1180, height: 640 })
- await page.goto("/e2e/paas/index.html?ux&unified")
- await page.getByLabel("API Key", { exact: true }).fill("synthetic")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.getByLabel("外观模式").selectOption(theme)
- await page.evaluate(() =>
- Object.assign(Reflect.get(window, "paasUX"), {
- directories: ["D:/Project/main", "D:/Project/extra-long-folder-name-for-layout/data", "D:/Project/third"],
- }),
- )
- const sidebar = page.locator(".paas-sidebar")
- const before = await sidebar.locator(".paas-project-switcher").boundingBox()
- const trigger = page.getByRole("button", { name: "项目设置", exact: true })
- await trigger.click()
- const dialog = page.getByRole("dialog", { name: "项目设置", exact: true })
- await expect(dialog).toBeVisible()
- for (let i = 0; i < 3; i++) await dialog.getByRole("button", { name: "添加工作文件夹", exact: true }).click()
- await expect(dialog.locator(".paas-project-folder-card")).toHaveCount(3)
- expect((await sidebar.locator(".paas-project-switcher").boundingBox())!.height).toBe(before!.height)
- await dialog.getByRole("button", { name: "设为主目录", exact: true }).last().click()
- await expect(dialog.locator(".paas-project-folder-card").first()).toContainText("third")
- await dialog.getByRole("button", { name: "移除文件夹 main", exact: true }).click()
- await expect(dialog.locator(".paas-project-folder-card")).toHaveCount(2)
- await page.screenshot({ path: `/private/tmp/lambda-project-dialog-${theme}.png` })
- await page.keyboard.press("Escape")
- await expect(dialog).toHaveCount(0)
- await expect(trigger).toBeFocused()
- const footer = await sidebar.locator(".paas-sidebar-footer").boundingBox()
- expect(footer!.y + footer!.height).toBeLessThanOrEqual(640)
- expect(await sidebar.locator(".paas-nav-history").evaluate((el) => el.clientHeight)).toBeGreaterThanOrEqual(120)
- await page.screenshot({ path: `/private/tmp/lambda-sidebar-compact-${theme}.png` })
- await trigger.click()
- await expect(dialog.locator(".paas-project-folder-card")).toHaveCount(2)
- await page.setViewportSize({ width: 390, height: 580 })
- await expect(dialog.getByRole("button", { name: "完成", exact: true })).toBeInViewport()
- const bounds = await dialog.boundingBox()
- expect(bounds!.x).toBeGreaterThanOrEqual(0)
- expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(390)
- await page.screenshot({ path: `/private/tmp/lambda-project-dialog-narrow-${theme}.png` })
- })
- }
- test("closing project settings ignores a late native folder selection", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?ux")
- await page.getByLabel("API Key", { exact: true }).fill("synthetic")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await page.getByRole("button", { name: "项目设置", exact: true }).click()
- await page.evaluate(() => Object.assign(Reflect.get(window, "paasUX"), { holdDirectory: true }))
- await page.getByRole("button", { name: "添加工作文件夹", exact: true }).click()
- await page.keyboard.press("Escape")
- await page.evaluate(() => Reflect.get(window, "paasUX").releaseDirectory())
- await page.getByRole("button", { name: "项目设置", exact: true }).click()
- await expect(page.locator(".paas-project-folder-card")).toHaveCount(0)
- })
|