- Add iOS review diff module, parser, and highlighter support - Wire mobile native lint tooling into CI and local docs - Include fixtures and tests for the new diff pipeline
Showing the changes to apps/mobile/src/features/debug/native-review-diff/nativeReviewDiffModule.test.ts (1 of 26 files). Show all
Unified · Split
| @@ -0,0 +1,69 @@ | ||
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | + | |
| 3 | +const expoModulesCoreMocks = vi.hoisted(() => ({ | |
| 4 | + requireNativeViewManager: vi.fn(), | |
| 5 | +})); | |
| 6 | +const nativeView = () => null; | |
| 7 | +const originalExpo = globalThis.expo; | |
| 8 | + | |
| 9 | +function setExpoViewConfigAvailable() { | |
| 10 | + globalThis.expo = { | |
| 11 | + getViewConfig: vi.fn().mockReturnValue({ validAttributes: {}, directEventTypes: {} }), | |
| 12 | + } as unknown as typeof globalThis.expo; | |
| 13 | +} | |
| 14 | + | |
| 15 | +vi.mock("expo-modules-core", () => ({ | |
| 16 | + requireNativeViewManager: expoModulesCoreMocks.requireNativeViewManager, | |
| 17 | +})); | |
| 18 | + | |
| 19 | +describe("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("./nativeReviewDiffModule"); | |
| 32 | + expect(resolveNativeReviewDiffView()).toBeNull(); | |
| 33 | + expect(expoModulesCoreMocks.requireNativeViewManager).not.toHaveBeenCalled(); | |
| 34 | + }); | |
| 35 | + | |
| 36 | + it("returns the native review diff view when the view config is installed", async () => { | |
| 37 | + setExpoViewConfigAvailable(); | |
| 38 | + expoModulesCoreMocks.requireNativeViewManager.mockReturnValue(nativeView); | |
| 39 | + const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffModule"); | |
| 40 | + expect(resolveNativeReviewDiffView()).toBe(nativeView); | |
| 41 | + expect(expoModulesCoreMocks.requireNativeViewManager).toHaveBeenCalledWith( | |
| 42 | + "T3ReviewDiffSurface", | |
| 43 | + ); | |
| 44 | + }); | |
| 45 | + | |
| 46 | + it("does not fall back to stale legacy native review diff view names", async () => { | |
| 47 | + globalThis.expo = { | |
| 48 | + getViewConfig: vi.fn().mockImplementation((moduleName: string) => { | |
| 49 | + if (moduleName === "T3ReviewDiffView") { | |
| 50 | + return { validAttributes: {}, directEventTypes: {} }; | |
| 51 | + } | |
| 52 | + return null; | |
| 53 | + }), | |
| 54 | + } as unknown as typeof globalThis.expo; | |
| 55 | + expoModulesCoreMocks.requireNativeViewManager.mockReturnValue(nativeView); | |
| 56 | + const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffModule"); | |
| 57 | + expect(resolveNativeReviewDiffView()).toBeNull(); | |
| 58 | + expect(expoModulesCoreMocks.requireNativeViewManager).not.toHaveBeenCalled(); | |
| 59 | + }); | |
| 60 | + | |
| 61 | + it("returns null when the view manager cannot be required", async () => { | |
| 62 | + setExpoViewConfigAvailable(); | |
| 63 | + expoModulesCoreMocks.requireNativeViewManager.mockImplementation(() => { | |
| 64 | + throw new Error("boom"); | |
| 65 | + }); | |
| 66 | + const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffModule"); | |
| 67 | + expect(resolveNativeReviewDiffView()).toBeNull(); | |
| 68 | + }); | |
| 69 | +}); | |