88 lines
2.0 KiB
TypeScript
88 lines
2.0 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server"
|
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
|
|
import { es } from "@/i18n/dictionaries/es"
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
getI18n: vi.fn(),
|
|
findById: vi.fn(),
|
|
redirect: vi.fn(),
|
|
}))
|
|
|
|
vi.mock("@/i18n/server", () => ({
|
|
getI18n: mocks.getI18n,
|
|
}))
|
|
|
|
vi.mock("@/services/person.service", () => ({
|
|
PersonService: {
|
|
findById: mocks.findById,
|
|
},
|
|
}))
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
redirect: mocks.redirect,
|
|
useRouter: () => ({
|
|
push: vi.fn(),
|
|
}),
|
|
}))
|
|
|
|
vi.mock("@/actions/person.actions", () => ({
|
|
createNewPerson: vi.fn(),
|
|
updatePerson: vi.fn(),
|
|
}))
|
|
|
|
vi.mock("sonner", () => ({
|
|
toast: {
|
|
error: vi.fn(),
|
|
success: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
describe("person pages", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
|
})
|
|
|
|
it("renders the edit person page with Person heading and no username", async () => {
|
|
const { default: PersonEditPage } = await import(
|
|
"@/app/(dashboard)/people/[personId]/edit/page"
|
|
)
|
|
|
|
mocks.findById.mockResolvedValue({
|
|
id: "person-1",
|
|
firstName: "Ada",
|
|
lastName: "Lovelace",
|
|
email: "ada@example.test",
|
|
phone: "1234",
|
|
department: "ENGINEERING",
|
|
})
|
|
|
|
const html = renderToStaticMarkup(
|
|
await PersonEditPage({
|
|
params: Promise.resolve({ personId: "person-1" }),
|
|
}),
|
|
)
|
|
|
|
expect(html).toContain("Editar persona")
|
|
expect(html).toContain("Actualizar persona")
|
|
expect(html).not.toContain("Usuario")
|
|
})
|
|
|
|
it("renders a Person not-found message on edit page", async () => {
|
|
const { default: PersonEditPage } = await import(
|
|
"@/app/(dashboard)/people/[personId]/edit/page"
|
|
)
|
|
|
|
mocks.findById.mockResolvedValue(null)
|
|
|
|
const html = renderToStaticMarkup(
|
|
await PersonEditPage({
|
|
params: Promise.resolve({ personId: "missing-person" }),
|
|
}),
|
|
)
|
|
|
|
expect(html).toContain("Persona no encontrada")
|
|
})
|
|
})
|