@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
tsx 75 lines 2.32 KB
Raw
1 import type { ReactNode } from "react";
2 import { act } from "react";
3 import { createRoot } from "react-dom/client";
4 import { describe, expect, it, vi } from "vite-plus/test";
5
6 type PanEvent = { readonly translationY: number };
7 type PanHandlers = {
8 onStart?: () => void;
9 onUpdate?: (event: PanEvent) => void;
10 onFinalize?: (event: PanEvent, success: boolean) => void;
11 };
12
13 const pans = vi.hoisted(() => [] as PanHandlers[]);
14
15 vi.mock("react-native", () => ({
16 View: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
17 }));
18 vi.mock("react-native-gesture-handler", () => ({
19 GestureDetector: ({ children }: { children?: ReactNode }) => children,
20 Gesture: {
21 Pan: () => {
22 const handlers: PanHandlers = {};
23 pans.push(handlers);
24 const pan = {
25 minDistance: () => pan,
26 shouldCancelWhenOutside: () => pan,
27 runOnJS: () => pan,
28 onStart: (callback: PanHandlers["onStart"]) => ((handlers.onStart = callback), pan),
29 onUpdate: (callback: PanHandlers["onUpdate"]) => ((handlers.onUpdate = callback), pan),
30 onFinalize: (callback: PanHandlers["onFinalize"]) => (
31 (handlers.onFinalize = callback),
32 pan
33 ),
34 };
35 return pan;
36 },
37 },
38 }));
39 vi.mock("../../../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
40
41 import { SettingsDragHandle } from "./SettingsDragHandle";
42
43 describe("SettingsDragHandle", () => {
44 // The worklets Babel plugin copies values a gesture callback closes over when the gesture is
45 // built, so a drop must not read a translation tracked in a local variable.
46 it("reports the released translation when the pan ends", () => {
47 pans.length = 0;
48 const onEnd = vi.fn();
49 const root = createRoot(document.createElement("div"));
50 act(() =>
51 root.render(
52 <SettingsDragHandle
53 title="Built-in microphone"
54 canMoveUp
55 canMoveDown
56 onStart={() => {}}
57 onMove={() => {}}
58 onEnd={onEnd}
59 onStep={() => {}}
60 />,
61 ),
62 );
63 const pan = pans.at(-1)!;
64
65 act(() => {
66 pan.onStart?.();
67 pan.onUpdate?.({ translationY: 64 });
68 pan.onUpdate?.({ translationY: 130 });
69 pan.onFinalize?.({ translationY: 130 }, true);
70 });
71
72 expect(onEnd).toHaveBeenCalledWith(130, false);
73 act(() => root.unmount());
74 });
75 });