The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 2 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 3 | import { beforeEach, expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { selectThreadRightPanelState, useRightPanelStore } from "../rightPanelStore"; |
| 6 | import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore"; |
| 7 | import { revealThreadTerminal } from "./revealThreadTerminal"; |
| 8 | |
| 9 | const threadRef = scopeThreadRef(EnvironmentId.make("local"), ThreadId.make("settled-thread")); |
| 10 | const remoteRef = scopeThreadRef(EnvironmentId.make("remote"), threadRef.threadId); |
| 11 | |
| 12 | beforeEach(() => { |
| 13 | useTerminalUiStateStore.setState({ |
| 14 | terminalUiStateByThreadKey: {}, |
| 15 | suppressedTerminalIdsByThreadKey: {}, |
| 16 | }); |
| 17 | useRightPanelStore.setState({ byThreadKey: {} }); |
| 18 | }); |
| 19 | |
| 20 | it("reopens the existing panel and selects a running terminal in its split", () => { |
| 21 | const panels = useRightPanelStore.getState(); |
| 22 | panels.openTerminal(threadRef, "terminal-1"); |
| 23 | const surfaceId = selectThreadRightPanelState( |
| 24 | useRightPanelStore.getState().byThreadKey, |
| 25 | threadRef, |
| 26 | ).activeSurfaceId!; |
| 27 | panels.splitTerminal(threadRef, surfaceId, "setup-install"); |
| 28 | panels.activateTerminal(threadRef, surfaceId, "terminal-1"); |
| 29 | panels.close(threadRef); |
| 30 | |
| 31 | revealThreadTerminal(threadRef, "setup-install"); |
| 32 | expect( |
| 33 | selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef), |
| 34 | ).toMatchObject({ |
| 35 | isOpen: true, |
| 36 | activeSurfaceId: surfaceId, |
| 37 | surfaces: [ |
| 38 | { |
| 39 | terminalIds: ["terminal-1", "setup-install"], |
| 40 | activeTerminalId: "setup-install", |
| 41 | }, |
| 42 | ], |
| 43 | }); |
| 44 | expect( |
| 45 | selectThreadTerminalUiState( |
| 46 | useTerminalUiStateStore.getState().terminalUiStateByThreadKey, |
| 47 | threadRef, |
| 48 | ).terminalIds, |
| 49 | ).toEqual([]); |
| 50 | }); |
| 51 | |
| 52 | it("reveals terminals in their own environment without changing another environment's drawer", () => { |
| 53 | revealThreadTerminal(threadRef, "default"); |
| 54 | revealThreadTerminal(remoteRef, "setup-install"); |
| 55 | const state = useTerminalUiStateStore.getState().terminalUiStateByThreadKey; |
| 56 | expect(selectThreadTerminalUiState(state, threadRef).terminalIds).toEqual(["default"]); |
| 57 | expect(selectThreadTerminalUiState(state, remoteRef).terminalIds).toEqual(["setup-install"]); |
| 58 | }); |