82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
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(),
|
|
personForm: vi.fn(),
|
|
}))
|
|
|
|
vi.mock("@/i18n/server", () => ({
|
|
getI18n: mocks.getI18n,
|
|
}))
|
|
|
|
vi.mock("@/services/person.service", () => ({
|
|
PersonService: {
|
|
findById: mocks.findById,
|
|
},
|
|
}))
|
|
|
|
vi.mock("@/app/(dashboard)/people/_components/person.form", () => ({
|
|
default: (props: unknown) => {
|
|
mocks.personForm(props)
|
|
return createElement("div", null, "Person form")
|
|
},
|
|
}))
|
|
|
|
describe("person form schema wiring", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it("passes server-resolved Person schema copy into the new person form boundary", async () => {
|
|
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
|
|
|
const { default: NewPersonPage } = await import(
|
|
"@/app/(dashboard)/people/new/page"
|
|
)
|
|
|
|
renderToStaticMarkup(await NewPersonPage())
|
|
|
|
expect(mocks.personForm).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
mode: "create",
|
|
schemaCopy: es.inventory.people.schema,
|
|
}),
|
|
)
|
|
})
|
|
|
|
it("passes server-resolved Person schema copy into the edit person form boundary", async () => {
|
|
mocks.getI18n.mockResolvedValue({ dictionary: en, locale: "en" })
|
|
mocks.findById.mockResolvedValue({
|
|
id: "person-1",
|
|
firstName: "Ada",
|
|
lastName: "Lovelace",
|
|
department: "ENGINEERING",
|
|
email: "ada@example.test",
|
|
phone: "1234",
|
|
})
|
|
|
|
const { default: PersonEditPage } = await import(
|
|
"@/app/(dashboard)/people/[personId]/edit/page"
|
|
)
|
|
|
|
renderToStaticMarkup(
|
|
await PersonEditPage({
|
|
params: Promise.resolve({ personId: "person-1" }),
|
|
}),
|
|
)
|
|
|
|
expect(mocks.personForm).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
mode: "edit",
|
|
schemaCopy: en.inventory.people.schema,
|
|
}),
|
|
)
|
|
})
|
|
})
|