-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathopenUrlInAppBrowser.test.ts
More file actions
73 lines (60 loc) · 2.44 KB
/
openUrlInAppBrowser.test.ts
File metadata and controls
73 lines (60 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, expect, it, vi } from "vitest";
import type { DesktopBridge, NativeApi, ProjectId, ThreadId } from "@okcode/contracts";
import { openUrlInAppBrowser } from "./openUrlInAppBrowser";
function projectId(value: string): ProjectId {
return value as ProjectId;
}
function threadId(value: string): ThreadId {
return value as ThreadId;
}
describe("openUrlInAppBrowser", () => {
it("opens in the desktop preview when project and thread ids are available", async () => {
const createTab = vi.fn<DesktopBridge["preview"]["createTab"]>().mockResolvedValue({
tabId: "tab-1",
state: { tabs: [], activeTabId: null, visible: false },
});
const setPreviewOpen = vi.fn();
const result = await openUrlInAppBrowser({
url: "https://tweakcn.com",
projectId: projectId("project-1"),
threadId: threadId("thread-1"),
previewBridge: { createTab } as unknown as DesktopBridge["preview"],
setPreviewOpen,
});
expect(result).toBe("preview");
expect(setPreviewOpen).toHaveBeenCalledWith(threadId("thread-1"), true);
expect(createTab).toHaveBeenCalledWith({
url: "https://tweakcn.com",
threadId: threadId("thread-1"),
});
});
it("pops the preview out when requested", async () => {
const createTab = vi.fn<DesktopBridge["preview"]["createTab"]>().mockResolvedValue({
tabId: "tab-1",
state: { tabs: [], activeTabId: null, visible: false },
});
const popOut = vi.fn<DesktopBridge["preview"]["popOut"]>().mockResolvedValue(undefined);
const result = await openUrlInAppBrowser({
url: "https://tweakcn.com",
projectId: projectId("project-1"),
threadId: threadId("thread-1"),
previewBridge: { createTab, popOut } as unknown as DesktopBridge["preview"],
setPreviewOpen: vi.fn(),
popOut: true,
});
expect(result).toBe("popout");
expect(createTab).toHaveBeenCalledOnce();
expect(popOut).toHaveBeenCalledOnce();
});
it("falls back to an external open when preview context is unavailable", async () => {
const openExternal = vi.fn<NativeApi["shell"]["openExternal"]>().mockResolvedValue(undefined);
const result = await openUrlInAppBrowser({
url: "https://tweakcn.com",
projectId: null,
threadId: null,
nativeApi: { shell: { openExternal } } as unknown as NativeApi,
});
expect(result).toBe("external");
expect(openExternal).toHaveBeenCalledWith("https://tweakcn.com");
});
});