|
| 1 | +import { mkdir, writeFile } from "node:fs/promises"; |
| 2 | +import path from "node:path"; |
| 3 | +import { expect, it } from "vitest"; |
| 4 | +import { installMockGateway } from "../test-helpers/control-ui-e2e.ts"; |
| 5 | +import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts"; |
| 6 | + |
| 7 | +const suite = createControlUiE2eSuite({ |
| 8 | + name: "Control UI channel wizard option contrast", |
| 9 | + startServerBeforeBrowser: true, |
| 10 | + unavailableMessage: (executablePath) => |
| 11 | + `Playwright Chromium is required for channel wizard contrast proof at ${executablePath}`, |
| 12 | +}); |
| 13 | + |
| 14 | +const proofVariant = process.env.OPENCLAW_PICKER_PROOF_VARIANT; |
| 15 | +const proofDirectory = path.join( |
| 16 | + process.cwd(), |
| 17 | + ".artifacts", |
| 18 | + "control-ui-e2e", |
| 19 | + "channel-wizard-option-contrast", |
| 20 | +); |
| 21 | + |
| 22 | +suite.define(() => { |
| 23 | + it("keeps active option subtext as legible as its label", async () => { |
| 24 | + await suite.withPage( |
| 25 | + { |
| 26 | + colorScheme: "dark", |
| 27 | + locale: "en-US", |
| 28 | + serviceWorkers: "block", |
| 29 | + viewport: { height: 900, width: 1280 }, |
| 30 | + }, |
| 31 | + async ({ page }) => { |
| 32 | + await installMockGateway(page, { |
| 33 | + featureMethods: ["channels.status", "channels.pairing.list", "wizard.start"], |
| 34 | + methodResponses: { |
| 35 | + "channels.status": { |
| 36 | + ts: Date.now(), |
| 37 | + channelOrder: ["imessage"], |
| 38 | + channelLabels: { imessage: "iMessage" }, |
| 39 | + channelMeta: [{ id: "imessage", label: "iMessage" }], |
| 40 | + channels: { imessage: { configured: true, running: true } }, |
| 41 | + channelAccounts: {}, |
| 42 | + channelDefaultAccountId: {}, |
| 43 | + }, |
| 44 | + "channels.pairing.list": { |
| 45 | + accounts: [], |
| 46 | + requests: [], |
| 47 | + commandOwnerConfigured: true, |
| 48 | + limits: { pendingPerAccount: 3, ttlMs: 3_600_000 }, |
| 49 | + }, |
| 50 | + "wizard.start": { |
| 51 | + sessionId: "channel-option-contrast-proof", |
| 52 | + done: false, |
| 53 | + status: "running", |
| 54 | + step: { |
| 55 | + id: "account", |
| 56 | + type: "select", |
| 57 | + message: "Account", |
| 58 | + initialValue: "primary", |
| 59 | + options: [ |
| 60 | + { |
| 61 | + value: "primary", |
| 62 | + label: "Primary iMessage connection", |
| 63 | + hint: "The main iMessage connection for this OpenClaw gateway", |
| 64 | + }, |
| 65 | + { |
| 66 | + value: "another", |
| 67 | + label: "Add another iMessage account", |
| 68 | + }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }); |
| 74 | + |
| 75 | + expect((await page.goto(`${suite.server.baseUrl}settings/channels`))?.status()).toBe(200); |
| 76 | + await page.locator(".channels-item", { hasText: "iMessage" }).first().click(); |
| 77 | + await page.locator(".channels-detail").getByRole("button", { name: "Run setup" }).click(); |
| 78 | + |
| 79 | + const wizard = page.locator(".channels-wizard"); |
| 80 | + const picker = wizard.locator("wa-select"); |
| 81 | + await picker.click(); |
| 82 | + await expect.poll(() => picker.getAttribute("open")).not.toBeNull(); |
| 83 | + |
| 84 | + const activeOption = wizard.locator("wa-option").filter({ |
| 85 | + has: page.getByText("Primary iMessage connection", { exact: true }), |
| 86 | + }); |
| 87 | + await expect |
| 88 | + .poll(() => activeOption.evaluate((option) => option.matches(":state(current)"))) |
| 89 | + .toBe(true); |
| 90 | + const colors = await activeOption.evaluate((option) => { |
| 91 | + const label = option.querySelector<HTMLElement>(".picker-select__label"); |
| 92 | + const description = option.querySelector<HTMLElement>(".picker-select__description"); |
| 93 | + if (!label || !description) { |
| 94 | + throw new Error("Expected the active picker option label and description"); |
| 95 | + } |
| 96 | + return { |
| 97 | + background: getComputedStyle(option).backgroundColor, |
| 98 | + description: getComputedStyle(description).color, |
| 99 | + label: getComputedStyle(label).color, |
| 100 | + }; |
| 101 | + }); |
| 102 | + |
| 103 | + if (proofVariant) { |
| 104 | + await mkdir(proofDirectory, { recursive: true }); |
| 105 | + await page.screenshot({ |
| 106 | + animations: "disabled", |
| 107 | + fullPage: true, |
| 108 | + path: path.join(proofDirectory, `${proofVariant}.png`), |
| 109 | + }); |
| 110 | + await writeFile( |
| 111 | + path.join(proofDirectory, `${proofVariant}.json`), |
| 112 | + `${JSON.stringify(colors, null, 2)}\n`, |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + expect(colors.description).toBe(colors.label); |
| 117 | + }, |
| 118 | + ); |
| 119 | + }); |
| 120 | +}); |
0 commit comments