The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { expect } from "e2e"; |
| 2 | import type { Browser } from "@e2e-dev/web"; |
| 3 | |
| 4 | import { test, WEB } from "./t3.ts"; |
| 5 | |
| 6 | // Two 1x1 PNGs, one red and one blue, that encode to the same number of bytes. |
| 7 | const RED_PIXEL = |
| 8 | "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AP8AAAMBAQCNHeWCAAAAAElFTkSuQmCC"; |
| 9 | const BLUE_PIXEL = |
| 10 | "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AAAA/wEDAQB8wnTbAAAAAElFTkSuQmCC"; |
| 11 | |
| 12 | /** Pastes a PNG the way a clipboard image arrives: a new File named image.png. */ |
| 13 | const pastePng = (browser: Browser, base64: string) => |
| 14 | browser.evaluate((payload: string) => { |
| 15 | const bytes = Uint8Array.from(atob(payload), (char) => char.charCodeAt(0)); |
| 16 | const clipboardData = new DataTransfer(); |
| 17 | clipboardData.items.add(new File([bytes], "image.png", { type: "image/png" })); |
| 18 | const editor = document.querySelector('[contenteditable="true"]'); |
| 19 | if (!editor) throw new Error("No composer editor to paste into"); |
| 20 | return editor.dispatchEvent( |
| 21 | new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }), |
| 22 | ); |
| 23 | }, base64); |
| 24 | |
| 25 | test( |
| 26 | "Two different pasted images with the same name, type and size both attach", |
| 27 | WEB, |
| 28 | async ({ t3, app, browser, screen }) => { |
| 29 | const project = await t3.project("demo"); |
| 30 | const thread = await t3.thread({ project, title: "Screenshots", messages: ["first"] }); |
| 31 | await t3.open(thread); |
| 32 | await expect(screen.getByText("first fixture turn complete", { exact: false })).toBeVisible(); |
| 33 | |
| 34 | const composer = screen.getByRole("textbox"); |
| 35 | await composer.fill("Compare "); |
| 36 | const chips = composer.getByRole("button", "Image attachment", { exact: false }); |
| 37 | |
| 38 | await pastePng(browser, RED_PIXEL); |
| 39 | await expect(chips).toHaveCount(1); |
| 40 | await pastePng(browser, BLUE_PIXEL); |
| 41 | await app.screenshot("after-second-paste"); |
| 42 | await expect(chips).toHaveCount(2); |
| 43 | }, |
| 44 | ); |