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

server-preview-app-link-stops-loading.e2e.ts

53 lines2.3 KB

1// @effect-diagnostics-next-line nodeBuiltinImport:off - one fixture page for the server's browser to load
2import * as NodeHttp from "node:http";
3​
4import { expect } from "e2e";
5​
6import { test, WEB } from "./t3.ts";
7​
8// One app link that fills the page. Its click renames the page a moment later, after the server
9// has seen the link's request.
10const PAGE = `<!doctype html>
11<title>Note link</title>
12<a href="obsidian://open?vault=demo&amp;file=Note" style="display:block;height:100vh"
13 onclick="setTimeout(function () { document.title = 'Link clicked'; }, 500)">Open the note</a>`;
14​
15test(
16 "An app link clicked in the Browser leaves the page shown and loaded",
17 WEB,
18 async ({ t3, app, browser, screen }) => {
19 const server = NodeHttp.createServer((_request, response) => {
20 response.writeHead(200, { "content-type": "text/html" });
21 response.end(PAGE);
22 });
23 await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
24 try {
25 const address = server.address();
26 if (address === null || typeof address === "string") throw new Error("No page port.");
27 const url = `http://127.0.0.1:${address.port}/`;
28 const project = await t3.project("demo");
29 const thread = await t3.thread({ project, title: "Note check", messages: ["first"] });
30 await t3.open(thread);
31​
32 await screen.getByRole("button", "Toggle right panel").tap();
33 await screen.getByRole("button", "Browser B").tap();
34 const addressBar = screen.getByRole("textbox", "Search or enter URL");
35 await addressBar.fill(url);
36 await browser.keyboard.press("Enter");
37 await expect(screen.getByText("Note link")).toBeVisible();
38​
39 // The page draws on the canvas beside its input proxy.
40 await browser.locator('canvas:has(~ textarea[aria-label="Browser page"])').tap();
41 try {
42 // Chromium hands the link to the OS and keeps the page, which goes on renaming itself.
43 await expect(screen.getByText("Link clicked")).toBeVisible({ timeout: 2_000 });
44 await expect(addressBar).toHaveValue(url);
45 await expect(screen.getByRole("button", "Refresh", { exact: true })).toBeVisible();
46 } finally {
47 await app.screenshot("after-click");
48 }
49 } finally {
50 await new Promise((resolve) => server.close(resolve));
51 }
52 },
53);