@devries-cameron20 / t3code Mirror · read-only
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 21, 04:45 UTC

main
ts 88 lines 3.56 KB
Raw
1 import { expect, it, vi } from "vite-plus/test";
2
3 vi.mock("react-native", () => ({ View: () => null }));
4 vi.mock("expo", () => ({ requireNativeView: vi.fn() }));
5 vi.mock("../../components/ui/EmptyState", () => ({ EmptyState: () => null }));
6
7 import {
8 handlePullRequestDiffDebugEvent,
9 pullRequestDiffInitialPosition,
10 } from "./pullRequestDiffDebug";
11 import { createReviewDiffHighlightScheduler } from "../review/reviewDiffHighlightScheduler";
12 import type { NativeReviewDiffViewProps } from "../diffs/nativeReviewDiffSurface";
13
14 it("enters at a file header without changing guide focus positioning", () => {
15 expect(pullRequestDiffInitialPosition("last-file", -1)).toEqual({
16 initialFileId: "last-file",
17 initialRowIndex: -1,
18 });
19 expect(pullRequestDiffInitialPosition("last-file", 904)).toEqual({
20 initialFileId: "",
21 initialRowIndex: 901,
22 });
23 expect(pullRequestDiffInitialPosition(undefined, -1)).toEqual({
24 initialFileId: "",
25 initialRowIndex: -1,
26 });
27 });
28
29 it.each([true, false])(
30 "starts warm highlighting at the declared file without a JS jump (iOS: %s)",
31 async (isIos) => {
32 vi.useFakeTimers();
33 // A warm engine can issue its source RPC immediately when the scheduler flushes.
34 const sourceRequest = vi.fn();
35 const scheduler = createReviewDiffHighlightScheduler(sourceRequest);
36 const scrollToFile = vi.fn(async () => {});
37 const loadMore = vi.fn();
38 const onDebug: NonNullable<NativeReviewDiffViewProps["onDebug"]> = ({ nativeEvent }) => {
39 if (nativeEvent.message === "visible-range")
40 scheduler.update({
41 firstRowIndex: nativeEvent.firstRowIndex as number,
42 lastRowIndex: nativeEvent.lastRowIndex as number,
43 });
44 };
45 let lastShownRowIndex = 999;
46 const emit = (nativeEvent: Record<string, unknown>) =>
47 handlePullRequestDiffDebugEvent({ nativeEvent } as Parameters<typeof onDebug>[0], {
48 rowCount: 1000,
49 lastShownRowIndex,
50 targetFileId: "last-file",
51 focusIndex: -1,
52 isIos,
53 nativeView: { current: { scrollToFile, scrollToTop: vi.fn(async () => {}) } },
54 jumpStarted: () => true,
55 setJumpStarted: () => {},
56 onDebug,
57 loadMore,
58 });
59 try {
60 const position = pullRequestDiffInitialPosition("last-file", -1);
61 emit({ message: "rows-decoded", rows: 1000 });
62 // Native applies the declared file before publishing its viewport. A later
63 // imperative bridge command cannot retract an RPC started from a top range.
64 const first = position.initialFileId === "last-file" ? 900 : 0;
65 emit({
66 message: "visible-range",
67 firstRowIndex: first,
68 lastRowIndex: first + 40,
69 totalRows: 1000,
70 });
71 await vi.runOnlyPendingTimersAsync();
72 expect(sourceRequest.mock.calls).toEqual([[{ firstRowIndex: 900, lastRowIndex: 940 }]]);
73 expect(scrollToFile).not.toHaveBeenCalled();
74 // Near-end pagination and stale-payload filtering still use native ranges.
75 emit({ message: "visible-range", firstRowIndex: 950, lastRowIndex: 990, totalRows: 999 });
76 expect(loadMore).not.toHaveBeenCalled();
77 emit({ message: "visible-range", firstRowIndex: 950, lastRowIndex: 990, totalRows: 1000 });
78 expect(loadMore).toHaveBeenCalledOnce();
79 // A folded final file ends at its header, short of the full payload's tail.
80 lastShownRowIndex = 920;
81 emit({ message: "visible-range", firstRowIndex: 880, lastRowIndex: 920, totalRows: 1000 });
82 expect(loadMore).toHaveBeenCalledTimes(2);
83 } finally {
84 scheduler.cancel();
85 vi.useRealTimers();
86 }
87 },
88 );