Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
|
|
import { type EnvironmentId, ThreadId } from "@t3tools/contracts";
|
|
import { beforeEach, describe, expect, it } from "vite-plus/test";
|
|
|
|
import { selectThreadPreviewMiniPlayer, usePreviewMiniPlayerStore } from "./previewMiniPlayerStore";
|
|
|
|
const refA = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-A"));
|
|
const refB = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-B"));
|
|
|
|
beforeEach(() => {
|
|
usePreviewMiniPlayerStore.setState({ byThreadKey: {} });
|
|
});
|
|
|
|
describe("previewMiniPlayerStore", () => {
|
|
it("keeps floating previews scoped to their thread", () => {
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
|
|
usePreviewMiniPlayerStore.getState().open(refB, "tab-b");
|
|
|
|
expect(
|
|
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
|
).toMatchObject({ tabId: "tab-a" });
|
|
expect(
|
|
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refB),
|
|
).toMatchObject({ tabId: "tab-b" });
|
|
});
|
|
|
|
it("preserves position when switching the floating tab within one thread", () => {
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
|
|
usePreviewMiniPlayerStore.getState().move(refA, "tab-a", { x: 24, y: 48 });
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-b");
|
|
|
|
expect(
|
|
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
|
).toEqual({
|
|
tabId: "tab-b",
|
|
position: { x: 24, y: 48 },
|
|
width: null,
|
|
});
|
|
});
|
|
|
|
it("ignores stale drag updates after the floating tab changes", () => {
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-b");
|
|
usePreviewMiniPlayerStore.getState().move(refA, "tab-a", { x: 100, y: 100 });
|
|
|
|
expect(
|
|
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
|
).toEqual({
|
|
tabId: "tab-b",
|
|
position: null,
|
|
width: null,
|
|
});
|
|
});
|
|
|
|
it("preserves a thread-bound width while switching tabs", () => {
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
|
|
usePreviewMiniPlayerStore.getState().resize(refA, "tab-a", 480);
|
|
usePreviewMiniPlayerStore.getState().open(refA, "tab-b");
|
|
|
|
expect(
|
|
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
|
).toMatchObject({ tabId: "tab-b", width: 480 });
|
|
});
|
|
});
|