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

appLinking.test.ts

67 lines2.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { shouldHandleAppLink, restoreDraftLinkState } 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)).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)).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)).toBe(false);
25 },
26 );
27});
28​
29describe("draft deep links", () => {
30 it("opens the old draft URL on the thread screen with its draft identity", () => {
31 const draft = { projectId: "project-1", environmentId: "env-1", draftId: "draft-1" };
32 expect(
33 restoreDraftLinkState(
34 { routes: [{ name: "Home" }, { name: "Thread", params: draft }] },
35 "/new/draft?draftId=draft-1",
36 ),
37 ).toEqual({
38 index: 1,
39 routes: [{ name: "Home" }, { name: "Thread", params: { draft } }],
40 });
41 });
42​
43 it.each([
44 ["environment", "NewTaskEnvironment"],
45 ["branch", "NewTaskBranch"],
46 ["files", "NewTaskFiles"],
47 ["files/src/index.ts", "NewTaskFile"],
48 ["attachments/attachment-1", "NewTaskAttachment"],
49 ["settings", "NewTaskThreadSettings"],
50 ])("restores a draft beneath its %s screen", (path, name) => {
51 const params = { environmentId: "env-1", projectId: "project-1" };
52 const target = { name, params };
53 expect(
54 restoreDraftLinkState({ routes: [{ name: "Home" }, target] }, `/new/draft/${path}`),
55 ).toEqual({
56 index: 2,
57 routes: [{ name: "Home" }, { name: "Thread", params: { draft: params } }, target],
58 });
59 });
60​
61 it("leaves live-thread and project-selection links unchanged", () => {
62 const state = { routes: [{ name: "Thread", params: { threadId: "thread-1" } }] };
63 expect(restoreDraftLinkState(state, "/threads/env-1/thread-1")).toBe(state);
64 expect(restoreDraftLinkState(state, "/new")).toBe(state);
65 expect(restoreDraftLinkState(undefined, "/new/draft")).toBeUndefined();
66 });
67});