Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

previewMiniPlayerStore.test.ts

64 lines2.5 KB

1import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2import { type EnvironmentId, ThreadId } from "@t3tools/contracts";
3import { beforeEach, describe, expect, it } from "vite-plus/test";
4​
5import { selectThreadPreviewMiniPlayer, usePreviewMiniPlayerStore } from "./previewMiniPlayerStore";
6​
7const refA = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-A"));
8const refB = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-B"));
9​
10beforeEach(() => {
11 usePreviewMiniPlayerStore.setState({ byThreadKey: {} });
12});
13​
14describe("previewMiniPlayerStore", () => {
15 it("keeps floating previews scoped to their thread", () => {
16 usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
17 usePreviewMiniPlayerStore.getState().open(refB, "tab-b");
18​
19 expect(
20 selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
21 ).toMatchObject({ tabId: "tab-a" });
22 expect(
23 selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refB),
24 ).toMatchObject({ tabId: "tab-b" });
25 });
26​
27 it("preserves position when switching the floating tab within one thread", () => {
28 usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
29 usePreviewMiniPlayerStore.getState().move(refA, "tab-a", { x: 24, y: 48 });
30 usePreviewMiniPlayerStore.getState().open(refA, "tab-b");
31​
32 expect(
33 selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
34 ).toEqual({
35 tabId: "tab-b",
36 position: { x: 24, y: 48 },
37 size: null,
38 });
39 });
40​
41 it("ignores stale drag updates after the floating tab changes", () => {
42 usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
43 usePreviewMiniPlayerStore.getState().open(refA, "tab-b");
44 usePreviewMiniPlayerStore.getState().move(refA, "tab-a", { x: 100, y: 100 });
45​
46 expect(
47 selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
48 ).toEqual({
49 tabId: "tab-b",
50 position: null,
51 size: null,
52 });
53 });
54​
55 it("preserves a thread-bound size while switching tabs", () => {
56 usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
57 usePreviewMiniPlayerStore.getState().resize(refA, "tab-a", { width: 480, height: 320 });
58 usePreviewMiniPlayerStore.getState().open(refA, "tab-b");
59​
60 expect(
61 selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
62 ).toMatchObject({ tabId: "tab-b", size: { width: 480, height: 320 } });
63 });
64});