|
| 1 | +import { expect, test } from "@playwright/test" |
| 2 | +import { mockOpenCodeServer } from "../utils/mock-server" |
| 3 | +import { expectAppVisible } from "../utils/waits" |
| 4 | + |
| 5 | +const draftID = "draft_new_session_panel_corner" |
| 6 | +const directory = "C:/OpenCode/NewSessionPanelCorner" |
| 7 | +const server = `http://${process.env.PLAYWRIGHT_SERVER_HOST ?? "127.0.0.1"}:${process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"}` |
| 8 | + |
| 9 | +test.use({ |
| 10 | + viewport: { width: 935, height: 522 }, |
| 11 | + deviceScaleFactor: 1, |
| 12 | +}) |
| 13 | + |
| 14 | +test("matches the rounded panel corners to the dark new-session background", async ({ page }, testInfo) => { |
| 15 | + await mockOpenCodeServer(page, { |
| 16 | + directory, |
| 17 | + project: { |
| 18 | + id: "proj_new_session_panel_corner", |
| 19 | + worktree: directory, |
| 20 | + vcs: "git", |
| 21 | + name: "new-session-panel-corner", |
| 22 | + time: { created: 1700000000000, updated: 1700000000000 }, |
| 23 | + sandboxes: [], |
| 24 | + }, |
| 25 | + provider: { all: [], connected: [], default: {} }, |
| 26 | + sessions: [], |
| 27 | + pageMessages: () => ({ items: [] }), |
| 28 | + }) |
| 29 | + await page.addInitScript( |
| 30 | + ({ directory, draftID, server }) => { |
| 31 | + localStorage.setItem("settings.v3", JSON.stringify({ general: { newLayoutDesigns: true } })) |
| 32 | + localStorage.setItem("opencode-theme-id", "oc-2") |
| 33 | + localStorage.setItem("opencode-color-scheme", "dark") |
| 34 | + localStorage.setItem( |
| 35 | + "opencode.global.dat:server", |
| 36 | + JSON.stringify({ |
| 37 | + projects: { local: [{ worktree: directory, expanded: true }] }, |
| 38 | + lastProject: { local: directory }, |
| 39 | + }), |
| 40 | + ) |
| 41 | + localStorage.setItem( |
| 42 | + "opencode.window.browser.dat:tabs", |
| 43 | + JSON.stringify([{ type: "draft", draftID, server, directory }]), |
| 44 | + ) |
| 45 | + }, |
| 46 | + { directory, draftID, server }, |
| 47 | + ) |
| 48 | + |
| 49 | + await page.goto(`/new-session?draftId=${draftID}`) |
| 50 | + await expectAppVisible(page.locator('[data-component="prompt-input"]')) |
| 51 | + await expect(page.locator("html")).toHaveAttribute("data-color-scheme", "dark") |
| 52 | + const panel = page.locator('main div[class*="rounded-[10px]"][class*="overflow-hidden"]') |
| 53 | + await expect(panel).toHaveCount(1) |
| 54 | + const box = await panel.boundingBox() |
| 55 | + if (!box) throw new Error("New-session panel bounds are unavailable") |
| 56 | + |
| 57 | + const screenshot = await page.screenshot({ path: testInfo.outputPath("new-session-dark.png") }) |
| 58 | + const corners = await page.evaluate( |
| 59 | + async ({ source, points }) => { |
| 60 | + const image = new Image() |
| 61 | + image.src = source |
| 62 | + await image.decode() |
| 63 | + const canvas = document.createElement("canvas") |
| 64 | + canvas.width = image.naturalWidth |
| 65 | + canvas.height = image.naturalHeight |
| 66 | + const context = canvas.getContext("2d") |
| 67 | + if (!context) throw new Error("2D canvas is unavailable") |
| 68 | + context.drawImage(image, 0, 0) |
| 69 | + return points.map((point) => Array.from(context.getImageData(point.x, point.y, 1, 1).data)) |
| 70 | + }, |
| 71 | + { |
| 72 | + source: `data:image/png;base64,${screenshot.toString("base64")}`, |
| 73 | + points: [ |
| 74 | + { x: Math.floor(box.x), y: Math.floor(box.y) }, |
| 75 | + { x: Math.ceil(box.x + box.width) - 1, y: Math.floor(box.y) }, |
| 76 | + { x: Math.floor(box.x), y: Math.ceil(box.y + box.height) - 1 }, |
| 77 | + { x: Math.ceil(box.x + box.width) - 1, y: Math.ceil(box.y + box.height) - 1 }, |
| 78 | + ], |
| 79 | + }, |
| 80 | + ) |
| 81 | + |
| 82 | + expect(corners.every(([red, green, blue, alpha]) => red <= 8 && green <= 8 && blue <= 8 && alpha === 255)).toBe(true) |
| 83 | +}) |
0 commit comments