import { createElement } from "react" import { renderToStaticMarkup } from "react-dom/server" import { beforeEach, describe, expect, it, vi } from "vitest" const mocks = vi.hoisted(() => ({ useRouter: vi.fn(() => ({ push: vi.fn() })), createAssetAction: vi.fn(), })) vi.mock("next/navigation", () => ({ useRouter: mocks.useRouter, })) vi.mock("@/actions/asset.actions", () => ({ createAssetAction: mocks.createAssetAction, })) describe("new asset form", () => { beforeEach(() => { vi.clearAllMocks() }) it("renders the operational asset fields on the create form", async () => { const { default: NewAssetForm } = await import( "@/app/(dashboard)/inventory/assets/_components/new.asset.form" ) const html = renderToStaticMarkup( createElement(NewAssetForm, { items: [{ id: "item-1", name: "Laptop" }], people: [{ id: "person-1", firstName: "Ada", lastName: "Lovelace" }], formCopy: { itemLabel: "Item", itemPlaceholder: "Select an item", serialNumberLabel: "Serial Number", serialNumberPlaceholder: "Serial number", deliveryNoteLabel: "Delivery Note", deliveryNotePlaceholder: "Delivery note", statusLabel: "Status", statusPlaceholder: "Select a status", personLabel: "Person", personPlaceholder: "Select a person", assetTagLabel: "Asset Tag", assetTagPlaceholder: "Asset tag", manufacturerLabel: "Manufacturer", manufacturerPlaceholder: "Manufacturer", modelLabel: "Model", modelPlaceholder: "Model", purchaseDateLabel: "Purchase Date", purchaseDatePlaceholder: "YYYY-MM-DD", purchasePriceLabel: "Purchase Price", purchasePricePlaceholder: "0.00", warrantyEndsAtLabel: "Warranty Ends At", warrantyEndsAtPlaceholder: "YYYY-MM-DD", createSubmit: "Create Asset", updateSubmit: "Update Asset", }, schemaCopy: { itemRequired: "Item is required", serialNumberRequired: "Serial number is required", idRequired: "ID is required", statusRequired: "Status is required", invalidCreateStatus: "Status must be Available or Assigned", invalidUpdateStatus: "Invalid status", personRequired: "Person is required", }, statusCopy: { AVAILABLE: "Available", ASSIGNED: "Assigned", IN_REPAIR: "In repair", BROKEN: "Broken", LOST: "Lost", STOLEN: "Stolen", DISPOSED: "Disposed", RETIRED: "Retired", }, submitButtonCopy: { defaultLabel: "Submit", processing: "Processing", success: "Success", }, }), ) expect(html).toContain("Asset Tag") expect(html).toContain("Manufacturer") expect(html).toContain("Model") expect(html).toContain("Purchase Date") expect(html).toContain("Purchase Price") expect(html).toContain("Warranty Ends At") }) it("only exposes create-supported asset statuses", async () => { const { default: NewAssetForm } = await import( "@/app/(dashboard)/inventory/assets/_components/new.asset.form" ) const html = renderToStaticMarkup( createElement(NewAssetForm, { items: [{ id: "item-1", name: "Laptop" }], people: [], formCopy: { itemLabel: "Item", itemPlaceholder: "Select an item", serialNumberLabel: "Serial Number", serialNumberPlaceholder: "Serial number", deliveryNoteLabel: "Delivery Note", deliveryNotePlaceholder: "Delivery note", statusLabel: "Status", statusPlaceholder: "Select a status", personLabel: "Person", personPlaceholder: "Select a person", assetTagLabel: "Asset Tag", assetTagPlaceholder: "Asset tag", manufacturerLabel: "Manufacturer", manufacturerPlaceholder: "Manufacturer", modelLabel: "Model", modelPlaceholder: "Model", purchaseDateLabel: "Purchase Date", purchaseDatePlaceholder: "YYYY-MM-DD", purchasePriceLabel: "Purchase Price", purchasePricePlaceholder: "0.00", warrantyEndsAtLabel: "Warranty Ends At", warrantyEndsAtPlaceholder: "YYYY-MM-DD", createSubmit: "Create Asset", updateSubmit: "Update Asset", }, schemaCopy: { itemRequired: "Item is required", serialNumberRequired: "Serial number is required", idRequired: "ID is required", statusRequired: "Status is required", invalidCreateStatus: "Status must be Available or Assigned", invalidUpdateStatus: "Invalid status", personRequired: "Person is required", }, statusCopy: { AVAILABLE: "Available", ASSIGNED: "Assigned", IN_REPAIR: "In repair", BROKEN: "Broken", LOST: "Lost", STOLEN: "Stolen", DISPOSED: "Disposed", RETIRED: "Retired", }, submitButtonCopy: { defaultLabel: "Submit", processing: "Processing", success: "Success", }, }), ) expect(html).toContain('value="AVAILABLE"') expect(html).toContain('value="ASSIGNED"') expect(html).not.toContain('value="IN_REPAIR"') expect(html).not.toContain('value="BROKEN"') }) })