Repository navigation
Expand file tree
/
Copy pathKeybindingsUpdateToast.test.ts
More file actions
65 lines (59 loc) · 2.21 KB
/
Copy pathKeybindingsUpdateToast.test.ts
File metadata and controls
65 lines (59 loc) · 2.21 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
import type { ServerConfigStreamEvent } from "@t3tools/contracts";
import { describe, expect, it, vi } from "vite-plus/test";
const mocks = vi.hoisted(() => ({
state: null as unknown as import("effect/reactivity").Atom.Writable<{
readonly latestEvent: ServerConfigStreamEvent | null;
}>,
addToast: vi.fn<(toast: { readonly title?: unknown }) => void>(),
}));
// The event atom is derived from server state, as in production; nothing else reads it.
vi.mock(import("../state/server"), async () => {
const { Atom } = await import("effect/reactivity");
mocks.state = Atom.make<{ readonly latestEvent: ServerConfigStreamEvent | null }>({
latestEvent: null,
});
return {
primaryServerConfigAtom: Atom.make(null),
primaryServerConfigEventAtom: Atom.make((get) => get(mocks.state).latestEvent),
} as never;
});
vi.mock(import("../state/primaryEnvironment"), async () => {
const { Atom } = await import("effect/reactivity");
return { primaryEnvironmentIdAtom: Atom.make(null) } as never;
});
vi.mock(
import("./KeybindingsConfigWarning"),
() => ({ KeybindingsConfigWarning: () => null }) as never,
);
vi.mock(
import("./ui/toast"),
() =>
({
toastManager: { add: mocks.addToast },
stackedThreadToast: (toast: unknown) => toast,
}) as never,
);
import { appAtomRegistry } from "../rpc/atomRegistry";
import { startKeybindingsUpdateToasts } from "./KeybindingsUpdateToast";
function keybindingsUpdated(issues: ReadonlyArray<unknown>): ServerConfigStreamEvent {
return { type: "keybindingsUpdated", payload: { keybindings: [], issues } } as never;
}
describe("startKeybindingsUpdateToasts", () => {
it("toasts reloads the server reports after start", () => {
const stop = startKeybindingsUpdateToasts();
try {
appAtomRegistry.set(mocks.state, { latestEvent: keybindingsUpdated([]) });
appAtomRegistry.set(mocks.state, {
latestEvent: keybindingsUpdated([
{ kind: "keybindings.malformed-config", message: "Unexpected token" },
]),
});
expect(mocks.addToast.mock.calls.map(([toast]) => toast.title)).toEqual([
"Keybindings updated",
"Invalid keybindings configuration",
]);
} finally {
stop();
}
});
});