Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composer-paste-to-code-block.e2e.ts

43 lines1.5 KB

1/// <reference lib="dom" />
2import { expect } from "e2e";
3​
4import { test, WEB } from "./t3.ts";
5​
6test(
7 "Pasting into an unfocused composer appends literal text inside its last code block",
8 WEB,
9 async ({ t3, app, browser, screen }) => {
10 const project = await t3.project("demo");
11 const thread = await t3.thread({ project, title: "Paste into code", messages: ["first"] });
12 await t3.open(thread);
13 const composer = screen.getByRole("textbox");
14 await composer.tap();
15​
16 await browser.evaluate(() => {
17 const editor = document.activeElement;
18 if (!(editor instanceof HTMLElement) || !editor.isContentEditable) {
19 throw new Error("The composer is not focused");
20 }
21 const clipboardData = new DataTransfer();
22 clipboardData.setData("text/plain", "```text\nprefix \n```");
23 editor.dispatchEvent(
24 new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }),
25 );
26 editor.blur();
27 clipboardData.setData("text/plain", "Setup guide");
28 clipboardData.setData("text/html", '<a href="https://example.com/setup">Setup guide</a>');
29 document.body.dispatchEvent(
30 new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }),
31 );
32 return null;
33 });
34​
35 await app.screenshot("pasted-into-code-block");
36 const code = await browser.evaluate(() => {
37 return (
38 document.querySelector('[data-testid="composer-editor"] pre code')?.textContent ?? null
39 );
40 });
41 expect(code).toBe("prefix Setup guide");
42 },
43);