Open History to see the last commit
1import {
2 CodeView,
3 FileDiff,
4 FileRenderer,
5 getSharedHighlighter,
6 type CodeViewItem,
7 type CodeViewScrollTarget,
8 type FileContents,
9} from "@pierre/diffs";
10import { useWorkerPool, type CodeViewProps } from "@pierre/diffs/react";
11import { WorkerPoolManager, type WorkerRequest, type WorkerResponse } from "@pierre/diffs/worker";
12import DiffsWorker from "@pierre/diffs/worker/worker.js?worker";
13import { getDiffLineStat, getRenderablePatch } from "../../lib/diffRendering";
14import {
15 act,
16 StrictMode,
17 useEffect,
18 useImperativeHandle,
19 useLayoutEffect,
20 useRef,
21 useState,
22 type ReactElement,
23 type Ref,
24} from "react";
25import { createRoot, type Root } from "react-dom/client";
26import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
27
28const testState = vi.hoisted(() => ({
29 workers: [] as Worker[],
30 terminations: 0,
31 requests: [] as WorkerRequest[],
32 pools: new Map<WorkerPoolManager, Promise<void>>(),
33 renderPools: [] as (WorkerPoolManager | undefined)[],
34 failWorkers: false,
35 holdInitialization: false,
36 heldResponses: [] as (() => void)[],
37 onInitializationHeld: undefined as (() => void) | undefined,
38}));
39
40vi.mock(import("../../hooks/useTheme"), async (original) => ({
41 ...(await original()),
42 useRenderedAppearance: (() => "dark") as never,
43}));
44
45// Wraps Pierre's real worker so the suite can count workers, read requests and hold startup.
46// Vite's `?worker` export is a factory that returns a plain Worker, so this patches the instance.
47vi.mock("@pierre/diffs/worker/worker.js?worker", async (original) => {
48 const actual = await original<{ default: new () => Worker }>();
49 return {
50 ...actual,
51 default: function TestDiffsWorker() {
52 if (testState.failWorkers) throw new Error("Worker creation failed");
53 const worker = new actual.default();
54 testState.workers.push(worker);
55 const addEventListener = worker.addEventListener.bind(worker);
56 const postMessage = worker.postMessage.bind(worker);
57 const terminate = worker.terminate.bind(worker);
58 worker.addEventListener = (type: string, listener: EventListenerOrEventListenerObject) => {
59 if (type !== "message" || typeof listener !== "function") {
60 addEventListener(type, listener);
61 return;
62 }
63 addEventListener("message", (event) => {
64 const data = (event as MessageEvent<WorkerResponse>).data;
65 const deliver = () => listener(event);
66 if (
67 testState.holdInitialization &&
68 data.type === "success" &&
69 data.requestType === "initialize"
70 ) {
71 testState.heldResponses.push(deliver);
72 if (testState.heldResponses.length === 2) testState.onInitializationHeld?.();
73 } else {
74 deliver();
75 }
76 });
77 };
78 worker.postMessage = (message: WorkerRequest) => {
79 testState.requests.push(message);
80 postMessage(message);
81 };
82 worker.terminate = () => {
83 testState.terminations += 1;
84 terminate();
85 };
86 return worker;
87 },
88 };
89});
90
91// Pierre's real viewer virtualizes into a shadow root; this stand-in renders each file through
92// the same worker pool and keeps the highlighted HTML readable.
93vi.mock(import("@pierre/diffs/react"), async (original) => ({
94 ...(await original()),
95 CodeView: ((props: CodeViewProps<undefined, undefined>) =>
96 props.items?.map((item) =>
97 item.type === "file" ? <FileOutput key={item.id} file={item.file} /> : null,
98 )) as never,
99}));
100
101import { StyledDiffCodeView } from "./StyledDiffCodeView";
102import { useCodeViewFileReveal } from "./useCodeViewFileReveal";
103
104function FileOutput({ file }: { file: FileContents }) {
105 const pool = useWorkerPool();
106 const [html, setHtml] = useState("");
107 useEffect(() => {
108 testState.renderPools.push(pool);
109 const renderer = new FileRenderer(
110 { theme: "pierre-dark", preferredHighlighter: "shiki-wasm" },
111 undefined,
112 render,
113 pool,
114 );
115 function render() {
116 const result = renderer.renderFile(file);
117 if (result) setHtml(renderer.renderFullHTML(result));
118 }
119 render();
120 return () => renderer.cleanUp();
121 }, [file, pool]);
122 return <pre data-code-file={file.name}>{html}</pre>;
123}
124
125const files = [
126 { name: "notes.txt", contents: "Plain text is ready.\n", cacheKey: "plain-text" },
127 { name: "answer.ts", contents: "const answer = 42;\n", cacheKey: "typescript" },
128] satisfies FileContents[];
129
130function Views({ count }: { count: number }) {
131 const [draft, setDraft] = useState("Draft");
132 return (
133 <>
134 <button onClick={() => setDraft("Edited draft")}>{draft}</button>
135 {files.slice(0, count).map((file) => (
136 <StyledDiffCodeView key={file.name} items={[{ type: "file", id: file.name, file }]} />
137 ))}
138 </>
139 );
140}
141
142function renderViews(count: number) {
143 return (
144 <StrictMode>
145 <Views count={count} />
146 </StrictMode>
147 );
148}
149
150const roots: Root[] = [];
151
152function mount(element: ReactElement) {
153 const container = document.createElement("div");
154 document.body.append(container);
155 const root = createRoot(container);
156 roots.push(root);
157 return {
158 root,
159 render: (next: ReactElement) => act(async () => root.render(next)),
160 initial: act(async () => root.render(element)),
161 };
162}
163
164async function unmountAll() {
165 for (const root of roots.splice(0)) await act(async () => root.unmount());
166 document.body.replaceChildren();
167}
168
169const codeFile = (name: string) =>
170 document.querySelector(`[data-code-file="${name}"]`)?.textContent ?? "";
171const loadingViews = () => document.querySelectorAll('[role="status"]').length;
172
173describe("code-view worker lifecycle", () => {
174 beforeEach(() => {
175 testState.workers = [];
176 testState.terminations = 0;
177 testState.requests = [];
178 testState.pools.clear();
179 testState.renderPools = [];
180 testState.failWorkers = false;
181 testState.holdInitialization = false;
182 testState.heldResponses = [];
183 testState.onInitializationHeld = undefined;
184 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
185 // Pins the pool at two workers whatever machine runs the suite.
186 Object.defineProperty(navigator, "hardwareConcurrency", { configurable: true, value: 2 });
187 const initialize = WorkerPoolManager.prototype.initialize;
188 vi.spyOn(WorkerPoolManager.prototype, "initialize").mockImplementation(function (
189 this: WorkerPoolManager,
190 ...args
191 ) {
192 const pending = initialize.apply(this, args);
193 testState.pools.set(this, pending);
194 return pending;
195 });
196 });
197
198 afterEach(async () => {
199 if (!vi.isFakeTimers()) vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
200 await unmountAll();
201 await vi.runOnlyPendingTimersAsync();
202 vi.useRealTimers();
203 vi.restoreAllMocks();
204 vi.unstubAllGlobals();
205 delete (navigator as { hardwareConcurrency?: number }).hardwareConcurrency;
206 });
207
208 it("starts on demand, keeps quick reopens warm, and expires the last closed pool", async () => {
209 const view = mount(renderViews(0));
210 await view.initial;
211 const button = document.querySelector("button")!;
212 expect(testState.workers).toHaveLength(0);
213 expect(testState.pools.size).toBe(0);
214 await act(async () => button.click());
215 await view.render(renderViews(1));
216 const pool = [...testState.pools.keys()][0]!;
217 await act(async () => testState.pools.get(pool));
218 expect(pool.isInitialized()).toBe(true);
219 expect(testState.workers).toHaveLength(2);
220 await vi.waitFor(() => expect(codeFile("notes.txt")).toContain("Plain text is ready."));
221 expect(testState.requests.filter((request) => request.type === "file")).toHaveLength(0);
222
223 await view.render(renderViews(2));
224 await act(async () => pool.primeFileHighlightCache(files[1]!));
225 expect(testState.pools.size).toBe(1);
226 expect(testState.workers).toHaveLength(2);
227 expect(new Set(testState.renderPools)).toEqual(new Set([pool]));
228 expect(pool.getFileResultCache(files[1]!)).toBeDefined();
229 await vi.waitFor(() => expect(codeFile("answer.ts")).toContain("answer"));
230
231 // Worker startup uses real time. Only advance the clock once highlighting
232 // has finished, so idle expiry cannot also expire a worker startup timer.
233 vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
234 await view.render(renderViews(1));
235 expect(pool.getStats().totalWorkers).toBe(2);
236 expect(testState.terminations).toBe(0);
237 await view.render(renderViews(0));
238 await vi.advanceTimersByTimeAsync(29_999);
239 expect(pool.getStats().totalWorkers).toBe(2);
240 expect(testState.terminations).toBe(0);
241
242 await view.render(renderViews(1));
243 expect(testState.pools.size).toBe(1);
244 expect(testState.workers).toHaveLength(2);
245 expect(loadingViews()).toBe(0);
246 expect(pool.getFileResultCache(files[1]!)).toBeDefined();
247 await vi.advanceTimersByTimeAsync(30_000);
248 expect(pool.getStats().totalWorkers).toBe(2);
249
250 await view.render(renderViews(0));
251 await vi.advanceTimersByTimeAsync(30_000);
252 expect(pool.getStats().totalWorkers).toBe(0);
253 expect(testState.terminations).toBe(2);
254
255 vi.useRealTimers();
256 await view.render(renderViews(1));
257 const reopenedPool = [...testState.pools.keys()][1]!;
258 await act(async () => testState.pools.get(reopenedPool));
259 expect(reopenedPool.isInitialized()).toBe(true);
260 expect(testState.workers).toHaveLength(4);
261 expect(document.querySelector("button")).toBe(button);
262 expect(button.textContent).toBe("Edited draft");
263 await vi.waitFor(() => expect(codeFile("notes.txt")).toContain("Plain text is ready."));
264 });
265
266 it("renders through Pierre's main-thread fallback when worker creation fails", async () => {
267 testState.failWorkers = true;
268 await mount(renderViews(1)).initial;
269 const pool = [...testState.pools.keys()][0]!;
270 await act(async () => {
271 await expect(testState.pools.get(pool)).rejects.toMatchObject({ _tag: "DiffWorkerError" });
272 await getSharedHighlighter({
273 themes: ["pierre-dark"],
274 langs: ["text"],
275 preferredHighlighter: "shiki-wasm",
276 });
277 });
278 expect(pool.isWorkingPool()).toBe(false);
279 expect(testState.workers).toHaveLength(0);
280 await vi.waitFor(() => expect(codeFile("notes.txt")).toContain("Plain text is ready."));
281 });
282
283 it("keeps an initializing pool until its last view closes and ignores late responses", async () => {
284 vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
285 testState.holdInitialization = true;
286 const held = new Promise<void>((resolve) => {
287 testState.onInitializationHeld = resolve;
288 });
289 const view = mount(renderViews(2));
290 await view.initial;
291 const pool = [...testState.pools.keys()][0]!;
292 const pending = testState.pools.get(pool)!;
293 await held;
294 expect(pool.isInitialized()).toBe(false);
295 expect(testState.pools.size).toBe(1);
296 expect(loadingViews()).toBe(2);
297 expect(testState.renderPools).toHaveLength(0);
298
299 await view.render(renderViews(1));
300 expect(pool.getStats().totalWorkers).toBe(2);
301 expect(testState.terminations).toBe(0);
302 await view.render(renderViews(0));
303 // Pierre gives up on a held startup after 10 seconds; the idle timer then tears the pool down.
304 const timedOut = expect(pending).rejects.toThrow("worker initialization timed out");
305 await vi.advanceTimersByTimeAsync(30_000);
306 await timedOut;
307 await act(async () => {
308 for (const deliver of testState.heldResponses) deliver();
309 });
310 expect(pool.getStats().totalWorkers).toBe(0);
311 expect(testState.workers).toHaveLength(2);
312 expect(testState.terminations).toBe(2);
313 expect(testState.renderPools).toHaveLength(0);
314 expect(document.querySelectorAll("pre")).toHaveLength(0);
315 });
316});
317
318describe("collapsed diff content", () => {
319 let pool: WorkerPoolManager;
320 let container: HTMLDivElement;
321 let viewer: FileDiff<string> | CodeView<string> | undefined;
322
323 const loadedDiff = () => {
324 const parsed = getRenderablePatch(
325 [
326 "diff --git a/before.ts b/after.ts",
327 "similarity index 50%",
328 "rename from before.ts",
329 "rename to after.ts",
330 "--- a/before.ts",
331 "+++ b/after.ts",
332 "@@ -1,2 +1,2 @@",
333 " const shared = 1;",
334 "-const before = 2;",
335 "+const after = 3;",
336 ].join("\n"),
337 "collapsed-content",
338 );
339 if (parsed?.kind !== "files" || !parsed.files[0]) throw new Error("Expected diff");
340 return parsed.files[0];
341 };
342 const code = () =>
343 [...container.querySelectorAll("diffs-container")]
344 .flatMap((element) => [...(element.shadowRoot?.querySelectorAll("[data-line]") ?? [])])
345 .map((line) => line.textContent)
346 .join("\n");
347
348 beforeEach(async () => {
349 testState.requests = [];
350 testState.failWorkers = false;
351 testState.holdInitialization = false;
352 pool = new WorkerPoolManager(
353 { workerFactory: () => new DiffsWorker(), poolSize: 1 },
354 { theme: "pierre-dark", langs: ["typescript"], preferredHighlighter: "shiki-wasm" },
355 );
356 await pool.initialize();
357 container = document.createElement("div");
358 container.style.cssText = "height: 400px; width: 800px; overflow: auto";
359 document.body.append(container);
360 });
361
362 afterEach(() => {
363 viewer?.cleanUp();
364 viewer = undefined;
365 pool.terminate();
366 container.remove();
367 vi.restoreAllMocks();
368 });
369
370 it("defers plain AST and highlight work across collapsed renders until expansion", async () => {
371 const fileDiff = loadedDiff();
372 const highlight = vi.spyOn(pool, "highlightDiffAST");
373 const plainAST = vi.spyOn(pool, "getPlainDiffAST");
374 const options = { theme: "pierre-dark", collapsed: true, disableErrorHandling: true } as const;
375 const file = new FileDiff<string>(options, pool);
376 viewer = file;
377 file.render({ fileDiff, containerWrapper: container });
378 file.render({ fileDiff, forceRender: true });
379 expect.soft(highlight.mock.calls.length).toBe(0);
380 expect.soft(plainAST.mock.calls.length).toBe(0);
381 expect(code()).toBe("");
382 expect(container.querySelector("diffs-container")?.shadowRoot?.textContent).toContain(
383 "after.ts",
384 );
385
386 file.setOptions({ ...options, collapsed: false });
387 file.render({ fileDiff, forceRender: true });
388 expect(highlight).toHaveBeenCalled();
389 await pool.primeDiffHighlightCache(fileDiff);
390 await vi.waitFor(() => expect(code()).toContain("const after = 3;"));
391 expect(code()).toContain("const before = 2;");
392 expect(testState.requests.filter((request) => request.type === "diff")).toHaveLength(1);
393 });
394
395 it("finds newly loaded collapsed lines and unfolds the match with its annotation and header", async () => {
396 const fileDiff = loadedDiff();
397 const item: CodeViewItem<string> = {
398 type: "diff",
399 id: "renamed",
400 fileDiff,
401 collapsed: true,
402 annotations: [{ side: "additions", lineNumber: 2, metadata: "Review this change" }],
403 };
404 const view = new CodeView<string>(
405 {
406 theme: "pierre-dark",
407 disableErrorHandling: true,
408 onRevealSearchMatch: (match) =>
409 view.setItems([{ ...match, collapsed: false, version: (match.version ?? 0) + 1 }]),
410 renderHeaderMetadata: (file) => {
411 if (!("hunks" in file)) return;
412 const metadata = document.createElement("span");
413 const { additions, deletions } = getDiffLineStat([file]);
414 metadata.textContent = "+" + additions + " / -" + deletions;
415 return metadata;
416 },
417 renderAnnotation: (annotation) => {
418 const note = document.createElement("span");
419 note.textContent = annotation.metadata ?? "";
420 return note;
421 },
422 },
423 pool,
424 );
425 viewer = view;
426 view.setup(container);
427 view.openSearch();
428 const search = container.querySelector("[data-diffs-search]")!.shadowRoot!;
429 const input = search.querySelector<HTMLInputElement>("input[data-search]")!;
430 input.value = "const after";
431 input.dispatchEvent(new Event("input", { bubbles: true }));
432 view.setItems([item]);
433 view.render(true);
434 expect(code()).toBe("");
435 expect(search.textContent).toContain("1 results");
436 expect(container.textContent).toContain("+1 / -1");
437
438 input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
439 view.render(true);
440 await vi.waitFor(() => expect(code()).toContain("const after = 3;"));
441 expect(search.textContent).toContain("1 of 1");
442 expect(container.textContent).toContain("Review this change");
443 expect(container.textContent).toContain("+1 / -1");
444 expect(container.querySelector("diffs-container")?.shadowRoot?.textContent).toContain(
445 "after.ts",
446 );
447
448 await pool.primeDiffHighlightCache(fileDiff);
449 view.render(true);
450 const highlight = vi.spyOn(pool, "highlightDiffAST");
451 const plainAST = vi.spyOn(pool, "getPlainDiffAST");
452 const updatedDiff = { ...fileDiff, name: "updated.ts", cacheKey: "collapsed-update" };
453 view.setItems([{ ...item, fileDiff: updatedDiff, version: 2 }]);
454 view.render(true);
455 expect(highlight).not.toHaveBeenCalled();
456 expect(plainAST).not.toHaveBeenCalled();
457 expect(code()).toBe("");
458 expect(search.textContent).toContain("1 of 1");
459 expect(container.querySelector("diffs-container")?.shadowRoot?.textContent).toContain(
460 "updated.ts",
461 );
462 input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
463 view.render(true);
464 await vi.waitFor(() => expect(code()).toContain("const after = 3;"));
465 expect(container.textContent).toContain("Review this change");
466 });
467});
468
469type RevealHandle = NonNullable<Parameters<typeof useCodeViewFileReveal>[0]>;
470const revealCalls: {
471 scope: string;
472 fileKey: string;
473 mounted: boolean;
474 collapsed: boolean | undefined;
475}[] = [];
476
477function RevealViewer({
478 viewerRef,
479 scope,
480 collapsed,
481}: {
482 viewerRef: Ref<RevealHandle>;
483 scope: string;
484 collapsed: boolean;
485}) {
486 const instance = useRef<{ collapsed: boolean } | undefined>(undefined);
487 useLayoutEffect(() => {
488 instance.current = { collapsed };
489 return () => {
490 instance.current = undefined;
491 };
492 }, [collapsed]);
493 useImperativeHandle(
494 viewerRef,
495 () => ({
496 getInstance: () => instance.current,
497 scrollTo: (target: CodeViewScrollTarget) => {
498 if (target.type !== "item") return;
499 revealCalls.push({
500 scope,
501 fileKey: target.id,
502 mounted: instance.current !== undefined,
503 collapsed: instance.current?.collapsed,
504 });
505 },
506 }),
507 [scope],
508 );
509 return null;
510}
511
512function RevealViews({
513 scope,
514 visible,
515 selectedFile = null,
516 requestId = 0,
517}: {
518 scope: string;
519 visible: boolean;
520 selectedFile?: string | null;
521 requestId?: number;
522}) {
523 const [viewer, setViewer] = useState<RevealHandle | null>(null);
524 const [collapsed, setCollapsed] = useState(true);
525 // The reveal hook cancels pending clicks by scope identity, so a scope object
526 // must only be replaced when one of its inputs changes.
527 const [storedRevealScope, setRevealScope] = useState(() => ({
528 scope,
529 selectedRequest: { selectedFile, requestId },
530 }));
531 let revealScope = storedRevealScope;
532 if (
533 revealScope.scope !== scope ||
534 revealScope.selectedRequest.selectedFile !== selectedFile ||
535 revealScope.selectedRequest.requestId !== requestId
536 ) {
537 revealScope = {
538 scope,
539 selectedRequest:
540 revealScope.selectedRequest.selectedFile === selectedFile &&
541 revealScope.selectedRequest.requestId === requestId
542 ? revealScope.selectedRequest
543 : { selectedFile, requestId },
544 };
545 setRevealScope(revealScope);
546 }
547 const { selectedRequest } = revealScope;
548 useEffect(() => {
549 if (!selectedRequest.selectedFile || !viewer?.getInstance()) return;
550 viewer.scrollTo({ type: "item", id: selectedRequest.selectedFile, align: "start" });
551 }, [selectedRequest, viewer]);
552 const requestReveal = useCodeViewFileReveal(viewer, revealScope);
553 return (
554 <>
555 {visible && (
556 <RevealViewer key={scope} viewerRef={setViewer} scope={scope} collapsed={collapsed} />
557 )}
558 <button
559 onClick={() => {
560 setCollapsed(false);
561 requestReveal("tree-file");
562 }}
563 >
564 Reveal file
565 </button>
566 </>
567 );
568}
569
570describe("code-view file reveals", () => {
571 let view: ReturnType<typeof mount>;
572 const reveal = () => act(async () => document.querySelector("button")!.click());
573
574 beforeEach(() => {
575 revealCalls.length = 0;
576 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
577 });
578
579 afterEach(async () => {
580 await unmountAll();
581 vi.unstubAllGlobals();
582 });
583
584 it("does not replay a handled tree click or scroll an old handle when a selected file remounts the view", async () => {
585 view = mount(<RevealViews scope="first" visible selectedFile="external-a" />);
586 await view.initial;
587 await reveal();
588 expect(revealCalls.at(-1)?.fileKey).toBe("tree-file");
589 revealCalls.length = 0;
590
591 await view.render(
592 <RevealViews scope="second" visible selectedFile="external-b" requestId={1} />,
593 );
594 expect(revealCalls).toEqual([
595 { scope: "second", fileKey: "external-b", mounted: true, collapsed: false },
596 ]);
597 });
598
599 it("waits for a live viewer and applies each pending tree click only once", async () => {
600 view = mount(<RevealViews scope="diff" visible={false} selectedFile="external" />);
601 await view.initial;
602 await reveal();
603 expect(revealCalls).toEqual([]);
604
605 await view.render(<RevealViews scope="diff" visible selectedFile="external" />);
606 expect(revealCalls.map((call) => call.fileKey)).toEqual(["external", "tree-file"]);
607 revealCalls.length = 0;
608 await view.render(<RevealViews scope="diff" visible={false} selectedFile="external" />);
609 await view.render(<RevealViews scope="diff" visible selectedFile="external" />);
610 expect(revealCalls).toEqual([
611 { scope: "diff", fileKey: "external", mounted: true, collapsed: false },
612 ]);
613
614 revealCalls.length = 0;
615 // A click that lands in the same update that hides the viewer waits for it to return.
616 await act(async () => {
617 document.querySelector("button")!.click();
618 view.root.render(<RevealViews scope="diff" visible={false} selectedFile="external" />);
619 });
620 expect(revealCalls).toEqual([]);
621 await view.render(<RevealViews scope="diff" visible selectedFile="external" />);
622 expect(revealCalls).toEqual([
623 { scope: "diff", fileKey: "external", mounted: true, collapsed: false },
624 { scope: "diff", fileKey: "tree-file", mounted: true, collapsed: false },
625 ]);
626 });
627
628 it("cancels pending tree clicks when an external selection or diff scope changes", async () => {
629 view = mount(<RevealViews scope="first" visible={false} selectedFile="external-a" />);
630 await view.initial;
631 await reveal();
632 await view.render(
633 <RevealViews scope="first" visible selectedFile="external-b" requestId={1} />,
634 );
635 expect(revealCalls.map((call) => call.fileKey)).toEqual(["external-b"]);
636 revealCalls.length = 0;
637
638 await view.render(<RevealViews scope="first" visible={false} />);
639 await reveal();
640 await view.render(<RevealViews scope="second" visible={false} />);
641 await view.render(<RevealViews scope="first" visible />);
642 expect(revealCalls).toEqual([]);
643 });
644
645 it("reveals after a collapsed file expands and honors another click on the same file", async () => {
646 view = mount(<RevealViews scope="diff" visible />);
647 await view.initial;
648 await reveal();
649 await reveal();
650 expect(revealCalls).toEqual([
651 { scope: "diff", fileKey: "tree-file", mounted: true, collapsed: false },
652 { scope: "diff", fileKey: "tree-file", mounted: true, collapsed: false },
653 ]);
654 });
655});