The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 2 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 3 | import { expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { selectActiveRightPanelSurface, useRightPanelStore } from "../rightPanelStore"; |
| 6 | import { selectThreadRightPanelState } from "../rightPanelStore"; |
| 7 | import { openSideThread, resolveThreadOpenRoute } from "./sideChatPane"; |
| 8 | |
| 9 | const environmentId = EnvironmentId.make("environment:test"); |
| 10 | const mainRef = scopeThreadRef(environmentId, ThreadId.make("main")); |
| 11 | const sideChatRef = scopeThreadRef(environmentId, ThreadId.make("side-chat")); |
| 12 | |
| 13 | it("routes a side chat to its parent with the side chat tab active", () => { |
| 14 | useRightPanelStore.setState(useRightPanelStore.getInitialState()); |
| 15 | const route = resolveThreadOpenRoute(sideChatRef, { |
| 16 | lineage: { sideChat: true, parentThreadId: mainRef.threadId } as never, |
| 17 | }); |
| 18 | |
| 19 | expect(route).toEqual(mainRef); |
| 20 | expect( |
| 21 | selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, mainRef)?.id, |
| 22 | ).toBe("thread:side-chat"); |
| 23 | expect( |
| 24 | resolveThreadOpenRoute(mainRef, { |
| 25 | lineage: { sideChat: false, parentThreadId: null } as never, |
| 26 | }), |
| 27 | ).toBe(mainRef); |
| 28 | }); |
| 29 | |
| 30 | it("opens a side thread beside the thread the click was in, or in its place", () => { |
| 31 | useRightPanelStore.setState(useRightPanelStore.getInitialState()); |
| 32 | const navigated: unknown[] = []; |
| 33 | const open = ( |
| 34 | input: Pick<Parameters<typeof openSideThread>[0], "threadRef" | "panelRef" | "intent">, |
| 35 | ) => openSideThread({ ...input, navigate: (ref) => void navigated.push(ref) }); |
| 36 | const surfaces = () => |
| 37 | selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, mainRef).surfaces; |
| 38 | |
| 39 | expect(open({ threadRef: sideChatRef, panelRef: mainRef, intent: "primary" })).toBe("panel"); |
| 40 | expect(surfaces().map((surface) => surface.id)).toEqual(["thread:side-chat"]); |
| 41 | expect(navigated).toEqual([]); |
| 42 | |
| 43 | expect(open({ threadRef: sideChatRef, panelRef: mainRef, intent: "alternate" })).toBe("main"); |
| 44 | expect(navigated).toEqual([sideChatRef]); |
| 45 | |
| 46 | // No panel shows a thread beside itself, of another environment, or where there is none. |
| 47 | const elsewhere = scopeThreadRef(EnvironmentId.make("environment:other"), sideChatRef.threadId); |
| 48 | expect(open({ threadRef: mainRef, panelRef: mainRef, intent: "panel" })).toBe("main"); |
| 49 | expect(open({ threadRef: elsewhere, panelRef: mainRef, intent: "panel" })).toBe("main"); |
| 50 | expect(open({ threadRef: sideChatRef, panelRef: null, intent: "panel" })).toBe("main"); |
| 51 | expect(navigated).toEqual([sideChatRef, mainRef, elsewhere, sideChatRef]); |
| 52 | expect(surfaces()).toHaveLength(1); |
| 53 | }); |