feat(i18n): localize inventory assignments UI
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
import { createElement } from "react"
|
||||
import { renderToStaticMarkup } from "react-dom/server"
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest"
|
||||
|
||||
import { es } from "@/i18n/dictionaries/es"
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
findAllWithRecipientPaginated: vi.fn(),
|
||||
getI18n: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
returnAssignment: vi.fn(),
|
||||
toastError: vi.fn(),
|
||||
toastSuccess: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock("@/i18n/server", () => ({
|
||||
getI18n: mocks.getI18n,
|
||||
}))
|
||||
|
||||
vi.mock("@/services/assignment.service", () => ({
|
||||
AssignmentService: {
|
||||
findAllWithRecipientPaginated: mocks.findAllWithRecipientPaginated,
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock("@/actions/assignment.actions", () => ({
|
||||
returnAssignment: mocks.returnAssignment,
|
||||
}))
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
refresh: mocks.refresh,
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock("sonner", () => ({
|
||||
toast: {
|
||||
error: mocks.toastError,
|
||||
success: mocks.toastSuccess,
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock("@/components/common/pageheader", () => ({
|
||||
default: ({ title, addLabel }: { title: string; addLabel?: string }) =>
|
||||
createElement(
|
||||
"header",
|
||||
null,
|
||||
[title, addLabel].filter(Boolean).join(" | "),
|
||||
),
|
||||
}))
|
||||
|
||||
vi.mock("@/components/common/pagination", () => ({
|
||||
default: ({ totalPages }: { totalPages: number }) =>
|
||||
createElement("nav", { "aria-label": "Pagination" }, totalPages),
|
||||
}))
|
||||
|
||||
describe("assignment pages localization", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
||||
})
|
||||
|
||||
it("renders the assignment list in Spanish with localized action labels and unchanged assignment data", async () => {
|
||||
const { default: AssignmentsPage } = await import(
|
||||
"@/app/(dashboard)/assignments/page"
|
||||
)
|
||||
|
||||
mocks.findAllWithRecipientPaginated.mockResolvedValue({
|
||||
data: [
|
||||
{
|
||||
id: "assignment-1",
|
||||
quantity: 2,
|
||||
recipient: {
|
||||
id: "recipient-1",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
},
|
||||
item: {
|
||||
id: "item-1",
|
||||
name: "Laptop",
|
||||
},
|
||||
asset: {
|
||||
serialNumber: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
totalPages: 1,
|
||||
})
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
await AssignmentsPage({ searchParams: Promise.resolve({}) }),
|
||||
)
|
||||
|
||||
expect(html).toContain("Asignaciones")
|
||||
expect(html).toContain("Agregar asignación")
|
||||
expect(html).toContain("Destinatario")
|
||||
expect(html).toContain("Artículo")
|
||||
expect(html).toContain("Número de serie")
|
||||
expect(html).toContain("Cantidad")
|
||||
expect(html).toContain("Acciones")
|
||||
expect(html).toContain("Ada Lovelace")
|
||||
expect(html).toContain("Laptop")
|
||||
expect(html).toContain("No disponible")
|
||||
expect(html).toContain('aria-label="Editar asignación"')
|
||||
expect(html).toContain('aria-label="Devolver asignación"')
|
||||
})
|
||||
|
||||
it("renders the localized assignment empty state when no assignments exist", async () => {
|
||||
const { default: AssignmentsPage } = await import(
|
||||
"@/app/(dashboard)/assignments/page"
|
||||
)
|
||||
|
||||
mocks.findAllWithRecipientPaginated.mockResolvedValue({
|
||||
data: [],
|
||||
totalPages: 0,
|
||||
})
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
await AssignmentsPage({ searchParams: Promise.resolve({}) }),
|
||||
)
|
||||
|
||||
expect(html).toContain("No se encontraron asignaciones.")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user