@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 62 lines 2.56 KB
Raw
1 import { expect } from "e2e";
2 import type { Browser } from "@e2e-dev/web";
3
4 import {
5 expectHeldImageCompressions,
6 finishNextImageCompression,
7 holdImageCompression,
8 } from "./image-compression-hold.ts";
9 import { test, WEB } from "./t3.ts";
10
11 /** Copies a PNG over the 2000 px limit, so pasting it compresses; noise keeps it large. */
12 const copyWidePng = (browser: Browser, noise: boolean) =>
13 browser.evaluate(async (noisy: boolean) => {
14 const canvas = new OffscreenCanvas(2200, noisy ? 200 : 20);
15 const context = canvas.getContext("2d")!;
16 const pixels = context.createImageData(canvas.width, canvas.height);
17 let seed = 1;
18 for (let index = 0; index < pixels.data.length; index++) {
19 seed ^= seed << 13;
20 seed ^= seed >>> 17;
21 seed ^= seed << 5;
22 pixels.data[index] = index % 4 === 3 ? 255 : noisy ? seed & 255 : 40;
23 }
24 context.putImageData(pixels, 0, 0);
25 const png = await canvas.convertToBlob({ type: "image/png" });
26 await navigator.clipboard.write([new ClipboardItem({ "image/png": png })]);
27 return png.size;
28 }, noise);
29
30 test(
31 "An image pasted while an earlier pasted image prepares lands after it before a space in the prompt",
32 WEB,
33 async ({ t3, app, browser, screen }) => {
34 await holdImageCompression(browser);
35 const project = await t3.project("demo");
36 const thread = await t3.thread({ project, title: "Screenshots", messages: ["first"] });
37 await t3.open(thread);
38 await expect(screen.getByText("first fixture turn complete", { exact: false })).toBeVisible();
39
40 const composer = screen.getByRole("textbox");
41 await composer.fill("Compare screenshots");
42 await browser.keyboard.press("Home");
43 for (let index = 0; index < "Compare".length; index++) {
44 await browser.keyboard.press("ArrowRight");
45 }
46 await copyWidePng(browser, false);
47 await browser.keyboard.press("ControlOrMeta+V");
48 await expectHeldImageCompressions(browser, 1);
49 await copyWidePng(browser, true);
50 await browser.keyboard.press("ControlOrMeta+V");
51 await expectHeldImageCompressions(browser, 2);
52
53 await finishNextImageCompression(browser);
54 await finishNextImageCompression(browser);
55 const chips = composer.getByRole("button", "Image attachment", { exact: false });
56 await expect(chips).toHaveCount(2);
57 await app.screenshot("both-images-prepared");
58 // The solid image, pasted first, is the 1 KB one.
59 await expect(chips.first()).toHaveAccessibleName("Image attachment, image.png, 1 KB");
60 await expect(chips.nth(1)).not.toHaveAccessibleName("Image attachment, image.png, 1 KB");
61 },
62 );