1import { describe, expect, it } from "vite-plus/test";
2import type { ServerConfigStreamEvent } from "@t3tools/contracts";
3
4import { createKeybindingsUpdateToastController } from "./KeybindingsUpdateToast.logic";
5
6function keybindingsUpdated(issueMessages: ReadonlyArray<string>): ServerConfigStreamEvent {
7 return {
8 version: 1,
9 type: "keybindingsUpdated",
10 payload: {
11 keybindings: [],
12 issues: issueMessages.map((message, index) => ({
13 kind: "keybindings.invalid-entry" as const,
14 message,
15 index,
16 })),
17 },
18 };
19}
20
21describe("keybindings update toast", () => {
22 it("shows one warning when a save and the file watcher report the same issue", () => {
23 let currentTime = 0;
24 const controller = createKeybindingsUpdateToastController({ now: () => currentTime });
25 const invalid = { _tag: "InvalidConfiguration", message: "unknown command" };
26
27 expect(controller.handle(keybindingsUpdated(["unknown command"]))).toEqual(invalid);
28 currentTime = 100;
29 expect(controller.handle(keybindingsUpdated(["unknown command"]))).toBeNull();
30
31 currentTime = 200;
32 expect(controller.handle(keybindingsUpdated(["bad shortcut"]))).toEqual({
33 _tag: "InvalidConfiguration",
34 message: "bad shortcut",
35 });
36
37 currentTime = 5_000;
38 expect(controller.handle(keybindingsUpdated(["bad shortcut"]))).toEqual({
39 _tag: "InvalidConfiguration",
40 message: "bad shortcut",
41 });
42 currentTime = 5_100;
43 expect(controller.handle(keybindingsUpdated([]))).toEqual({ _tag: "Success" });
44 currentTime = 5_200;
45 expect(controller.handle(keybindingsUpdated([]))).toBeNull();
46 });
47});