refactor: rename recipients route to people, update all frontend references
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
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(),
|
||||
createNewPerson: vi.fn(),
|
||||
updatePerson: vi.fn(),
|
||||
push: vi.fn(),
|
||||
toastError: vi.fn(),
|
||||
toastSuccess: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock("@/i18n/server", () => ({
|
||||
getI18n: mocks.getI18n,
|
||||
}))
|
||||
|
||||
vi.mock("@/services/person.service", () => ({
|
||||
PersonService: {
|
||||
findById: mocks.findById,
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock("@/actions/person.actions", () => ({
|
||||
createNewPerson: mocks.createNewPerson,
|
||||
updatePerson: mocks.updatePerson,
|
||||
}))
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: mocks.push,
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock("sonner", () => ({
|
||||
toast: {
|
||||
error: mocks.toastError,
|
||||
success: mocks.toastSuccess,
|
||||
},
|
||||
}))
|
||||
|
||||
describe("person form pages", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
||||
})
|
||||
|
||||
it("renders the new person page with Person form copy and no username field", async () => {
|
||||
const { default: NewPersonPage } = await import(
|
||||
"@/app/(dashboard)/people/new/page"
|
||||
)
|
||||
|
||||
const html = renderToStaticMarkup(await NewPersonPage())
|
||||
|
||||
// Person form, not Recipient
|
||||
expect(html).toContain("Agregar persona")
|
||||
// No username label or placeholder
|
||||
expect(html).not.toContain("Usuario")
|
||||
expect(html).not.toContain('placeholder="Usuario"')
|
||||
// Has expected person form fields
|
||||
expect(html).toContain("Nombre")
|
||||
expect(html).toContain("Apellido")
|
||||
expect(html).toContain("Selecciona un departamento")
|
||||
expect(html).toContain('option value="ENGINEERING"')
|
||||
expect(html).toContain(">Ingeniería</option>")
|
||||
// Has department options from PERSON_DEPARTMENTS
|
||||
expect(html).toContain("Correo electrónico")
|
||||
expect(html).toContain("Teléfono")
|
||||
expect(html).toContain("Crear persona")
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
|
||||
it("wires English Person form submit copy through the new page", async () => {
|
||||
const { default: NewPersonPage } = await import(
|
||||
"@/app/(dashboard)/people/new/page"
|
||||
)
|
||||
|
||||
mocks.getI18n.mockResolvedValueOnce({ dictionary: en, locale: "en" })
|
||||
|
||||
const html = renderToStaticMarkup(await NewPersonPage())
|
||||
|
||||
expect(html).toContain("Create Person")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user