|
| 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("reveals a server-created setup terminal without adding a default shell", () => { |
| 21 | + revealThreadTerminal(threadRef, "setup-install"); |
| 22 | + expect( |
| 23 | + selectThreadTerminalUiState( |
| 24 | + useTerminalUiStateStore.getState().terminalUiStateByThreadKey, |
| 25 | + threadRef, |
| 26 | + ), |
| 27 | + ).toMatchObject({ |
| 28 | + terminalOpen: true, |
| 29 | + terminalIds: ["setup-install"], |
| 30 | + activeTerminalId: "setup-install", |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +it("reopens the existing panel and selects a running terminal in its split", () => { |
| 35 | + const panels = useRightPanelStore.getState(); |
| 36 | + panels.openTerminal(threadRef, "terminal-1"); |
| 37 | + const surfaceId = selectThreadRightPanelState( |
| 38 | + useRightPanelStore.getState().byThreadKey, |
| 39 | + threadRef, |
| 40 | + ).activeSurfaceId!; |
| 41 | + panels.splitTerminal(threadRef, surfaceId, "setup-install"); |
| 42 | + panels.activateTerminal(threadRef, surfaceId, "terminal-1"); |
| 43 | + panels.close(threadRef); |
| 44 | + |
| 45 | + revealThreadTerminal(threadRef, "setup-install"); |
| 46 | + expect( |
| 47 | + selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef), |
| 48 | + ).toMatchObject({ |
| 49 | + isOpen: true, |
| 50 | + activeSurfaceId: surfaceId, |
| 51 | + surfaces: [ |
| 52 | + { |
| 53 | + terminalIds: ["terminal-1", "setup-install"], |
| 54 | + activeTerminalId: "setup-install", |
| 55 | + }, |
| 56 | + ], |
| 57 | + }); |
| 58 | + expect( |
| 59 | + selectThreadTerminalUiState( |
| 60 | + useTerminalUiStateStore.getState().terminalUiStateByThreadKey, |
| 61 | + threadRef, |
| 62 | + ).terminalIds, |
| 63 | + ).toEqual([]); |
| 64 | +}); |
| 65 | + |
| 66 | +it("reveals terminals in their own environment without changing another environment's drawer", () => { |
| 67 | + revealThreadTerminal(threadRef, "default"); |
| 68 | + revealThreadTerminal(remoteRef, "setup-install"); |
| 69 | + const state = useTerminalUiStateStore.getState().terminalUiStateByThreadKey; |
| 70 | + expect(selectThreadTerminalUiState(state, threadRef).terminalIds).toEqual(["default"]); |
| 71 | + expect(selectThreadTerminalUiState(state, remoteRef).terminalIds).toEqual(["setup-install"]); |
| 72 | +}); |
0 commit comments