@devries-cameron20 / t3code Mirror · read-only / commits / 0ad399c6c5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 17:00 UTC

test(web): the diff boundary observer counter lives in its fixture (#25170)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 25, 2026 at 17:46 UTC 0ad399c6c5fc521f26e42cfcd50ec056390e4870
1 file changed +24 -21
apps/web/src/components/diffs/DiffFileLoadingBoundary.browser.test.tsx
+24 -21
@@ -3,31 +3,34 @@ import { describe, expect, it, vi } from "vite-plus/test";
3 import { render } from "../../../test/render";
4 import { DiffFileLoadingBoundary } from "./DiffFileLoadingBoundary";
5
6 -// Like the real observer, every observe() reports the target's current state; this boundary
7 -// is always in range.
8 -class InRangeIntersectionObserver {
9 - static observeCount = 0;
10 - constructor(readonly callback: IntersectionObserverCallback) {}
11 - observe(target: Element) {
12 - InRangeIntersectionObserver.observeCount += 1;
13 - this.callback(
14 - [{ target, isIntersecting: true } as IntersectionObserverEntry],
15 - this as unknown as IntersectionObserver,
16 - );
17 - }
18 - unobserve() {}
19 - disconnect() {}
20 -}
21 -
6 function stubIntersectionObserver() {
23 - InRangeIntersectionObserver.observeCount = 0;
7 + let observeCount = 0;
8 + // Like the real observer, every observe() reports the target's current state; this boundary
9 + // is always in range.
10 + class InRangeIntersectionObserver {
11 + constructor(readonly callback: IntersectionObserverCallback) {}
12 + observe(target: Element) {
13 + observeCount += 1;
14 + this.callback(
15 + [{ target, isIntersecting: true } as IntersectionObserverEntry],
16 + this as unknown as IntersectionObserver,
17 + );
18 + }
19 + unobserve() {}
20 + disconnect() {}
21 + }
22 vi.stubGlobal("IntersectionObserver", InRangeIntersectionObserver);
25 - return { [Symbol.dispose]: () => vi.unstubAllGlobals() };
23 + return {
24 + get observeCount() {
25 + return observeCount;
26 + },
27 + [Symbol.dispose]: () => vi.unstubAllGlobals(),
28 + };
29 }
30
31 describe("DiffFileLoadingBoundary", () => {
32 it("observes once and loads once while its parent re-renders with a new load", async () => {
30 - using _observer = stubIntersectionObserver();
33 + using observer = stubIntersectionObserver();
34 const load = vi.fn();
35 // DiffPanel hands over a new loadNextFiles whenever any file patch changes.
36 await using screen = await render(<DiffFileLoadingBoundary load={() => load()} count={8} />, {
@@ -38,12 +41,12 @@ describe("DiffFileLoadingBoundary", () => {
41 await screen.rerender(<DiffFileLoadingBoundary load={() => load()} count={8} />);
42
43 await expect.element(screen.getByRole("status", { name: "Loading diff…" })).toBeInTheDocument();
41 - expect(InRangeIntersectionObserver.observeCount).toBe(1);
44 + expect(observer.observeCount).toBe(1);
45 expect(load).toHaveBeenCalledTimes(1);
46
47 // A settled batch leaves the boundary in range, so it asks for the next one.
48 await screen.rerender(<DiffFileLoadingBoundary load={() => load()} count={4} />);
46 - expect(InRangeIntersectionObserver.observeCount).toBe(1);
49 + expect(observer.observeCount).toBe(1);
50 expect(load).toHaveBeenCalledTimes(2);
51 });
52 });