| 1 | import { beforeEach, describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { useBrowserPointerStore } from "./browserPointerStore"; |
| 4 | |
| 5 | beforeEach(() => { |
| 6 | useBrowserPointerStore.setState({ byTabId: {} }); |
| 7 | }); |
| 8 | |
| 9 | describe("browserPointerStore", () => { |
| 10 | it("tracks the latest pointer target independently for each tab", () => { |
| 11 | const store = useBrowserPointerStore.getState(); |
| 12 | store.apply({ |
| 13 | tabId: "tab_a", |
| 14 | phase: "move", |
| 15 | x: 20, |
| 16 | y: 30, |
| 17 | sequence: 0, |
| 18 | createdAt: "2026-06-12T00:00:00.000Z", |
| 19 | }); |
| 20 | store.apply({ |
| 21 | tabId: "tab_b", |
| 22 | phase: "move", |
| 23 | x: 40, |
| 24 | y: 50, |
| 25 | sequence: 1, |
| 26 | createdAt: "2026-06-12T00:00:01.000Z", |
| 27 | }); |
| 28 | store.apply({ |
| 29 | tabId: "tab_a", |
| 30 | phase: "click", |
| 31 | x: 60, |
| 32 | y: 70, |
| 33 | sequence: 2, |
| 34 | createdAt: "2026-06-12T00:00:02.000Z", |
| 35 | }); |
| 36 | |
| 37 | expect(useBrowserPointerStore.getState().byTabId).toMatchObject({ |
| 38 | tab_a: { phase: "click", x: 60, y: 70, sequence: 2 }, |
| 39 | tab_b: { phase: "move", x: 40, y: 50, sequence: 1 }, |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | it("clears one tab without affecting the others", () => { |
| 44 | const store = useBrowserPointerStore.getState(); |
| 45 | store.apply({ |
| 46 | tabId: "tab_a", |
| 47 | phase: "move", |
| 48 | x: 20, |
| 49 | y: 30, |
| 50 | sequence: 0, |
| 51 | createdAt: "2026-06-12T00:00:00.000Z", |
| 52 | }); |
| 53 | store.apply({ |
| 54 | tabId: "tab_b", |
| 55 | phase: "move", |
| 56 | x: 40, |
| 57 | y: 50, |
| 58 | sequence: 1, |
| 59 | createdAt: "2026-06-12T00:00:01.000Z", |
| 60 | }); |
| 61 | |
| 62 | store.clear("tab_a"); |
| 63 | |
| 64 | expect(useBrowserPointerStore.getState().byTabId).toEqual({ |
| 65 | tab_b: expect.objectContaining({ x: 40, y: 50 }), |
| 66 | }); |
| 67 | }); |
| 68 | }); |