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

nativeReviewDiffSurface.test.ts

67 lines2.4 KB

1import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2​
3const expoMocks = vi.hoisted(() => ({
4 requireNativeView: vi.fn(),
5}));
6const nativeView = () => null;
7const originalExpo = globalThis.expo;
8​
9function setExpoViewConfigAvailable() {
10 globalThis.expo = {
11 getViewConfig: vi.fn().mockReturnValue({ validAttributes: {}, directEventTypes: {} }),
12 } as unknown as typeof globalThis.expo;
14​
15vi.mock("expo", () => ({
16 requireNativeView: expoMocks.requireNativeView,
17}));
18​
19describe("resolveNativeReviewDiffView", () => {
20 beforeEach(() => {
21 vi.clearAllMocks();
22 vi.resetModules();
23 globalThis.expo = undefined as unknown as typeof globalThis.expo;
24 });
25​
26 afterEach(() => {
27 globalThis.expo = originalExpo;
28 });
29​
30 it("returns null when the native review diff view config is unavailable", async () => {
31 const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffSurface");
32 expect(resolveNativeReviewDiffView()).toBeNull();
33 expect(expoMocks.requireNativeView).not.toHaveBeenCalled();
34 });
35​
36 it("returns the native review diff view when the view config is installed", async () => {
37 setExpoViewConfigAvailable();
38 expoMocks.requireNativeView.mockReturnValue(nativeView);
39 const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffSurface");
40 expect(resolveNativeReviewDiffView()).toBe(nativeView);
41 expect(expoMocks.requireNativeView).toHaveBeenCalledWith("T3ReviewDiffSurface");
42 });
43​
44 it("does not fall back to stale legacy native review diff view names", async () => {
45 globalThis.expo = {
46 getViewConfig: vi.fn().mockImplementation((moduleName: string) => {
47 if (moduleName === "T3ReviewDiffView") {
48 return { validAttributes: {}, directEventTypes: {} };
49 }
50 return null;
51 }),
52 } as unknown as typeof globalThis.expo;
53 expoMocks.requireNativeView.mockReturnValue(nativeView);
54 const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffSurface");
55 expect(resolveNativeReviewDiffView()).toBeNull();
56 expect(expoMocks.requireNativeView).not.toHaveBeenCalled();
57 });
58​
59 it("returns null when the view manager cannot be required", async () => {
60 setExpoViewConfigAvailable();
61 expoMocks.requireNativeView.mockImplementation(() => {
62 throw new Error("boom");
63 });
64 const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffSurface");
65 expect(resolveNativeReviewDiffView()).toBeNull();
66 });
67});