Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
502 lines
22 KiB
TypeScript
502 lines
22 KiB
TypeScript
import { act, render, screen, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
getStockCount: vi.fn(),
|
|
saveStockCountEntries: vi.fn(),
|
|
stockCountAction: vi.fn(),
|
|
getEventCloseOut: vi.fn(),
|
|
}));
|
|
vi.mock("@/app/lib/services/adminStockCounts", () => mocks);
|
|
|
|
const events = vi.hoisted(() => ({ getEvent: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminEvents", () => events);
|
|
|
|
// The real dialog loads warehouses and posts the close; here it only proves it was opened for the
|
|
// right event and can report the close back.
|
|
vi.mock("@/app/components/events/EventCloseOutDialog", () => ({
|
|
EventCloseOutDialog: (p: { event: { name: string }; onClosed: () => void }) => (
|
|
<div role="dialog" aria-label="Close out">
|
|
Close out {p.event.name}
|
|
<button onClick={p.onClosed}>Return stock and close event</button>
|
|
</div>
|
|
),
|
|
}));
|
|
|
|
const auth = vi.hoisted(() => ({ hasModule: vi.fn() }));
|
|
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: () => ({ hasModule: auth.hasModule }) }));
|
|
|
|
// The real picker searches the server; a button that "picks" one SKU is enough here.
|
|
vi.mock("@/app/components/catalog-setup/SkuVariationPicker", () => ({
|
|
SkuVariationPicker: (p: { onSelect: (o: unknown) => void; label: string }) => (
|
|
<button
|
|
onClick={() =>
|
|
p.onSelect({ skuVariationId: 13, code: "BA-013", skuId: 1, skuCode: "BA", skuName: "Bib", variant: "13", variantName: "Blue" })
|
|
}
|
|
>
|
|
{p.label}
|
|
</button>
|
|
),
|
|
}));
|
|
|
|
const lookup = vi.hoisted(() => ({ findSkuVariationsByCode: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminCatalogSetup", () => lookup);
|
|
|
|
import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages";
|
|
import { StockCountDetail } from "./StockCountDetail";
|
|
|
|
type Line = {
|
|
skuVariationId: string;
|
|
variationId: string | null;
|
|
skuCode: string | null;
|
|
variantName: string | null;
|
|
expectedQty: number | null;
|
|
countedQty: number | null;
|
|
variance: number | null;
|
|
};
|
|
|
|
const line = (sku: string, code: string, counted: number | null, expected: number | null = null): Line => ({
|
|
skuVariationId: sku,
|
|
variationId: `V${sku}`,
|
|
skuCode: code,
|
|
variantName: `Variant ${sku}`,
|
|
expectedQty: expected,
|
|
countedQty: counted,
|
|
variance: expected === null || counted === null ? null : counted - expected,
|
|
});
|
|
|
|
const count = (status: string, lines: Line[], extra: Record<string, unknown> = {}) => ({
|
|
id: 5,
|
|
warehouseId: 7,
|
|
warehouseCode: "MYB-W",
|
|
warehouseName: "MYB-HQ",
|
|
eventId: null,
|
|
status,
|
|
openedBy: "alice",
|
|
openedDate: "2026-10-08T10:00:00",
|
|
submittedBy: status === "OPEN" ? null : "bob",
|
|
submittedDate: null,
|
|
closedBy: null,
|
|
closedDate: null,
|
|
adjustmentRef: null,
|
|
lines,
|
|
...extra,
|
|
});
|
|
|
|
const grant = (...mods: string[]) => auth.hasModule.mockImplementation((m: string) => mods.includes(m));
|
|
|
|
beforeEach(() => {
|
|
mocks.getStockCount.mockReset();
|
|
mocks.saveStockCountEntries.mockReset();
|
|
mocks.stockCountAction.mockReset();
|
|
mocks.getEventCloseOut.mockReset();
|
|
events.getEvent.mockReset();
|
|
lookup.findSkuVariationsByCode.mockReset();
|
|
grant("BO_STOCK_COUNT", "BO_STOCK_COUNT_APPROVE");
|
|
});
|
|
|
|
describe("StockCountDetail — open (blind) count", () => {
|
|
it("shows no expected quantities while counting", async () => {
|
|
mocks.getStockCount.mockResolvedValue(count("OPEN", [line("11", "BA-001", null), line("12", "BA-002", 2)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByRole("heading", { name: "Stock count #5" })).toBeInTheDocument();
|
|
expect(screen.getByText("Counting")).toBeInTheDocument();
|
|
expect(screen.getByText(/MYB-W/)).toBeInTheDocument();
|
|
expect(screen.queryByRole("columnheader", { name: /expected/i })).not.toBeInTheDocument();
|
|
expect(screen.getByRole("spinbutton", { name: "Counted BA-002" })).toHaveValue(2);
|
|
});
|
|
|
|
it("saves every line's counted quantity, blanks as null", async () => {
|
|
const user = userEvent.setup();
|
|
const open = count("OPEN", [line("11", "BA-001", null), line("12", "BA-002", 2)]);
|
|
mocks.getStockCount.mockResolvedValue(open);
|
|
mocks.saveStockCountEntries.mockResolvedValue(open);
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.type(await screen.findByRole("spinbutton", { name: "Counted BA-001" }), "4");
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
|
|
expect(mocks.saveStockCountEntries).toHaveBeenCalledWith("5", [
|
|
{ skuVariationId: "11", variationId: "V11", countedQty: 4 },
|
|
{ skuVariationId: "12", variationId: "V12", countedQty: 2 },
|
|
]);
|
|
});
|
|
|
|
it("adds a SKU that was not on the list", async () => {
|
|
const user = userEvent.setup();
|
|
const open = count("OPEN", [line("11", "BA-001", 1)]);
|
|
mocks.getStockCount.mockResolvedValue(open);
|
|
mocks.saveStockCountEntries.mockResolvedValue(open);
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Add SKU" }));
|
|
await user.type(screen.getByRole("spinbutton", { name: "Counted BA-013" }), "3");
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
|
|
expect(mocks.saveStockCountEntries).toHaveBeenCalledWith("5", [
|
|
{ skuVariationId: "11", variationId: "V11", countedQty: 1 },
|
|
{ skuVariationId: "13", variationId: null, countedQty: 3 },
|
|
]);
|
|
});
|
|
|
|
it("refuses to submit while a line is blank, without calling the server", async () => {
|
|
const user = userEvent.setup();
|
|
mocks.getStockCount.mockResolvedValue(count("OPEN", [line("11", "BA-001", null)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Submit for approval" }));
|
|
|
|
expect(await screen.findByRole("alert")).toHaveTextContent("Enter a counted quantity for every line");
|
|
expect(mocks.saveStockCountEntries).not.toHaveBeenCalled();
|
|
expect(mocks.stockCountAction).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("saves then submits, and shows the variance that comes back", async () => {
|
|
const user = userEvent.setup();
|
|
const open = count("OPEN", [line("11", "BA-001", 3)]);
|
|
mocks.getStockCount.mockResolvedValue(open);
|
|
mocks.saveStockCountEntries.mockResolvedValue(open);
|
|
mocks.stockCountAction.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Submit for approval" }));
|
|
|
|
expect(mocks.saveStockCountEntries).toHaveBeenCalled();
|
|
expect(mocks.stockCountAction).toHaveBeenCalledWith("5", "submit");
|
|
const row = (await screen.findByText("BA-001")).closest("tr")!;
|
|
expect(within(row).getByText("-2")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("StockCountDetail — submitted count", () => {
|
|
it("shows expected, counted and variance, and lets an approver approve", async () => {
|
|
const user = userEvent.setup();
|
|
mocks.getStockCount.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5), line("12", "BA-002", 4, 4)]));
|
|
mocks.stockCountAction.mockResolvedValue(count("APPROVED", [], { adjustmentRef: "AJO2610081", closedBy: "carol" }));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByRole("columnheader", { name: /expected/i })).toBeInTheDocument();
|
|
expect(screen.getByText("1 line differs")).toBeInTheDocument();
|
|
await user.click(screen.getByRole("button", { name: "Approve and post adjustments" }));
|
|
|
|
expect(mocks.stockCountAction).toHaveBeenCalledWith("5", "approve");
|
|
expect(await screen.findByText(/AJO2610081/)).toBeInTheDocument();
|
|
});
|
|
|
|
it("sends a count back for recount", async () => {
|
|
const user = userEvent.setup();
|
|
mocks.getStockCount.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5)]));
|
|
mocks.stockCountAction.mockResolvedValue(count("OPEN", [line("11", "BA-001", 3)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Send back for recount" }));
|
|
|
|
expect(mocks.stockCountAction).toHaveBeenCalledWith("5", "reopen");
|
|
expect(await screen.findByRole("spinbutton", { name: "Counted BA-001" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("hides approve and recount without the approve module", async () => {
|
|
grant("BO_STOCK_COUNT");
|
|
mocks.getStockCount.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await screen.findByText("BA-001");
|
|
expect(screen.queryByRole("button", { name: "Approve and post adjustments" })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "Send back for recount" })).not.toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: "Cancel count" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the server's refusal when the submitter tries to approve", async () => {
|
|
const user = userEvent.setup();
|
|
mocks.getStockCount.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5)]));
|
|
mocks.stockCountAction.mockRejectedValue(new Error("The person who submitted a count cannot approve it"));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Approve and post adjustments" }));
|
|
|
|
expect(await screen.findByRole("alert")).toHaveTextContent("The person who submitted a count cannot approve it");
|
|
});
|
|
});
|
|
|
|
describe("StockCountDetail — final counts", () => {
|
|
it("says nothing was posted for an approved count with no variance", async () => {
|
|
mocks.getStockCount.mockResolvedValue(count("APPROVED", [line("11", "BA-001", 5, 5)], { closedBy: "carol" }));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByText("No variance — nothing was posted")).toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: /approve|cancel|save/i })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("links an event close-out count back to Events", async () => {
|
|
mocks.getStockCount.mockResolvedValue(count("CANCELLED", [], { eventId: 42 }));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByRole("link", { name: /event close-out/i })).toHaveAttribute("href", "/events");
|
|
});
|
|
|
|
it("shows a load error", async () => {
|
|
mocks.getStockCount.mockRejectedValue(new Error("Stock count not found"));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByRole("alert")).toHaveTextContent("Stock count not found");
|
|
});
|
|
});
|
|
|
|
// After an event count is approved the leftovers are still in the event warehouse. The return
|
|
// warehouse is chosen in the close-out dialog, so the approved count must point there.
|
|
describe("StockCountDetail — event count awaiting stock return", () => {
|
|
const closeOut = (phase: string) => ({
|
|
eventId: 42, phase, countId: 5, windowsOver: true, openReservations: [],
|
|
suggestedReturnWarehouseId: 3, returnWarehouseId: null,
|
|
});
|
|
const LEFTOVER = /leftover stock is still in the event warehouse/i;
|
|
|
|
it("offers to choose the return warehouse and opens close-out for the event", async () => {
|
|
const user = userEvent.setup();
|
|
grant("BO_STOCK_COUNT_APPROVE", "BO_EVENTS");
|
|
mocks.getStockCount.mockResolvedValue(count("APPROVED", [line("11", "BA-001", 5, 5)], { eventId: 42 }));
|
|
mocks.getEventCloseOut.mockResolvedValue(closeOut("READY_TO_CLOSE"));
|
|
events.getEvent.mockResolvedValue({ id: 42, name: "MV EXPO" });
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByText(LEFTOVER)).toBeInTheDocument();
|
|
expect(mocks.getEventCloseOut).toHaveBeenCalledWith("42");
|
|
|
|
await user.click(screen.getByRole("button", { name: "Choose return warehouse" }));
|
|
expect(await screen.findByRole("dialog", { name: "Close out" })).toHaveTextContent("Close out MV EXPO");
|
|
expect(events.getEvent).toHaveBeenCalledWith("42");
|
|
|
|
await user.click(screen.getByRole("button", { name: "Return stock and close event" }));
|
|
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
expect(screen.queryByText(LEFTOVER)).not.toBeInTheDocument();
|
|
expect(await screen.findByText(/event closed/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the prompt right after the approver approves the count", async () => {
|
|
const user = userEvent.setup();
|
|
grant("BO_STOCK_COUNT_APPROVE", "BO_EVENTS");
|
|
mocks.getStockCount.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5)], { eventId: 42 }));
|
|
mocks.stockCountAction.mockResolvedValue(count("APPROVED", [line("11", "BA-001", 3, 5)], { eventId: 42, adjustmentRef: "AJO1" }));
|
|
mocks.getEventCloseOut.mockResolvedValue(closeOut("READY_TO_CLOSE"));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Approve and post adjustments" }));
|
|
|
|
expect(await screen.findByText(LEFTOVER)).toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: "Choose return warehouse" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("says nothing more once the event is already closed", async () => {
|
|
grant("BO_EVENTS");
|
|
mocks.getStockCount.mockResolvedValue(count("APPROVED", [line("11", "BA-001", 5, 5)], { eventId: 42 }));
|
|
mocks.getEventCloseOut.mockResolvedValue(closeOut("CLOSED"));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await screen.findByText("No variance — nothing was posted");
|
|
await vi.waitFor(() => expect(mocks.getEventCloseOut).toHaveBeenCalled());
|
|
expect(screen.queryByText(LEFTOVER)).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "Choose return warehouse" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("tells an approver without event access who finishes close-out", async () => {
|
|
grant("BO_STOCK_COUNT_APPROVE");
|
|
mocks.getStockCount.mockResolvedValue(count("APPROVED", [line("11", "BA-001", 5, 5)], { eventId: 42 }));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
expect(await screen.findByText(/an event manager chooses the return warehouse/i)).toBeInTheDocument();
|
|
expect(mocks.getEventCloseOut).not.toHaveBeenCalled();
|
|
expect(screen.queryByRole("button", { name: "Choose return warehouse" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("does not look up close-out for a count that is not an event count", async () => {
|
|
grant("BO_EVENTS");
|
|
mocks.getStockCount.mockResolvedValue(count("APPROVED", [line("11", "BA-001", 5, 5)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await screen.findByText("No variance — nothing was posted");
|
|
expect(mocks.getEventCloseOut).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("StockCountDetail — barcode scan box", () => {
|
|
const opt = (id: number, code: string, variantName = "Ham") => ({
|
|
skuVariationId: id, code, skuId: 1, skuCode: "HAM", skuName: "Hamper", variant: code, variantName,
|
|
});
|
|
const HAM = opt(14, "HAM-004");
|
|
const scanBox = () => screen.getByRole("textbox", { name: "Scan barcode or SKU code" });
|
|
const openCount = (lines: Line[]) => {
|
|
const open = count("OPEN", lines);
|
|
mocks.getStockCount.mockResolvedValue(open);
|
|
mocks.saveStockCountEntries.mockResolvedValue(open);
|
|
};
|
|
|
|
it("has English defaults for the scan messages", () => {
|
|
expect(DEFAULT_MESSAGES.StockCountScanLabel).toBe("Scan barcode or SKU code");
|
|
expect(DEFAULT_MESSAGES.StockCountScanNoMatch).toBe("No SKU matches {code}");
|
|
expect(DEFAULT_MESSAGES.StockCountScanMany).toBe("More than one SKU matches {code}; add it from the list");
|
|
});
|
|
|
|
it("adds 1 per scan to a blank line, clears the box and keeps focus; Save posts the total", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("14", "HAM-004", null)]);
|
|
lookup.findSkuVariationsByCode.mockResolvedValue([HAM]);
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByRole("heading", { name: "Stock count #5" });
|
|
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
|
|
expect(lookup.findSkuVariationsByCode).toHaveBeenCalledWith("HAM-004");
|
|
expect(await screen.findByRole("spinbutton", { name: "Counted HAM-004" })).toHaveValue(3);
|
|
expect(scanBox()).toHaveValue("");
|
|
expect(scanBox()).toHaveFocus();
|
|
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
expect(mocks.saveStockCountEntries).toHaveBeenCalledWith("5", [{ skuVariationId: "14", variationId: "V14", countedQty: 3 }]);
|
|
});
|
|
|
|
it("adds one to a typed quantity", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("14", "HAM-004", null)]);
|
|
lookup.findSkuVariationsByCode.mockResolvedValue([HAM]);
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await user.type(await screen.findByRole("spinbutton", { name: "Counted HAM-004" }), "10");
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
|
|
expect(await screen.findByDisplayValue("11")).toBeInTheDocument();
|
|
});
|
|
|
|
it("adds a line for a SKU not on the count with quantity 1", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("11", "BA-001", 1)]);
|
|
lookup.findSkuVariationsByCode.mockResolvedValue([opt(3, "TEST-003-BLUE", "Blue")]);
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByText("BA-001");
|
|
|
|
await user.type(scanBox(), "TEST-003-BLUE-BLUE{Enter}");
|
|
|
|
expect(lookup.findSkuVariationsByCode).toHaveBeenCalledWith("TEST-003-BLUE-BLUE");
|
|
expect(await screen.findByRole("spinbutton", { name: "Counted TEST-003-BLUE" })).toHaveValue(1);
|
|
expect(screen.getByText("Blue")).toBeInTheDocument();
|
|
});
|
|
|
|
const deferredLookups = () => {
|
|
const resolvers: Array<(v: unknown[]) => void> = [];
|
|
lookup.findSkuVariationsByCode.mockImplementation(
|
|
() => new Promise<unknown[]>(res => { resolvers.push(res); }),
|
|
);
|
|
return resolvers;
|
|
};
|
|
|
|
it("overlapping scans of a new SKU add one row with the summed quantity", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("11", "BA-001", 1)]);
|
|
const resolvers = deferredLookups();
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByText("BA-001");
|
|
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
expect(resolvers).toHaveLength(2);
|
|
await act(async () => { resolvers.forEach(r => r([HAM])); });
|
|
|
|
expect(await screen.findAllByRole("spinbutton", { name: "Counted HAM-004" })).toHaveLength(1);
|
|
expect(screen.getByRole("spinbutton", { name: "Counted HAM-004" })).toHaveValue(2);
|
|
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
const entries = mocks.saveStockCountEntries.mock.calls[0][1] as Array<{ skuVariationId: string; countedQty: number }>;
|
|
expect(entries.filter(e => e.skuVariationId === "14")).toEqual([{ skuVariationId: "14", variationId: null, countedQty: 2 }]);
|
|
});
|
|
|
|
it("overlapping scans of an existing blank line add up to 2 on one row", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("14", "HAM-004", null)]);
|
|
const resolvers = deferredLookups();
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByText("HAM-004");
|
|
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
await user.type(scanBox(), "HAM-004{Enter}");
|
|
expect(resolvers).toHaveLength(2);
|
|
await act(async () => { resolvers.forEach(r => r([HAM])); });
|
|
|
|
expect(await screen.findByRole("spinbutton", { name: "Counted HAM-004" })).toHaveValue(2);
|
|
expect(screen.getAllByRole("spinbutton")).toHaveLength(1);
|
|
});
|
|
|
|
it("reports no match and changes nothing", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("11", "BA-001", 2)]);
|
|
lookup.findSkuVariationsByCode.mockResolvedValue([]);
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByText("BA-001");
|
|
|
|
await user.type(scanBox(), "NOPE-1{Enter}");
|
|
|
|
expect(await screen.findByText("No SKU matches NOPE-1")).toBeInTheDocument();
|
|
expect(screen.getAllByRole("spinbutton")).toHaveLength(1);
|
|
expect(screen.getByRole("spinbutton", { name: "Counted BA-001" })).toHaveValue(2);
|
|
});
|
|
|
|
it("reports an ambiguous code and changes nothing", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("14", "HAM-004", 2)]);
|
|
lookup.findSkuVariationsByCode.mockResolvedValue([HAM, opt(15, "HAM-005")]);
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByText("HAM-004");
|
|
|
|
await user.type(scanBox(), "X{Enter}");
|
|
|
|
expect(await screen.findByText("More than one SKU matches X; add it from the list")).toBeInTheDocument();
|
|
expect(screen.getAllByRole("spinbutton")).toHaveLength(1);
|
|
expect(screen.getByRole("spinbutton", { name: "Counted HAM-004" })).toHaveValue(2);
|
|
});
|
|
|
|
it("ignores a blank scan", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("14", "HAM-004", 2)]);
|
|
render(<StockCountDetail id="5" />);
|
|
await screen.findByText("HAM-004");
|
|
|
|
await user.type(scanBox(), " {Enter}");
|
|
|
|
expect(lookup.findSkuVariationsByCode).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("routes a scan typed while a button has focus to the scan box, without pressing it", async () => {
|
|
const user = userEvent.setup();
|
|
openCount([line("14", "HAM-004", null)]);
|
|
lookup.findSkuVariationsByCode.mockResolvedValue([HAM]);
|
|
render(<StockCountDetail id="5" />);
|
|
const saveButton = await screen.findByRole("button", { name: "Save" });
|
|
|
|
saveButton.focus();
|
|
await user.keyboard("HAM-004{Enter}");
|
|
|
|
expect(lookup.findSkuVariationsByCode).toHaveBeenCalledWith("HAM-004");
|
|
expect(await screen.findByRole("spinbutton", { name: "Counted HAM-004" })).toHaveValue(1);
|
|
expect(mocks.saveStockCountEntries).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("is not shown on a submitted count", async () => {
|
|
mocks.getStockCount.mockResolvedValue(count("SUBMITTED", [line("11", "BA-001", 3, 5)]));
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await screen.findByText("BA-001");
|
|
expect(screen.queryByRole("textbox", { name: "Scan barcode or SKU code" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("is not shown without the count module", async () => {
|
|
grant("BO_STOCK_COUNT_APPROVE");
|
|
openCount([line("11", "BA-001", 3)]);
|
|
render(<StockCountDetail id="5" />);
|
|
|
|
await screen.findByText("BA-001");
|
|
expect(screen.queryByRole("textbox", { name: "Scan barcode or SKU code" })).not.toBeInTheDocument();
|
|
});
|
|
});
|