-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpreviewStateStore.test.ts
More file actions
59 lines (49 loc) · 1.81 KB
/
Copy pathpreviewStateStore.test.ts
File metadata and controls
59 lines (49 loc) · 1.81 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
import { beforeEach, describe, expect, it, vi } from "vitest";
const STORAGE_KEY = "okcode:desktop-preview:v3";
let usePreviewStateStore: typeof import("./previewStateStore").usePreviewStateStore;
let storage: Map<string, string>;
describe("previewStateStore", () => {
beforeEach(async () => {
vi.resetModules();
storage = new Map<string, string>();
vi.stubGlobal("window", {
localStorage: {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => {
storage.set(key, value);
},
removeItem: (key: string) => {
storage.delete(key);
},
clear: () => {
storage.clear();
},
},
} as Window);
({ usePreviewStateStore } = await import("./previewStateStore"));
usePreviewStateStore.setState({
globalOpen: false,
dockByThreadId: {},
sizeByThreadId: {},
presetByThreadId: {},
favoriteUrls: [],
});
storage.clear();
});
it("persists and clears favorite URLs", () => {
const store = usePreviewStateStore.getState();
store.addFavoriteUrl("http://localhost:3000/");
expect(usePreviewStateStore.getState().favoriteUrls).toContain("http://localhost:3000/");
expect(storage.get(STORAGE_KEY)).toContain('"favoriteUrls"');
store.toggleFavoriteUrl("http://localhost:3000/");
expect(usePreviewStateStore.getState().favoriteUrls).not.toContain("http://localhost:3000/");
});
it("toggles globalOpen", () => {
const store = usePreviewStateStore.getState();
store.setGlobalOpen(true);
expect(usePreviewStateStore.getState().globalOpen).toBe(true);
expect(storage.get(STORAGE_KEY)).toContain('"globalOpen":true');
store.toggleGlobalOpen();
expect(usePreviewStateStore.getState().globalOpen).toBe(false);
});
});