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