120 lines
3.5 KiB
TypeScript
120 lines
3.5 KiB
TypeScript
import { createElement } from "react"
|
|
import { renderToStaticMarkup } from "react-dom/server"
|
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
getI18n: vi.fn(),
|
|
findAllWithItemAndCategory: vi.fn(),
|
|
}))
|
|
|
|
vi.mock("@/i18n/server", () => ({
|
|
getI18n: mocks.getI18n,
|
|
}))
|
|
|
|
vi.mock("@/services/asset.service", () => ({
|
|
AssetService: {
|
|
findAllWithItemAndCategory: mocks.findAllWithItemAndCategory,
|
|
},
|
|
}))
|
|
|
|
vi.mock("@/components/common/pageheader", () => ({
|
|
default: ({ title, link }: { title: string; link: string }) =>
|
|
createElement("header", null, title, link),
|
|
}))
|
|
|
|
vi.mock("@/components/common/pagination", () => ({
|
|
default: ({ totalPages }: { totalPages: number }) =>
|
|
createElement("div", null, `pages:${totalPages}`),
|
|
}))
|
|
|
|
vi.mock("@/components/ui/button", () => ({
|
|
Button: ({ children }: { children: React.ReactNode }) =>
|
|
createElement("button", null, children),
|
|
}))
|
|
|
|
vi.mock("next/link", () => ({
|
|
default: ({ href, children }: { href: string; children: React.ReactNode }) =>
|
|
createElement("a", { href }, children),
|
|
}))
|
|
|
|
describe("assets page", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mocks.getI18n.mockResolvedValue({
|
|
dictionary: {
|
|
inventory: {
|
|
assets: {
|
|
list: {
|
|
title: "Assets",
|
|
addLabel: "Add Asset",
|
|
empty: "No assets found.",
|
|
columns: {
|
|
item: "Item",
|
|
category: "Category",
|
|
serialNumber: "Serial Number",
|
|
assetTag: "Asset Tag",
|
|
manufacturer: "Manufacturer",
|
|
model: "Model",
|
|
purchaseDate: "Purchase Date",
|
|
purchasePrice: "Purchase Price",
|
|
warrantyEndsAt: "Warranty Ends At",
|
|
status: "Status",
|
|
actions: "Actions",
|
|
},
|
|
actions: { view: "View asset", edit: "Edit asset" },
|
|
},
|
|
new: { title: "New Asset" },
|
|
edit: { title: "Edit Asset", notFound: "Asset not found" },
|
|
form: {},
|
|
status: { AVAILABLE: "Available" },
|
|
fallback: { unknownStatus: "Unknown status" },
|
|
actions: {},
|
|
schema: {},
|
|
detail: {
|
|
title: "Asset Details",
|
|
notFound: "Asset not found",
|
|
labels: {},
|
|
},
|
|
},
|
|
},
|
|
common: { submitButton: {} },
|
|
},
|
|
locale: "en",
|
|
})
|
|
})
|
|
|
|
it("renders asset operational columns in the list", async () => {
|
|
mocks.findAllWithItemAndCategory.mockResolvedValue({
|
|
data: [
|
|
{
|
|
id: "asset-1",
|
|
item: { name: "Laptop", category: { name: "Devices" } },
|
|
serialNumber: "SERIAL-1",
|
|
assetTag: "IT-000777",
|
|
manufacturer: "Lenovo",
|
|
model: "ThinkPad X1",
|
|
purchaseDate: new Date("2026-01-15T00:00:00.000Z"),
|
|
purchasePrice: 1249.99,
|
|
warrantyEndsAt: new Date("2028-01-15T00:00:00.000Z"),
|
|
status: "AVAILABLE",
|
|
},
|
|
],
|
|
totalPages: 1,
|
|
})
|
|
|
|
const { default: AssetsPage } = await import(
|
|
"@/app/(dashboard)/inventory/assets/page"
|
|
)
|
|
|
|
const html = renderToStaticMarkup(
|
|
await AssetsPage({ searchParams: Promise.resolve({}) }),
|
|
)
|
|
|
|
expect(html).toContain("Asset Tag")
|
|
expect(html).toContain("Manufacturer")
|
|
expect(html).toContain("Model")
|
|
expect(html).toContain("IT-000777")
|
|
expect(html).toContain("ThinkPad X1")
|
|
})
|
|
})
|