feat(web): float device streams over chat (#11285)
Co-authored-by: Claude Code <[email protected]>
This commit is contained in:
1 parent
e22040dfc1
commit
8bbe2bf660
15 files changed
+612
-167
No files matched your search
@@ -2,10 +2,25 @@ 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";
|
||||
import {
|
||||
browserMiniPlayerSource,
|
||||
type PreviewMiniPlayerSource,
|
||||
selectThreadPreviewMiniPlayer,
|
||||
selectThreadPreviewMiniPlayerTabId,
|
||||
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"));
|
||||
const tabA = browserMiniPlayerSource("tab-a");
|
||||
const tabB = browserMiniPlayerSource("tab-b");
|
||||
const pixel: PreviewMiniPlayerSource = {
|
||||
kind: "device",
|
||||
hostId: "nucbox",
|
||||
deviceId: "emulator-5580",
|
||||
platform: "android",
|
||||
name: "Pixel",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
usePreviewMiniPlayerStore.setState({ byThreadKey: {} });
|
||||
@@ -13,52 +28,71 @@ beforeEach(() => {
|
||||
|
||||
describe("previewMiniPlayerStore", () => {
|
||||
it("keeps floating previews scoped to their thread", () => {
|
||||
usePreviewMiniPlayerStore.getState().open(refA, "tab-a");
|
||||
usePreviewMiniPlayerStore.getState().open(refB, "tab-b");
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabA);
|
||||
usePreviewMiniPlayerStore.getState().open(refB, tabB);
|
||||
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
||||
).toMatchObject({ tabId: "tab-a" });
|
||||
).toMatchObject({ source: tabA });
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refB),
|
||||
).toMatchObject({ tabId: "tab-b" });
|
||||
).toMatchObject({ source: tabB });
|
||||
});
|
||||
|
||||
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");
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabA);
|
||||
usePreviewMiniPlayerStore.getState().move(refA, "browser:tab-a", { x: 24, y: 48 });
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabB);
|
||||
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
||||
).toEqual({
|
||||
tabId: "tab-b",
|
||||
source: tabB,
|
||||
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 });
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabA);
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabB);
|
||||
usePreviewMiniPlayerStore.getState().move(refA, "browser:tab-a", { x: 100, y: 100 });
|
||||
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
||||
).toEqual({
|
||||
tabId: "tab-b",
|
||||
source: tabB,
|
||||
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");
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabA);
|
||||
usePreviewMiniPlayerStore.getState().resize(refA, "browser:tab-a", 480);
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabB);
|
||||
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
||||
).toMatchObject({ tabId: "tab-b", width: 480 });
|
||||
).toMatchObject({ source: tabB, width: 480 });
|
||||
});
|
||||
|
||||
it("floats one source per thread, so a device replaces the browser tab", () => {
|
||||
usePreviewMiniPlayerStore.getState().open(refA, tabA);
|
||||
usePreviewMiniPlayerStore.getState().open(refA, pixel);
|
||||
const floating = selectThreadPreviewMiniPlayer(
|
||||
usePreviewMiniPlayerStore.getState().byThreadKey,
|
||||
refA,
|
||||
);
|
||||
|
||||
expect(floating).toMatchObject({ source: pixel });
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayerTabId(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
||||
).toBeNull();
|
||||
// The same device under a new label is still the same floating source.
|
||||
usePreviewMiniPlayerStore.getState().open(refA, { ...pixel, name: "Renamed" });
|
||||
expect(
|
||||
selectThreadPreviewMiniPlayer(usePreviewMiniPlayerStore.getState().byThreadKey, refA),
|
||||
).toBe(floating);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user