| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { expect, test } from "@playwright/test"
- for (const theme of ["light", "dark"] as const) {
- for (const [width, height] of [
- [360, 740],
- [960, 700],
- [1440, 900],
- ]) {
- test(`editor keeps fields clear of actions at ${width}x${height} in ${theme}`, async ({ page }) => {
- await page.setViewportSize({ width, height })
- await page.emulateMedia({ colorScheme: theme })
- await page.goto("/e2e/paas/index.html?ux")
- await page.evaluate((mode) => {
- document.documentElement.style.colorScheme = mode
- document.documentElement.setAttribute("data-color-scheme", mode)
- }, theme)
- await page.getByLabel("API Key", { exact: true }).fill("editor-layout")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- const agents = page.getByRole("button", { name: "智能体", exact: true })
- if (!(await agents.isVisible())) await page.getByRole("button", { name: "打开导航", exact: true }).click()
- await agents.click()
- await page.getByRole("button", { name: "编辑 科研助手", exact: true }).click()
- const save = page.getByRole("button", { name: "保存修改", exact: true })
- await expect(save).toBeInViewport()
- await expect(page.getByText("保存后应用于后续任务", { exact: true })).toBeVisible()
- const geometry = await page.locator(".paas-agent-edit").evaluate((element) => {
- const scroll = element.querySelector(".paas-edit-scroll")!.getBoundingClientRect()
- const footer = element.querySelector(".paas-edit-footer")!.getBoundingClientRect()
- const content = element.closest(".paas-content")!
- const section = element.querySelector("fieldset")!.getBoundingClientRect()
- const title = element.querySelector("legend")!.getBoundingClientRect()
- return {
- scrollBottom: scroll.bottom,
- footerTop: footer.top,
- footerBottom: footer.bottom,
- viewport: innerHeight,
- outerOverflow: content.scrollHeight - content.clientHeight,
- titleInset: title.top - section.top,
- }
- })
- expect(geometry.scrollBottom).toBeLessThanOrEqual(geometry.footerTop + 1)
- expect(geometry.footerBottom).toBeLessThanOrEqual(height)
- expect(geometry.outerOverflow).toBeLessThanOrEqual(1)
- expect(geometry.titleInset).toBeGreaterThanOrEqual(16)
- const fields = page.locator(".paas-edit-scroll :is(input,textarea,select):visible")
- for (const field of await fields.all()) {
- await field.scrollIntoViewIfNeeded()
- const bounds = await field.boundingBox()
- const footer = await page.locator(".paas-edit-footer").boundingBox()
- const scroll = await page.locator(".paas-edit-scroll").boundingBox()
- expect(bounds!.y).toBeGreaterThanOrEqual(scroll!.y - 1)
- expect(bounds!.y + bounds!.height).toBeLessThanOrEqual(footer!.y + 1)
- expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width)
- }
- await page.getByText("高级配置(JSON)", { exact: true }).click()
- const json = page.getByLabel("智能体配置", { exact: true })
- await json.scrollIntoViewIfNeeded()
- await expect(json).toBeInViewport()
- await expect(save).toBeInViewport()
- expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width)
- const rounds = page.getByLabel("最多研究轮次", { exact: true })
- await rounds.fill("9")
- await save.click()
- await expect(rounds).toBeFocused()
- const box = await rounds.boundingBox()
- const footer = await page.locator(".paas-edit-footer").boundingBox()
- expect(box!.y + box!.height).toBeLessThan(footer!.y)
- })
- }
- }
|