import { createElement } from "react" import { renderToStaticMarkup } from "react-dom/server" import { beforeEach, describe, expect, it, vi } from "vitest" import { en } from "@/i18n/dictionaries/en" import { es } from "@/i18n/dictionaries/es" const mocks = vi.hoisted(() => ({ getI18n: vi.fn(), findById: vi.fn(), recipientForm: vi.fn(), })) vi.mock("@/i18n/server", () => ({ getI18n: mocks.getI18n, })) vi.mock("@/services/recipient.service", () => ({ RecipientService: { findById: mocks.findById, }, })) vi.mock("@/app/(dashboard)/recipients/_components/recipient.form", () => ({ default: (props: unknown) => { mocks.recipientForm(props) return createElement("div", null, "Recipient form") }, })) describe("recipient form schema wiring", () => { beforeEach(() => { vi.clearAllMocks() }) it("passes server-resolved schema copy into the new recipient form boundary", async () => { mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" }) const { default: NewRecipientPage } = await import( "@/app/(dashboard)/recipients/new/page" ) renderToStaticMarkup(await NewRecipientPage()) expect(mocks.recipientForm).toHaveBeenCalledWith( expect.objectContaining({ mode: "create", schemaCopy: es.inventory.recipients.schema, }), ) }) it("passes server-resolved schema copy into the edit recipient form boundary", async () => { mocks.getI18n.mockResolvedValue({ dictionary: en, locale: "en" }) mocks.findById.mockResolvedValue({ id: "recipient-1", username: "ada", firstName: "Ada", lastName: "Lovelace", department: "ENGINEERING", email: "ada@example.test", phone: "1234", }) const { default: RecipientEditPage } = await import( "@/app/(dashboard)/recipients/[recipientId]/edit/page" ) renderToStaticMarkup( await RecipientEditPage({ params: Promise.resolve({ recipientId: "recipient-1" }), }), ) expect(mocks.recipientForm).toHaveBeenCalledWith( expect.objectContaining({ mode: "edit", schemaCopy: en.inventory.recipients.schema, }), ) }) })