Open History to see the last commit
1import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2
3const mocks = vi.hoisted(() => ({
4 os: "android",
5 native: null as { configure?: ReturnType<typeof vi.fn>; clear?: ReturnType<typeof vi.fn> } | null,
6 config: { scheme: ["t3code-preview"], extra: { iosPersonalTeamBuild: false } },
7 requireModule: vi.fn(),
8}));
9
10vi.mock("expo", () => ({ requireOptionalNativeModule: mocks.requireModule }));
11vi.mock("expo-constants", () => ({ default: { expoConfig: mocks.config } }));
12vi.mock("react-native", () => ({
13 Platform: {
14 get OS() {
15 return mocks.os;
16 },
17 },
18}));
19
20beforeEach(() => {
21 vi.resetModules();
22 mocks.os = "android";
23 mocks.native = { configure: vi.fn(), clear: vi.fn() };
24 mocks.config.extra.iosPersonalTeamBuild = false;
25 mocks.requireModule.mockReset().mockImplementation(() => mocks.native);
26});
27
28describe("Android native notification capability", () => {
29 it("uses the installed module and the build variant's deep-link scheme", async () => {
30 const { configureAndroidAgentNotifications, clearAndroidAgentNotifications } =
31 await import("./androidNotifications");
32 const { supportsAgentAwarenessPush } = await import("./capabilities");
33 // An iOS-only signing restriction must not disable Android notifications.
34 mocks.config.extra.iosPersonalTeamBuild = true;
35 expect(supportsAgentAwarenessPush()).toBe(true);
36 configureAndroidAgentNotifications("device", "user", false);
37 expect(mocks.native?.configure).toHaveBeenCalledWith("device", "user", "t3code-preview", false);
38 clearAndroidAgentNotifications();
39 expect(mocks.native?.clear).toHaveBeenCalledOnce();
40 });
41
42 it.each([null, { clear: vi.fn() }, { configure: vi.fn() }])(
43 "disables push when the native binary is missing required methods (%j)",
44 async (native) => {
45 mocks.native = native;
46 const { configureAndroidAgentNotifications, clearAndroidAgentNotifications } =
47 await import("./androidNotifications");
48 const { supportsAgentAwarenessPush } = await import("./capabilities");
49 expect(supportsAgentAwarenessPush()).toBe(false);
50 expect(() => configureAndroidAgentNotifications("device", "user", true)).not.toThrow();
51 expect(() => clearAndroidAgentNotifications()).not.toThrow();
52 },
53 );
54
55 it("preserves the iOS personal-team restriction without loading Android code", async () => {
56 mocks.os = "ios";
57 const { supportsAgentAwarenessPush } = await import("./capabilities");
58 expect(supportsAgentAwarenessPush()).toBe(true);
59 mocks.config.extra.iosPersonalTeamBuild = true;
60 expect(supportsAgentAwarenessPush()).toBe(false);
61 expect(mocks.requireModule).not.toHaveBeenCalled();
62 });
63});