-
-
Notifications
You must be signed in to change notification settings - Fork 984
Expand file tree
/
Copy pathwebview.test.tsx
More file actions
59 lines (51 loc) · 2.24 KB
/
webview.test.tsx
File metadata and controls
59 lines (51 loc) · 2.24 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
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { globalStore } from "@/app/store/jotaiStore";
import { makeMockWaveEnv } from "@/preview/mock/mockwaveenv";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { atom } from "jotai";
import { getWebPreviewDisplayUrl, WebViewModel, WebViewPreviewFallback } from "./webview";
describe("webview preview fallback", () => {
it("shows the requested URL", () => {
const markup = renderToStaticMarkup(<WebViewPreviewFallback url="https://waveterm.dev/docs" />);
expect(markup).toContain("electron webview unavailable");
expect(markup).toContain("https://waveterm.dev/docs");
});
it("falls back to about:blank when no URL is available", () => {
expect(getWebPreviewDisplayUrl("")).toBe("about:blank");
expect(getWebPreviewDisplayUrl(null)).toBe("about:blank");
});
it("uses the supplied env for homepage atoms and config updates", async () => {
const blockId = "webview-env-block";
const env = makeMockWaveEnv({
settings: {
"web:defaulturl": "https://default.example",
},
mockWaveObjs: {
[`block:${blockId}`]: {
otype: "block",
oid: blockId,
version: 1,
meta: {
pinnedurl: "https://block.example",
},
} as Block,
},
});
const model = new WebViewModel({
blockId,
nodeModel: {
isFocused: atom(true),
focusNode: () => {},
} as any,
tabModel: {} as any,
waveEnv: env,
});
expect(globalStore.get(model.homepageUrl)).toBe("https://block.example");
await model.setHomepageUrl("https://global.example", "global");
expect(globalStore.get(model.homepageUrl)).toBe("https://global.example");
expect(globalStore.get(env.getSettingsKeyAtom("web:defaulturl"))).toBe("https://global.example");
expect(globalStore.get(env.wos.getWaveObjectAtom<Block>(`block:${blockId}`))?.meta?.pinnedurl).toBeUndefined();
});
});