import * as Native from "@effect/ui-native/Native" import * as NativeHost from "@effect/ui-native/NativeHost" import { assert, describe, it, vi } from "vitest" import * as FakeFabric from "./utils/FakeFabric.ts" vi.mock("react-native/Libraries/Core/Devtools/getDevServer", () => ({ default: () => ({ fullBundleUrl: null }) })) vi.mock("react-native/Libraries/Utilities/DevSettings", () => ({ default: { reload() {}, onFastRefresh() {} } })) vi.mock("react-native/Libraries/WebSocket/WebSocket", () => ({ default: () => {} })) vi.mock("#dev", () => import("@effect/ui-native/internal/devOn")) describe("NativeHost dev warnings", () => { it("warns once per view and reserved event when a native top* arrives without an events hook", () => { const warnings: Array = [] const warn = vi.spyOn(console, "warn").mockImplementation((message) => { warnings.push(String(message)) }) try { const hooked: Array = [] Native.defineView(() => new Native.Element("customBtn"), { viewName: "CustomButton" }) Native.defineView(() => new Native.Element("hookedBtn"), { viewName: "HookedButton", events: { topPress: (_, payload) => hooked.push(payload) } }) const fabric = FakeFabric.make() const { host, root } = NativeHost.make({ ui: fabric.ui, rootTag: 1, device: FakeFabric.device({ os: "macos" }) }) const custom = host.createElement("customBtn", {}) const hookedNode = host.createElement("hookedBtn", {}) const view = host.createElement("view", {}) host.insertBefore(root, custom, undefined) host.insertBefore(root, hookedNode, undefined) host.insertBefore(root, view, undefined) host.commit!() const customShadow = FakeFabric.find( fabric.committed(), FakeFabric.byName("CustomButton") )! const hookedShadow = FakeFabric.find( fabric.committed(), FakeFabric.byName("HookedButton") )! const viewShadow = FakeFabric.find( fabric.committed(), FakeFabric.byName("RCTView") )! fabric.emit(customShadow, "topPress", {}) fabric.emit(customShadow, "topPress", {}) fabric.emit(customShadow, "topPan", {}) fabric.emit(hookedShadow, "topPress", { ok: true }) // Host-routed pointer and click events do not warn. fabric.emit(viewShadow, "topClick", {}) fabric.emit(viewShadow, "topPointerDown", { pointerId: 1 }) fabric.emit(customShadow, "topPointerEnter", { pointerId: 1 }) assert.strictEqual(warnings.length, 2) assert.include(warnings[0], "CustomButton") assert.include(warnings[0], "topPress") assert.include(warnings[0], "\"press\"") assert.include(warnings[1], "topPan") assert.deepStrictEqual(hooked, [{ ok: true }]) } finally { warn.mockRestore() } }) })