Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

revealThreadTerminal.test.ts

58 lines2.2 KB

1import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3import { beforeEach, expect, it } from "vite-plus/test";
4​
5import { selectThreadRightPanelState, useRightPanelStore } from "../rightPanelStore";
6import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
7import { revealThreadTerminal } from "./revealThreadTerminal";
8​
9const threadRef = scopeThreadRef(EnvironmentId.make("local"), ThreadId.make("settled-thread"));
10const remoteRef = scopeThreadRef(EnvironmentId.make("remote"), threadRef.threadId);
11​
12beforeEach(() => {
13 useTerminalUiStateStore.setState({
14 terminalUiStateByThreadKey: {},
15 suppressedTerminalIdsByThreadKey: {},
16 });
17 useRightPanelStore.setState({ byThreadKey: {} });
18});
19​
20it("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​
52it("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});