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

rightPanelStore.test.ts

794 lines26.9 KB

1import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2import { type EnvironmentId, ThreadId } from "@t3tools/contracts";
3import { beforeEach, describe, expect, it } from "vite-plus/test";
4​
5import {
6 migratePersistedRightPanelState,
7 pullRequestSurfaceId,
8 selectActiveRightPanel,
9 selectActiveRightPanelSurface,
10 selectSelectedRightPanelSurface,
11 selectThreadPanelOpen,
12 selectThreadPanelVisibility,
13 selectThreadRightPanelState,
14 useRightPanelStore,
15} from "./rightPanelStore";
16​
17const refA = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-A"));
18const refB = scopeThreadRef("env-1" as EnvironmentId, ThreadId.make("thread-B"));
19​
20beforeEach(() => {
21 useRightPanelStore.setState({ byThreadKey: {}, threadPanelVisibilityByThreadKey: {} });
22});
23​
24describe("rightPanelStore", () => {
25 it("drops the legacy singleton terminal surface during migration", () => {
26 expect(
27 migratePersistedRightPanelState({
28 byThreadKey: {
29 "env-1:thread-A": {
30 activeSurfaceId: "terminal",
31 surfaces: [
32 { id: "browser:tab-a", kind: "preview", resourceId: "tab-a" },
33 { id: "terminal", kind: "terminal" },
34 ],
35 },
36 },
37 }),
38 ).toEqual({
39 byThreadKey: {
40 "env-1:thread-A": {
41 isOpen: false,
42 activeSurfaceId: null,
43 surfaces: [{ id: "browser:tab-a", kind: "preview", resourceId: "tab-a" }],
44 },
45 },
46 threadPanelVisibilityByThreadKey: {},
47 });
48 });
49​
50 it("upgrades saved single-session terminal surfaces to split-capable surfaces", () => {
51 expect(
52 migratePersistedRightPanelState({
53 byThreadKey: {
54 "env-1:thread-A": {
55 isOpen: true,
56 activeSurfaceId: "terminal:term-1",
57 surfaces: [{ id: "terminal:term-1", kind: "terminal", resourceId: "term-1" }],
58 },
59 },
60 }),
61 ).toEqual({
62 byThreadKey: {
63 "env-1:thread-A": {
64 isOpen: true,
65 activeSurfaceId: "terminal:term-1",
66 surfaces: [
67 {
68 id: "terminal:term-1",
69 kind: "terminal",
70 resourceId: "term-1",
71 terminalIds: ["term-1"],
72 activeTerminalId: "term-1",
73 },
74 ],
75 },
76 },
77 threadPanelVisibilityByThreadKey: {},
78 });
79 });
80​
81 it("upgrades saved file surfaces with neutral reveal state", () => {
82 expect(
83 migratePersistedRightPanelState({
84 byThreadKey: {
85 "env-1:thread-A": {
86 isOpen: true,
87 activeSurfaceId: "file:src/index.ts",
88 surfaces: [{ id: "file:src/index.ts", kind: "file", relativePath: "src/index.ts" }],
89 },
90 },
91 }),
92 ).toEqual({
93 byThreadKey: {
94 "env-1:thread-A": {
95 isOpen: true,
96 activeSurfaceId: "file:src/index.ts",
97 surfaces: [
98 {
99 id: "file:src/index.ts",
100 kind: "file",
101 relativePath: "src/index.ts",
102 revealLine: null,
103 revealRequestId: 0,
104 },
105 ],
106 },
107 },
108 threadPanelVisibilityByThreadKey: {},
109 });
110 });
111​
112 it("upgrades the legacy singleton pull request surface to a reference-keyed tab", () => {
113 const id = pullRequestSurfaceId({
114 projectId: "project-a",
115 repository: "pingdotgg/t3code",
116 number: 4909,
117 });
118 expect(
119 migratePersistedRightPanelState({
120 byThreadKey: {
121 "env-1:thread-A": {
122 isOpen: true,
123 activeSurfaceId: "pull-request",
124 surfaces: [
125 {
126 id: "pull-request",
127 kind: "pull-request",
128 projectId: "project-a",
129 repository: "pingdotgg/t3code",
130 number: 4909,
131 },
132 ],
133 },
134 },
135 }),
136 ).toEqual({
137 byThreadKey: {
138 "env-1:thread-A": {
139 isOpen: true,
140 activeSurfaceId: id,
141 surfaces: [
142 {
143 id,
144 kind: "pull-request",
145 projectId: "project-a",
146 repository: "pingdotgg/t3code",
147 number: 4909,
148 },
149 ],
150 },
151 },
152 threadPanelVisibilityByThreadKey: {},
153 });
154 });
155​
156 it("drops the pull-request list's shared panel so a restart opens the page fresh", () => {
157 const id = pullRequestSurfaceId({
158 projectId: "project-a",
159 repository: "pingdotgg/t3code",
160 number: 4909,
161 });
162 const panelState = {
163 isOpen: true,
164 activeSurfaceId: id,
165 surfaces: [
166 {
167 id,
168 kind: "pull-request" as const,
169 projectId: "project-a",
170 repository: "pingdotgg/t3code",
171 number: 4909,
172 },
173 ],
174 };
175 expect(
176 migratePersistedRightPanelState({
177 byThreadKey: {
178 "env-1:pull-requests-panel": panelState,
179 "env-1:thread-A": panelState,
180 },
181 }),
182 ).toEqual({
183 byThreadKey: { "env-1:thread-A": panelState },
184 threadPanelVisibilityByThreadKey: {},
185 });
186 });
187​
188 it("drops persisted plan surfaces and does not reopen an empty panel", () => {
189 expect(
190 migratePersistedRightPanelState({
191 byThreadKey: {
192 "env-1:thread-A": {
193 isOpen: true,
194 activeSurfaceId: "plan",
195 surfaces: [{ id: "plan", kind: "plan" }],
196 },
197 "env-1:thread-B": {
198 isOpen: true,
199 activeSurfaceId: "plan",
200 surfaces: [
201 { id: "plan", kind: "plan" },
202 { id: "diff", kind: "diff" },
203 ],
204 },
205 },
206 }),
207 ).toEqual({
208 byThreadKey: {
209 "env-1:thread-A": {
210 isOpen: false,
211 activeSurfaceId: null,
212 surfaces: [],
213 },
214 "env-1:thread-B": {
215 isOpen: true,
216 activeSurfaceId: "diff",
217 surfaces: [{ id: "diff", kind: "diff" }],
218 },
219 },
220 threadPanelVisibilityByThreadKey: {},
221 });
222 });
223​
224 it("persists inline preference without restoring an open popover", () => {
225 expect(
226 migratePersistedRightPanelState({
227 threadPanelVisibilityByThreadKey: {
228 "env-1:thread-A": { inlineOpen: false, popoverOpen: true },
229 "env-1:thread-B": { inlineOpen: true, popoverOpen: true },
230 },
231 }),
232 ).toEqual({
233 byThreadKey: {},
234 threadPanelVisibilityByThreadKey: {
235 "env-1:thread-A": { inlineOpen: false, popoverOpen: false },
236 },
237 });
238 });
239​
240 it("tracks inline and popover visibility independently", () => {
241 const store = useRightPanelStore.getState();
242​
243 expect(selectThreadPanelOpen(store.threadPanelVisibilityByThreadKey, refA, "inline")).toBe(
244 true,
245 );
246 expect(selectThreadPanelOpen(store.threadPanelVisibilityByThreadKey, refA, "popover")).toBe(
247 false,
248 );
249​
250 store.setThreadPanelOpen(refA, "inline", false);
251 store.toggleThreadPanel(refA, "popover");
252​
253 expect(
254 selectThreadPanelVisibility(
255 useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
256 refA,
257 ),
258 ).toEqual({ inlineOpen: false, popoverOpen: true });
259 expect(
260 selectThreadPanelVisibility(
261 useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
262 refB,
263 ),
264 ).toEqual({ inlineOpen: true, popoverOpen: false });
265 });
266​
267 it("closes the popover atomically when the real right panel opens", () => {
268 useRightPanelStore.getState().setThreadPanelOpen(refA, "popover", true);
269 useRightPanelStore.getState().open(refA, "diff");
270​
271 expect(
272 selectThreadPanelVisibility(
273 useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
274 refA,
275 ),
276 ).toEqual({ inlineOpen: true, popoverOpen: false });
277 });
278​
279 it("keeps an open popover visible by promoting it to inline when the real panel closes", () => {
280 const store = useRightPanelStore.getState();
281 store.open(refA, "diff");
282 store.setThreadPanelOpen(refA, "inline", false);
283 store.setThreadPanelOpen(refA, "popover", true);
284 store.close(refA);
285​
286 expect(
287 selectThreadPanelVisibility(
288 useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
289 refA,
290 ),
291 ).toEqual({ inlineOpen: true, popoverOpen: true });
292 });
293​
294 it("open sets the active panel for a thread", () => {
295 useRightPanelStore.getState().open(refA, "preview");
296 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("preview");
297 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refB)).toBeNull();
298 });
299​
300 it("opening a different kind keeps both surfaces and activates the new one", () => {
301 useRightPanelStore.getState().open(refA, "agents");
302 useRightPanelStore.getState().open(refA, "preview");
303 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("preview");
304 expect(
305 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
306 ).toHaveLength(2);
307 });
308​
309 it("reopening an inactive singleton activates its existing surface", () => {
310 useRightPanelStore.getState().open(refA, "diff");
311 useRightPanelStore.getState().open(refA, "agents");
312 useRightPanelStore.getState().open(refA, "diff");
313​
314 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
315 isOpen: true,
316 activeSurfaceId: "diff",
317 surfaces: [
318 { id: "diff", kind: "diff" },
319 { id: "agents", kind: "agents" },
320 ],
321 });
322 });
323​
324 it("keeps files as a singleton surface", () => {
325 useRightPanelStore.getState().open(refA, "files");
326 useRightPanelStore.getState().open(refA, "files");
327 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
328 isOpen: true,
329 activeSurfaceId: "files",
330 surfaces: [{ id: "files", kind: "files" }],
331 });
332 });
333​
334 it("replaces the standalone explorer with peer file surfaces", () => {
335 useRightPanelStore.getState().open(refA, "files");
336 useRightPanelStore.getState().openFile(refA, "src/index.ts");
337 useRightPanelStore.getState().openFile(refA, "src/index.ts");
338 useRightPanelStore.getState().openFile(refA, "README.md");
339​
340 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
341 isOpen: true,
342 activeSurfaceId: "file:README.md",
343 surfaces: [
344 {
345 id: "file:src/index.ts",
346 kind: "file",
347 relativePath: "src/index.ts",
348 revealLine: null,
349 revealRequestId: 2,
350 },
351 {
352 id: "file:README.md",
353 kind: "file",
354 relativePath: "README.md",
355 revealLine: null,
356 revealRequestId: 1,
357 },
358 ],
359 });
360 });
361​
362 it("opens an attachment as a file surface without the standalone explorer", () => {
363 const attachment = {
364 type: "file" as const,
365 id: "thread-A-attachment-pdf",
366 name: "report.pdf",
367 mimeType: "application/pdf",
368 sizeBytes: 42,
369 };
370 useRightPanelStore.getState().open(refA, "files");
371 useRightPanelStore.getState().openAttachment(refA, attachment);
372​
373 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
374 isOpen: true,
375 activeSurfaceId: "attachment:thread-A-attachment-pdf",
376 surfaces: [
377 {
378 id: "attachment:thread-A-attachment-pdf",
379 kind: "file",
380 relativePath: "report.pdf",
381 revealLine: null,
382 revealRequestId: 0,
383 attachment,
384 },
385 ],
386 });
387 });
388​
389 it("keeps attachment and workspace file ids disjoint", () => {
390 useRightPanelStore.getState().openFile(refA, "attachment:shared-id");
391 useRightPanelStore.getState().openAttachment(refA, {
392 type: "file",
393 id: "shared-id",
394 name: "report.pdf",
395 mimeType: "application/pdf",
396 sizeBytes: 42,
397 });
398​
399 expect(
400 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.map(
401 (surface) => surface.id,
402 ),
403 ).toEqual(["file:attachment:shared-id", "attachment:shared-id"]);
404 });
405​
406 it("updates line reveal requests when reopening a file surface", () => {
407 useRightPanelStore.getState().openFile(refA, "src/index.ts", 42);
408 useRightPanelStore.getState().openFile(refA, "src/index.ts", 87);
409​
410 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
411 isOpen: true,
412 activeSurfaceId: "file:src/index.ts",
413 surfaces: [
414 {
415 id: "file:src/index.ts",
416 kind: "file",
417 relativePath: "src/index.ts",
418 revealLine: 87,
419 revealRequestId: 2,
420 },
421 ],
422 });
423​
424 useRightPanelStore.getState().openFile(refA, "src/index.ts");
425​
426 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
427 isOpen: true,
428 activeSurfaceId: "file:src/index.ts",
429 surfaces: [
430 {
431 id: "file:src/index.ts",
432 kind: "file",
433 relativePath: "src/index.ts",
434 revealLine: null,
435 revealRequestId: 3,
436 },
437 ],
438 });
439 });
440​
441 it("removes persisted file surfaces when their workspace no longer exists", () => {
442 useRightPanelStore.getState().openFile(refA, "src/index.ts");
443 useRightPanelStore.getState().open(refA, "agents");
444 useRightPanelStore.getState().openFile(refA, "README.md");
445​
446 useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
447​
448 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
449 isOpen: true,
450 activeSurfaceId: "agents",
451 surfaces: [{ id: "agents", kind: "agents" }],
452 });
453​
454 useRightPanelStore.getState().openFile(refB, "conductor.json");
455 useRightPanelStore.getState().reconcileFileSurfaces(refB, false);
456 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refB)).toEqual({
457 isOpen: false,
458 activeSurfaceId: null,
459 surfaces: [],
460 });
461 });
462​
463 it("keeps attachment previews when their workspace is unavailable", () => {
464 const attachment = {
465 type: "file" as const,
466 id: "thread-A-attachment-pdf",
467 name: "report.pdf",
468 mimeType: "application/pdf",
469 sizeBytes: 42,
470 };
471 useRightPanelStore.getState().openFile(refA, "README.md");
472 useRightPanelStore.getState().openAttachment(refA, attachment);
473​
474 useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
475​
476 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
477 isOpen: true,
478 activeSurfaceId: "attachment:thread-A-attachment-pdf",
479 surfaces: [
480 {
481 id: "attachment:thread-A-attachment-pdf",
482 kind: "file",
483 relativePath: "report.pdf",
484 revealLine: null,
485 revealRequestId: 0,
486 attachment,
487 },
488 ],
489 });
490 });
491​
492 it("close hides the panel without clearing its selected surface", () => {
493 useRightPanelStore.getState().open(refA, "agents");
494 useRightPanelStore.getState().close(refA);
495 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
496 expect(
497 selectSelectedRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA),
498 ).toEqual({ id: "agents", kind: "agents" });
499 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
500 isOpen: false,
501 activeSurfaceId: "agents",
502 surfaces: [{ id: "agents", kind: "agents" }],
503 });
504 });
505​
506 it("toggles empty panel visibility without creating a surface", () => {
507 useRightPanelStore.getState().toggleVisibility(refA);
508 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
509 isOpen: true,
510 activeSurfaceId: null,
511 surfaces: [],
512 });
513​
514 useRightPanelStore.getState().toggleVisibility(refA);
515 expect(useRightPanelStore.getState().byThreadKey).toEqual({});
516 });
517​
518 it("toggle hides the panel without discarding the active surface", () => {
519 useRightPanelStore.getState().toggle(refA, "diff");
520 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
521 useRightPanelStore.getState().toggle(refA, "diff");
522 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
523 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
524 isOpen: false,
525 activeSurfaceId: "diff",
526 surfaces: [{ id: "diff", kind: "diff" }],
527 });
528 });
529​
530 it("toggle to a different kind switches active", () => {
531 useRightPanelStore.getState().toggle(refA, "preview");
532 useRightPanelStore.getState().toggle(refA, "agents");
533 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("agents");
534 });
535​
536 it("removeThread clears persisted state", () => {
537 useRightPanelStore.getState().open(refA, "agents");
538 useRightPanelStore.getState().removeThread(refA);
539 expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
540 });
541​
542 it("close on never-opened thread is a no-op", () => {
543 useRightPanelStore.getState().close(refA);
544 expect(useRightPanelStore.getState().byThreadKey).toEqual({});
545 });
546​
547 it("tracks one surface per browser session", () => {
548 useRightPanelStore.getState().openBrowser(refA, "tab-a");
549 useRightPanelStore.getState().openBrowser(refA, "tab-b");
550​
551 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
552 expect(state.surfaces.map((surface) => surface.id)).toEqual(["browser:tab-a", "browser:tab-b"]);
553 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
554 id: "browser:tab-b",
555 kind: "preview",
556 resourceId: "tab-b",
557 });
558 });
559​
560 it("tracks one surface per pull request", () => {
561 const first = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
562 const second = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4910 };
563 useRightPanelStore.getState().openPullRequest(refA, first);
564 useRightPanelStore.getState().openPullRequest(refA, second);
565 useRightPanelStore.getState().openPullRequest(refA, first);
566​
567 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
568 expect(state.surfaces.map((surface) => surface.id)).toEqual([
569 pullRequestSurfaceId(first),
570 pullRequestSurfaceId(second),
571 ]);
572 expect(state.activeSurfaceId).toBe(pullRequestSurfaceId(first));
573 });
574​
575 it("keeps one pull request read from two servers as two tabs", () => {
576 const local = {
577 environmentId: "local",
578 projectId: "project-a",
579 repository: "pingdotgg/t3code",
580 number: 4909,
581 };
582 const remote = { ...local, environmentId: "remote" };
583​
584 useRightPanelStore.getState().openPullRequest(refA, local);
585 useRightPanelStore.getState().openPullRequest(refA, remote);
586​
587 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
588 expect(state.surfaces.map((surface) => surface.id)).toEqual([
589 pullRequestSurfaceId(local),
590 pullRequestSurfaceId(remote),
591 ]);
592 });
593​
594 it("keeps the page's panel tabs reachable when the set of connected servers changes", () => {
595 // The pull-requests page keys its one shared panel by a fixed sentinel environment, not by
596 // whichever capable server happens to sort first (see PULL_REQUESTS_PANEL_ENVIRONMENT_ID in
597 // _chat.pull-requests.tsx) — a server disconnecting must not move every open tab to a store
598 // key nobody wrote them under.
599 const panelId = ThreadId.make("pull-requests-panel");
600 const stableRef = scopeThreadRef("pull-requests-panel" as EnvironmentId, panelId);
601 const fromServerA = {
602 environmentId: "server-a",
603 projectId: "project-a",
604 repository: "pingdotgg/t3code",
605 number: 1,
606 };
607 const fromServerB = {
608 environmentId: "server-b",
609 projectId: "project-b",
610 repository: "pingdotgg/t3code",
611 number: 2,
612 };
613​
614 // Both servers connected: tabs from each open under the one stable ref.
615 useRightPanelStore.getState().openPullRequest(stableRef, fromServerA);
616 useRightPanelStore.getState().openPullRequest(stableRef, fromServerB);
617​
618 // Server A disconnects. The stable ref does not depend on which servers remain connected, so
619 // the same lookup still finds both tabs.
620 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, stableRef);
621 expect(state.surfaces.map((surface) => surface.id)).toEqual([
622 pullRequestSurfaceId(fromServerA),
623 pullRequestSurfaceId(fromServerB),
624 ]);
625​
626 // The bug this guards against: a ref keyed by the first capable environment instead of a
627 // fixed sentinel changes identity when that environment drops out, and a lookup under the new
628 // key finds nothing even though the tabs are still sitting under the old one.
629 const refWhileBothConnected = scopeThreadRef("server-a" as EnvironmentId, panelId);
630 const refAfterServerADisconnects = scopeThreadRef("server-b" as EnvironmentId, panelId);
631 expect(refWhileBothConnected).not.toEqual(refAfterServerADisconnects);
632 expect(
633 selectThreadRightPanelState(
634 useRightPanelStore.getState().byThreadKey,
635 refAfterServerADisconnects,
636 ).surfaces,
637 ).toEqual([]);
638 });
639​
640 it("tracks one surface per terminal session", () => {
641 useRightPanelStore.getState().openTerminal(refA, "term-1");
642 useRightPanelStore.getState().openTerminal(refA, "term-2");
643​
644 const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
645 expect(state.surfaces).toEqual([
646 {
647 id: "terminal:term-1",
648 kind: "terminal",
649 resourceId: "term-1",
650 terminalIds: ["term-1"],
651 activeTerminalId: "term-1",
652 },
653 {
654 id: "terminal:term-2",
655 kind: "terminal",
656 resourceId: "term-2",
657 terminalIds: ["term-2"],
658 activeTerminalId: "term-2",
659 },
660 ]);
661 expect(state.activeSurfaceId).toBe("terminal:term-2");
662 });
663​
664 it("tracks split panes and the active pane within a terminal surface", () => {
665 useRightPanelStore.getState().openTerminal(refA, "term-1");
666 useRightPanelStore.getState().splitTerminal(refA, "terminal:term-1", "term-2");
667​
668 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
669 id: "terminal:term-1",
670 kind: "terminal",
671 resourceId: "term-1",
672 terminalIds: ["term-1", "term-2"],
673 activeTerminalId: "term-2",
674 });
675​
676 useRightPanelStore.getState().activateTerminal(refA, "terminal:term-1", "term-1");
677 useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1");
678 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
679 id: "terminal:term-1",
680 kind: "terminal",
681 resourceId: "term-1",
682 terminalIds: ["term-2"],
683 activeTerminalId: "term-2",
684 });
685 });
686​
687 it("tracks vertical layout for a terminal surface", () => {
688 useRightPanelStore.getState().openTerminal(refA, "term-1");
689 useRightPanelStore.getState().splitTerminal(refA, "terminal:term-1", "term-2", "vertical");
690​
691 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
692 id: "terminal:term-1",
693 kind: "terminal",
694 resourceId: "term-1",
695 terminalIds: ["term-1", "term-2"],
696 activeTerminalId: "term-2",
697 splitDirection: "vertical",
698 });
699 });
700​
701 it("closing the final terminal pane removes its surface and closes the panel", () => {
702 useRightPanelStore.getState().openTerminal(refA, "term-1");
703 useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1");
704​
705 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
706 isOpen: false,
707 activeSurfaceId: null,
708 surfaces: [],
709 });
710 });
711​
712 it("closing the active surface activates a neighboring surface", () => {
713 useRightPanelStore.getState().openBrowser(refA, "tab-a");
714 useRightPanelStore.getState().openTerminal(refA, "term-1");
715 useRightPanelStore.getState().closeSurface(refA, "terminal:term-1");
716​
717 expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)?.id).toBe(
718 "browser:tab-a",
719 );
720 });
721​
722 it("closing the final surface closes the panel", () => {
723 useRightPanelStore.getState().openTerminal(refA, "term-1");
724 useRightPanelStore.getState().closeSurface(refA, "terminal:term-1");
725​
726 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
727 isOpen: false,
728 activeSurfaceId: null,
729 surfaces: [],
730 });
731 });
732​
733 it("closing other surfaces keeps the selected surface active", () => {
734 useRightPanelStore.getState().openBrowser(refA, "tab-a");
735 useRightPanelStore.getState().openFile(refA, "src/index.ts");
736 useRightPanelStore.getState().openTerminal(refA, "term-1");
737​
738 useRightPanelStore.getState().closeOtherSurfaces(refA, "file:src/index.ts");
739​
740 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
741 isOpen: true,
742 activeSurfaceId: "file:src/index.ts",
743 surfaces: [
744 {
745 id: "file:src/index.ts",
746 kind: "file",
747 relativePath: "src/index.ts",
748 revealLine: null,
749 revealRequestId: 1,
750 },
751 ],
752 });
753 });
754​
755 it("closing surfaces to the right activates the selected surface when active was removed", () => {
756 useRightPanelStore.getState().openBrowser(refA, "tab-a");
757 useRightPanelStore.getState().openFile(refA, "src/index.ts");
758 useRightPanelStore.getState().openTerminal(refA, "term-1");
759​
760 useRightPanelStore.getState().closeSurfacesToRight(refA, "browser:tab-a");
761​
762 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
763 isOpen: true,
764 activeSurfaceId: "browser:tab-a",
765 surfaces: [{ id: "browser:tab-a", kind: "preview", resourceId: "tab-a" }],
766 });
767 });
768​
769 it("closing all surfaces closes the panel", () => {
770 useRightPanelStore.getState().openBrowser(refA, "tab-a");
771 useRightPanelStore.getState().openFile(refA, "src/index.ts");
772​
773 useRightPanelStore.getState().closeAllSurfaces(refA);
774​
775 expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
776 isOpen: false,
777 activeSurfaceId: null,
778 surfaces: [],
779 });
780 });
781​
782 it("reconciles browser surfaces without deleting other surface kinds", () => {
783 useRightPanelStore.getState().openTerminal(refA, "term-1");
784 useRightPanelStore.getState().openBrowser(refA, "tab-a");
785 useRightPanelStore.getState().openBrowser(refA, "tab-b");
786 useRightPanelStore.getState().reconcileBrowserSurfaces(refA, ["tab-b", "tab-c"]);
787​
788 expect(
789 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces.map(
790 (surface) => surface.id,
791 ),
792 ).toEqual(["terminal:term-1", "browser:tab-b", "browser:tab-c"]);
793 });
794});