Skip to content

Commit b81a690

Browse files
committed
Add smoke test for windowManagerStore
1 parent 949b478 commit b81a690

1 file changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { createPinia, setActivePinia } from "pinia";
2+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+
4+
import { useWindowManagerStore } from "./windowManagerStore";
5+
6+
describe("windowManagerStore", () => {
7+
beforeEach(() => {
8+
setActivePinia(createPinia());
9+
localStorage.clear();
10+
vi.useFakeTimers();
11+
});
12+
13+
afterEach(() => {
14+
vi.useRealTimers();
15+
});
16+
17+
it("toggles active state", () => {
18+
const store = useWindowManagerStore();
19+
expect(store.active).toBe(false);
20+
store.toggle();
21+
expect(store.active).toBe(true);
22+
store.toggle();
23+
expect(store.active).toBe(false);
24+
});
25+
26+
it("adds a window and focuses it", () => {
27+
const store = useWindowManagerStore();
28+
store.add({ title: "One", url: "/foo" });
29+
expect(store.windows).toHaveLength(1);
30+
const win = store.windows[0]!;
31+
expect(win.title).toBe("One");
32+
expect(win.url).toBe("/foo");
33+
expect(win.width).toBe(600);
34+
expect(win.height).toBe(400);
35+
expect(win.minimized).toBe(false);
36+
expect(win.maximized).toBe(false);
37+
expect(store.focusedId).toBe(win.id);
38+
});
39+
40+
it("removes a window and refocuses the last remaining one", () => {
41+
const store = useWindowManagerStore();
42+
store.add({ title: "A", url: "/a" });
43+
store.add({ title: "B", url: "/b" });
44+
const a = store.windows[0]!;
45+
const b = store.windows[1]!;
46+
store.remove(b.id);
47+
expect(store.windows).toHaveLength(1);
48+
expect(store.focusedId).toBe(a.id);
49+
store.remove(a.id);
50+
expect(store.windows).toHaveLength(0);
51+
expect(store.focusedId).toBeNull();
52+
});
53+
54+
it("raises zIndex when focusing a different window", () => {
55+
const store = useWindowManagerStore();
56+
store.add({ url: "/a" });
57+
store.add({ url: "/b" });
58+
const a = store.windows[0]!;
59+
const b = store.windows[1]!;
60+
expect(b.zIndex).toBeGreaterThan(a.zIndex);
61+
store.focus(a.id);
62+
expect(store.focusedId).toBe(a.id);
63+
expect(a.zIndex).toBeGreaterThan(b.zIndex);
64+
});
65+
66+
it("updates position and size", () => {
67+
const store = useWindowManagerStore();
68+
store.add({ url: "/a" });
69+
const win = store.windows[0]!;
70+
store.updatePosition(win.id, 123, 456);
71+
expect(win.x).toBe(123);
72+
expect(win.y).toBe(456);
73+
store.updateSize(win.id, 800, 500);
74+
expect(win.width).toBe(800);
75+
expect(win.height).toBe(500);
76+
});
77+
78+
it("toggles minimize and moves focus to another open window", () => {
79+
const store = useWindowManagerStore();
80+
store.add({ url: "/a" });
81+
store.add({ url: "/b" });
82+
const a = store.windows[0]!;
83+
const b = store.windows[1]!;
84+
store.focus(b.id);
85+
store.toggleMinimize(b.id);
86+
expect(b.minimized).toBe(true);
87+
expect(store.focusedId).toBe(a.id);
88+
store.toggleMinimize(b.id);
89+
expect(b.minimized).toBe(false);
90+
expect(store.focusedId).toBe(b.id);
91+
});
92+
93+
it("un-minimizes when toggling maximize on a minimized window", () => {
94+
const store = useWindowManagerStore();
95+
store.add({ url: "/a" });
96+
const win = store.windows[0]!;
97+
store.toggleMinimize(win.id);
98+
expect(win.minimized).toBe(true);
99+
store.toggleMaximize(win.id);
100+
expect(win.maximized).toBe(true);
101+
expect(win.minimized).toBe(false);
102+
});
103+
104+
it("beforeUnload reflects whether any windows are open", () => {
105+
const store = useWindowManagerStore();
106+
expect(store.beforeUnload()).toBe(false);
107+
store.add({ url: "/a" });
108+
expect(store.beforeUnload()).toBe(true);
109+
});
110+
111+
it("persists to localStorage and restores on demand", () => {
112+
const store = useWindowManagerStore();
113+
store.add({ title: "Saved", url: "/saved", x: 50, y: 60, width: 700, height: 450 });
114+
vi.runAllTimers();
115+
const raw = localStorage.getItem("galaxy-window-manager-windows");
116+
expect(raw).not.toBeNull();
117+
118+
// Fresh store should start empty, then restore from the same localStorage.
119+
setActivePinia(createPinia());
120+
const fresh = useWindowManagerStore();
121+
expect(fresh.windows).toHaveLength(0);
122+
fresh.restore();
123+
expect(fresh.active).toBe(true);
124+
expect(fresh.windows).toHaveLength(1);
125+
expect(fresh.windows[0]).toMatchObject({
126+
title: "Saved",
127+
url: "/saved",
128+
x: 50,
129+
y: 60,
130+
width: 700,
131+
height: 450,
132+
});
133+
});
134+
135+
it("buildUrl appends hide_panels and hide_masthead query params", () => {
136+
const store = useWindowManagerStore();
137+
const url = store.buildUrl("/tool/runner?tool_id=foo");
138+
expect(url).toContain("tool_id=foo");
139+
expect(url).toContain("hide_panels=true");
140+
expect(url).toContain("hide_masthead=true");
141+
});
142+
143+
it("getTab exposes a masthead entry that toggles the window manager", () => {
144+
const store = useWindowManagerStore();
145+
const tab = store.getTab();
146+
expect(tab.id).toBe("enable-window-manager");
147+
expect(tab.visible).toBe(true);
148+
tab.onclick();
149+
expect(store.active).toBe(true);
150+
});
151+
});

0 commit comments

Comments
 (0)