Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { findLinkedRoute, restoreDraftLinkState, shouldHandleAppLink } from "./appLinking";
4
5describe("shouldHandleAppLink", () => {
6 it.each(["t3code://", "t3code:///", "t3code-dev://", "t3code-preview://"])(
7 "ignores scheme-only URL %s",
8 (url) => {
9 expect(shouldHandleAppLink(url, true)).toBe(false);
10 },
11 );
12
13 it.each([
14 "t3code://threads/env-1/thread-1",
15 "t3code://pair?pairingUrl=x",
16 "t3code-dev://settings/usage?tab=limits",
17 ])("handles path-bearing URL %s", (url) => {
18 expect(shouldHandleAppLink(url, true)).toBe(true);
19 });
20
21 it.each(["t3code://expo-development-client/?url=x", "t3code://expo-sharing/anything"])(
22 "ignores lifecycle URL %s",
23 (url) => {
24 expect(shouldHandleAppLink(url, true)).toBe(false);
25 },
26 );
27});
28
29describe("cloud-only deep links", () => {
30 it.each([
31 "t3code://connect-onboarding",
32 "t3code-dev://connect-onboarding/?source=x",
33 "t3code://settings/waitlist",
34 "t3code://settings/auth",
35 "exp://192.168.1.2:8081/--/settings/auth",
36 ])("ignores %s without cloud config", (url) => {
37 expect(shouldHandleAppLink(url, false)).toBe(false);
38 expect(shouldHandleAppLink(url, true)).toBe(true);
39 });
40
41 it.each([
42 "t3code://settings",
43 "t3code://settings/authors",
44 "t3code://pair?next=settings/auth",
45 "t3code://threads/env/thread/files/scripts/connect-onboarding",
46 "t3code://new/draft/files/settings/auth",
47 "exp://192.168.1.2:8081/--/threads/env/thread/files/settings/waitlist",
48 ])("still handles %s without cloud config", (url) => {
49 expect(shouldHandleAppLink(url, false)).toBe(true);
50 });
51});
52
53describe("draft deep links", () => {
54 it("opens the old draft URL on the thread screen with its draft identity", () => {
55 const draft = { projectId: "project-1", environmentId: "env-1", draftId: "draft-1" };
56 expect(
57 restoreDraftLinkState(
58 { routes: [{ name: "Home" }, { name: "Thread", params: draft }] },
59 "/new/draft?draftId=draft-1",
60 ),
61 ).toEqual({
62 index: 1,
63 routes: [{ name: "Home" }, { name: "Thread", params: { draft } }],
64 });
65 });
66
67 it.each([
68 ["environment", "NewTaskEnvironment"],
69 ["branch", "NewTaskBranch"],
70 ["files", "NewTaskFiles"],
71 ["files/src/index.ts", "NewTaskFile"],
72 ["attachments/attachment-1", "NewTaskAttachment"],
73 ["settings", "NewTaskThreadSettings"],
74 ])("restores a draft beneath its %s screen", (path, name) => {
75 const params = { environmentId: "env-1", projectId: "project-1" };
76 const target = { name, params };
77 expect(
78 restoreDraftLinkState({ routes: [{ name: "Home" }, target] }, `/new/draft/${path}`),
79 ).toEqual({
80 index: 2,
81 routes: [{ name: "Home" }, { name: "Thread", params: { draft: params } }, target],
82 });
83 });
84
85 it("leaves live-thread and project-selection links unchanged", () => {
86 const state = { routes: [{ name: "Thread", params: { threadId: "thread-1" } }] };
87 expect(restoreDraftLinkState(state, "/threads/env-1/thread-1")).toBe(state);
88 expect(restoreDraftLinkState(state, "/new")).toBe(state);
89 expect(restoreDraftLinkState(undefined, "/new/draft")).toBeUndefined();
90 });
91});
92
93describe("nested link routes", () => {
94 const settingsLink = {
95 routes: [
96 { name: "Home" },
97 {
98 name: "SettingsSheet",
99 state: {
100 routes: [
101 { name: "Settings" },
102 { name: "SettingsEnvironmentNew", params: { pairingUrl: "x", autoConnect: "1" } },
103 ],
104 },
105 },
106 ],
107 };
108
109 it("finds a route the link opens inside a nested navigator", () => {
110 expect(findLinkedRoute(settingsLink, ["SettingsEnvironmentNew"])?.params).toEqual({
111 pairingUrl: "x",
112 autoConnect: "1",
113 });
114 expect(findLinkedRoute(settingsLink, ["ConnectionsNew"])).toBeUndefined();
115 });
116});