| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { expect, test, type Page } from "@playwright/test"
- async function open(page: Page) {
- await page.goto("/e2e/paas/index.html?completed&unified&sidenotes")
- await page.getByLabel("API Key", { exact: true }).fill("plugin-test")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- }
- async function manager(page: Page) {
- await page.getByRole("button", { name: "应用与插件", exact: true }).click()
- await page.getByRole("tab", { name: "界面扩展", exact: true }).click()
- }
- test("uninstall and reinstall retain history and register the answer contribution immediately", async ({ page }) => {
- await open(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")).toBeVisible()
- await manager(page)
- await expect(page.getByRole("article", { name: "侧注 SideNote" })).toContainText("v0.1.0")
- await page.getByRole("button", { name: "卸载插件", exact: true }).click()
- await expect(page.getByRole("button", { name: "安装插件", exact: true })).toBeVisible()
- await page.getByRole("button", { name: "会话", exact: true }).click()
- await expect(page.locator(".lambda-sidenote-toggle")).toHaveCount(0)
- await expect(page.locator(".paas-report").last()).toContainText("尚未运行浏览器端到端测试")
- await page.reload()
- await page.getByLabel("API Key", { exact: true }).fill("plugin-test")
- await page.getByRole("button", { name: "连接平台", exact: true }).click()
- await expect(page.locator(".lambda-sidenote-toggle")).toHaveCount(0)
- await manager(page)
- await page.getByRole("button", { name: "安装插件", exact: true }).click()
- 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("a rendering failure falls back to original text without losing notes", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?native-sidenote")
- await page.evaluate(async () => {
- const control = (
- window as Window & { nativeSideNotes: { fail: () => Promise<void>; update: (value: object) => void } }
- ).nativeSideNotes
- await control.fail()
- control.update({ text: "保留我的答案\n```sidenotes\n- 存疑 | 我的答案 | 不能丢失的限制\n```", completed: true })
- })
- await expect(page.locator('[data-slot="text-part-body"]')).toContainText("保留我的答案")
- await expect(page.locator('[data-slot="text-part-body"]')).toContainText("不能丢失的限制")
- await expect(page.locator(".lambda-sidenote-panel")).toHaveCount(0)
- })
- test("unavailable preference storage does not falsely report uninstall success", async ({ page }) => {
- await open(page)
- await manager(page)
- await page.evaluate(() => {
- const original = Storage.prototype.setItem
- Storage.prototype.setItem = function (key, value) {
- if (key === "lambda.desktop.ui-plugins.v1") throw new Error("Synthetic storage failure")
- return original.call(this, key, value)
- }
- })
- await page.getByRole("button", { name: "卸载插件", exact: true }).click()
- await expect(page.getByRole("alert")).toContainText("当前状态未更改")
- await expect(page.getByRole("button", { name: "停用插件", exact: true })).toBeVisible()
- })
- for (const theme of ["light", "dark"] as const) {
- test(`plugin controls are readable in ${theme} and in narrow windows`, async ({ page }) => {
- await page.emulateMedia({ colorScheme: theme })
- await open(page)
- await manager(page)
- await page.screenshot({ path: `/private/tmp/ui-plugins-${theme}.png` })
- await page.setViewportSize({ width: 390, height: 720 })
- expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
- await expect(page.getByRole("button", { name: "停用插件", exact: true })).toBeVisible()
- await page.screenshot({ path: `/private/tmp/ui-plugins-${theme}-narrow.png` })
- })
- }
- test("plugin installation synchronizes across open windows without reloading their conversation", async ({
- page,
- context,
- }) => {
- await open(page)
- await manager(page)
- await page.getByRole("button", { name: "卸载插件", exact: true }).click()
- const other = await context.newPage()
- await open(other)
- await other.getByRole("textbox", { name: "消息", exact: true }).fill("跨窗口插件验收")
- await other.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
- await expect(other.locator(".paas-report").last()).toContainText("尚未运行浏览器端到端测试")
- await expect(other.locator(".lambda-sidenote-toggle")).toHaveCount(0)
- await page.getByRole("button", { name: "安装插件", exact: true }).click()
- await expect(other.locator(".lambda-sidenote-toggle")).toBeVisible()
- await other.locator(".lambda-sidenote-toggle").click()
- await expect(other.locator(".lambda-sidenote-panel")).toBeVisible()
- await page.getByRole("button", { name: "卸载插件", exact: true }).click()
- await expect(other.locator(".lambda-sidenote-panel")).toHaveCount(0)
- await expect(other.locator(".paas-report").last()).toContainText("尚未运行浏览器端到端测试")
- await other.close()
- })
- test("the host selects drawer mode from available reading space, not window width", async ({ page }) => {
- await page.setViewportSize({ width: 1600, height: 1000 })
- await open(page)
- await page.getByRole("textbox", { name: "消息", exact: true }).fill("容器尺寸验收")
- await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
- await page.locator(".lambda-sidenote-toggle").click()
- const panel = page.locator(".lambda-sidenote-panel")
- await expect(panel).toHaveAttribute("data-narrow", "false")
- await page.locator("[data-ui-plugin-dock-host]").evaluate((element) => {
- ;(element as HTMLElement).style.maxWidth = "800px"
- })
- await expect(panel).toHaveAttribute("data-narrow", "true")
- await expect(page.locator("[data-ui-plugin-panel-open]")).toHaveCount(0)
- await page.locator("[data-ui-plugin-dock-host]").evaluate((element) => {
- ;(element as HTMLElement).style.removeProperty("max-width")
- })
- await expect(panel).toHaveAttribute("data-narrow", "false")
- await expect(page.locator("[data-ui-plugin-panel-open]")).toHaveCount(1)
- await page.getByRole("button", { name: "关闭侧注", exact: true }).click()
- await expect(page.locator("[data-ui-plugin-panel-open]")).toHaveCount(0)
- })
- test("hiding a mounted native workspace dismisses its portaled plugin panel", async ({ page }) => {
- await page.goto("/e2e/paas/index.html?native-sidenote")
- await page.evaluate(() => {
- ;(window as Window & { nativeSideNotes: { update: (value: object) => void } }).nativeSideNotes.update({
- text: "保留我的答案\n```sidenotes\n- 存疑 | 我的答案 | 尚未核验\n```",
- completed: true,
- })
- })
- await page.locator(".lambda-sidenote-toggle").click()
- await expect(page.locator(".lambda-sidenote-panel")).toBeVisible()
- await page.locator("main").evaluate((element) => {
- ;(element as HTMLElement).style.display = "none"
- })
- await expect(page.locator(".lambda-sidenote-panel")).toHaveCount(0)
- await page.locator("main").evaluate((element) => {
- ;(element as HTMLElement).style.removeProperty("display")
- })
- await expect(page.locator(".lambda-sidenote-toggle")).toHaveAttribute("aria-expanded", "false")
- })
|