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

browserLinkTarget.test.ts

69 lines1.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveLinkTarget } from "./browserLinkTarget";
4​
5const click = { metaKey: false, ctrlKey: false };
6​
7describe("resolveLinkTarget", () => {
8 it("keeps the system browser unless the user asked for in-app", () => {
9 expect(
10 resolveLinkTarget({
11 url: "https://example.com/",
12 event: click,
13 preference: "system",
14 canOpenInApp: true,
15 }),
16 ).toBe("system");
17 });
18​
19 it("opens in-app when asked and the runtime can", () => {
20 expect(
21 resolveLinkTarget({
22 url: "https://example.com/",
23 event: click,
24 preference: "app",
25 canOpenInApp: true,
26 }),
27 ).toBe("app");
28 });
29​
30 it("falls back to the system browser where there is no in-app browser", () => {
31 // The hosted web app and mobile have nowhere to open a tab, so the
32 // preference cannot be honoured there and the link still has to open.
33 expect(
34 resolveLinkTarget({
35 url: "https://example.com/",
36 event: click,
37 preference: "app",
38 canOpenInApp: false,
39 }),
40 ).toBe("system");
41 });
42​
43 it("treats a modifier click as the way out of the in-app default", () => {
44 expect(
45 resolveLinkTarget({
46 url: "https://example.com/",
47 event: { metaKey: true, ctrlKey: false },
48 preference: "app",
49 canOpenInApp: true,
50 }),
51 ).toBe("system");
52 expect(
53 resolveLinkTarget({
54 url: "https://example.com/",
55 event: { metaKey: false, ctrlKey: true },
56 preference: "app",
57 canOpenInApp: true,
58 }),
59 ).toBe("system");
60 });
61​
62 it("leaves non-web schemes to the shell", () => {
63 for (const url of ["mailto:someone@example.com", "vscode://file/x", "not a url"]) {
64 expect(resolveLinkTarget({ url, event: click, preference: "app", canOpenInApp: true })).toBe(
65 "system",
66 );
67 }
68 });
69});