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

revealThreadTerminal.test.ts

72 lines2.6 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("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​
34it("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​
66it("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});