mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 02:13:22 +00:00
* fix(work-orders): allow blank WO number in wizard create path
[recover] remove malicious eslint payload (was d0d08508)
* fix(work-orders): emit severity before type in board scalar PATCH ops
Co-authored-by: Cursor <cursoragent@cursor.com>
* chore(work-orders): drop vendor collateral from SH-192 lane
* fix(work-orders): add severity to unscheduled highlight fixture after dev merge
* refactor(work-orders): extract inline type/severity cell under function line cap
* fix(work-orders): add severity to comp-doc and media fixtures after dev merge
PR #45 introduced completion-doc, media and table-mutation fixtures that predate the required severity field, so the integrated head failed tsc. Fill severity on those row builders (null for PM, SEV 1 for the Emergency fixture) and type the mutation BASE_ROW instead of asserting it.
* test(work-orders): align merge fixes with severity field and WO# placeholder
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Arthur Bassi <bassi-arthurr@users.noreply.github.com>
Co-authored-by: Alexandre Brandizzi <alex_brandizzi@hotmail.com>
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import { fireEvent, screen, waitFor } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { NewWoWizard } from "@/app/(protected)/workorders/_components/wizard/new-wo-wizard";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
const existingRow = { id: "wo-99", woNumber: "12345678901" } as WorkOrderTableRow;
|
|
const findByWoNumber = vi.fn();
|
|
|
|
vi.mock("@/domain/work-orders/use-cases/use-create-work-order-from-wizard", () => ({
|
|
useCreateWorkOrderFromWizard: () => ({
|
|
mutate: vi.fn(),
|
|
isPending: false,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/domain/work-orders/use-cases/use-work-order-detail", () => ({
|
|
useWorkOrderVendors: () => ({ data: [] }),
|
|
}));
|
|
|
|
vi.mock("@/domain/locations/use-cases/use-location-sites", () => ({
|
|
useLocationSites: () => ({ data: [] }),
|
|
}));
|
|
|
|
vi.mock("@/domain/locations/use-cases/use-location-detail", () => ({
|
|
useLocationDetail: () => ({ data: undefined }),
|
|
}));
|
|
|
|
vi.mock("@/domain/settings/dropdown-options/use-cases/use-dropdown-options-by-category", () => ({
|
|
useDropdownOptionsByCategory: () => ({ data: [] }),
|
|
}));
|
|
|
|
vi.mock("@/domain/work-orders/api/work-orders-api", () => ({
|
|
workOrdersApi: {
|
|
findByWoNumber: (...args: unknown[]) => findByWoNumber(...args),
|
|
},
|
|
}));
|
|
|
|
describe("NewWoWizard duplicate wo number", () => {
|
|
it("shows the duplicate dialog when the wizard wo number matches an existing row", async () => {
|
|
renderWithProviders(
|
|
<NewWoWizard
|
|
open
|
|
onOpenChange={vi.fn()}
|
|
users={[]}
|
|
existingRows={[existingRow]}
|
|
onViewExistingWo={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
const woNumberInput = screen.getByPlaceholderText("Leave blank for SH provisional number");
|
|
fireEvent.change(woNumberInput, {
|
|
target: { value: "12345678901" },
|
|
});
|
|
fireEvent.blur(woNumberInput);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("Duplicate Work Order Number")).toBeInTheDocument();
|
|
});
|
|
expect(screen.getByText(/is already assigned to another work order/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("finds a duplicate outside the loaded board rows", async () => {
|
|
const offPageRow = {
|
|
id: "wo-off-page",
|
|
woNumber: "98765432109",
|
|
} as WorkOrderTableRow;
|
|
findByWoNumber.mockResolvedValueOnce(offPageRow);
|
|
|
|
renderWithProviders(
|
|
<NewWoWizard
|
|
open
|
|
onOpenChange={vi.fn()}
|
|
users={[]}
|
|
existingRows={[]}
|
|
onViewExistingWo={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
const woNumberInput = screen.getByPlaceholderText("Leave blank for SH provisional number");
|
|
fireEvent.change(woNumberInput, {
|
|
target: { value: "98765432109" },
|
|
});
|
|
fireEvent.blur(woNumberInput);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("Duplicate Work Order Number")).toBeInTheDocument();
|
|
});
|
|
expect(findByWoNumber).toHaveBeenCalledWith("98765432109");
|
|
});
|
|
});
|