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

rightPanelStore.test.ts

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