Files
fusion/packages/dashboard/app/test/mockHelpers.test.ts
Fusion 8e09af95ea feat(FN-3044): add canonical mock helpers and migrate representative test s
This merge introduces canonical mock helper modules across the dashboard and engine packages, and migrates representative test suites to use them for consistency. The changes add four new mock helpers (`mockApi.ts`, `mockLucide.ts`, `mockCore.ts`, `mockCoreEngine.ts`) and harden the API mock proxy's

Fusion-Task-Id: FN-3044
2026-05-01 00:33:17 -07:00

36 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createDashboardApiMock, dashboardApiMocks, resetDashboardApiMockState } from "./mockApi";
import { createLucideMock } from "./mockLucide";
describe("dashboard test mock helpers", () => {
it("creates stable fallback mocks for missing API function exports", async () => {
const module = await createDashboardApiMock(async () => ({ known: () => "ok" }));
const first = module.missingApi as (...args: unknown[]) => Promise<unknown>;
const second = module.missingApi as (...args: unknown[]) => Promise<unknown>;
expect(first).toBe(second);
await first("arg");
expect(first).toHaveBeenCalledWith("arg");
resetDashboardApiMockState();
expect(first).not.toHaveBeenCalled();
});
it("auto-generates missing lucide icons while preserving provided exports", async () => {
const existing = () => "existing";
const module = await createLucideMock(async () => ({ ExistingIcon: existing }));
expect(module.ExistingIcon).toBe(existing);
const Generated = module.BrandNewIcon as (props: Record<string, unknown>) => any;
const rendered = Generated({ className: "x" });
expect(rendered.props["data-testid"]).toBe("icon-brand-new-icon");
expect(rendered.props.className).toBe("x");
});
it("keeps canonical dashboard api mocks resettable", () => {
dashboardApiMocks.fetchSettings.mockResolvedValueOnce({ hello: "world" });
resetDashboardApiMockState();
expect(dashboardApiMocks.fetchSettings).not.toHaveBeenCalled();
});
});