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
594 lines
24 KiB
TypeScript
594 lines
24 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import { render, screen, waitFor, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import type { MovementHistoryPage as MovementHistoryPageData } from "@/app/lib/types";
|
|
import { memoryRouter } from "@/test/memoryRouter";
|
|
|
|
vi.mock("next/navigation", async () => (await import("@/test/memoryRouter")).navigationMock);
|
|
|
|
// ─── mock adminStock service ──────────────────────────────────────────────────
|
|
|
|
const svc = vi.hoisted(() => ({
|
|
getMovements: vi.fn(),
|
|
getSkuCatalog: vi.fn(),
|
|
}));
|
|
vi.mock("@/app/lib/services/adminStock", () => ({
|
|
getMovements: (params: unknown) => svc.getMovements(params),
|
|
getSkuCatalog: () => svc.getSkuCatalog(),
|
|
}));
|
|
|
|
// ─── mock adminWarehouses service ─────────────────────────────────────────────
|
|
|
|
const warehouseSvc = vi.hoisted(() => ({
|
|
listAdminWarehouses: vi.fn(),
|
|
}));
|
|
vi.mock("@/app/lib/services/adminWarehouses", () => ({
|
|
listAdminWarehouses: warehouseSvc.listAdminWarehouses,
|
|
}));
|
|
|
|
// ─── mock xlsx utilities ──────────────────────────────────────────────────────
|
|
|
|
const xlsxMocks = vi.hoisted(() => ({
|
|
toXlsx: vi.fn(),
|
|
downloadXlsx: vi.fn(),
|
|
}));
|
|
vi.mock("@/app/lib/xlsx", () => ({
|
|
toXlsx: xlsxMocks.toXlsx,
|
|
downloadXlsx: xlsxMocks.downloadXlsx,
|
|
}));
|
|
const XLSX_BYTES = new Uint8Array([1, 2, 3]);
|
|
|
|
import { MovementHistoryReport } from "./MovementHistoryReport";
|
|
|
|
// ─── fixture data ─────────────────────────────────────────────────────────────
|
|
|
|
const WAREHOUSES = [
|
|
{ id: 11, code: "MYB-M", name: "MYB-Master store", type: "M", parentId: null, status: "Y" },
|
|
{ id: 10, code: "MYB-W", name: "MYB-HQ", type: "W", parentId: null, status: "Y" },
|
|
];
|
|
|
|
const SKU_CATALOG = [
|
|
{ skuVariationId: "SV-001", skuCode: "BB-001", skuName: "Baby Milk", variation: "100g" },
|
|
{ skuVariationId: "SV-002", skuCode: "BB-002", skuName: "Baby Lotion", variation: "50ml" },
|
|
];
|
|
|
|
const ONE_ROW_PAGE: MovementHistoryPageData = {
|
|
content: [
|
|
{
|
|
id: "100001",
|
|
warehouseId: "11",
|
|
skuVariationId: "SV-001",
|
|
trxnType: "STOCK_IN",
|
|
quantityIn: 50,
|
|
quantityOut: 0,
|
|
trxnDate: "2026-09-01",
|
|
trxnTime: "10:00:00",
|
|
batchNumber: "B001",
|
|
expiryDate: "2027-12-31",
|
|
remark: "Initial stock",
|
|
refNo: "SI-0001",
|
|
},
|
|
],
|
|
number: 0,
|
|
size: 20,
|
|
totalElements: 1,
|
|
totalPages: 1,
|
|
};
|
|
|
|
const TWO_PAGE_RESULT: MovementHistoryPageData = {
|
|
content: [
|
|
{
|
|
id: "100002",
|
|
warehouseId: "10",
|
|
skuVariationId: "SV-002",
|
|
trxnType: "TRANSFER_OUT",
|
|
quantityIn: 0,
|
|
quantityOut: 20,
|
|
trxnDate: "2026-09-02",
|
|
trxnTime: "12:00:00",
|
|
refNo: "TRF-0001",
|
|
},
|
|
],
|
|
number: 0,
|
|
size: 20,
|
|
totalElements: 25,
|
|
totalPages: 2,
|
|
};
|
|
|
|
function renderPage() {
|
|
return render(<MovementHistoryReport reloadKey={0} />);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
memoryRouter.reset("/inventory");
|
|
svc.getMovements.mockReset();
|
|
svc.getMovements.mockResolvedValue(ONE_ROW_PAGE);
|
|
svc.getSkuCatalog.mockReset();
|
|
svc.getSkuCatalog.mockResolvedValue(SKU_CATALOG);
|
|
warehouseSvc.listAdminWarehouses.mockReset();
|
|
warehouseSvc.listAdminWarehouses.mockResolvedValue(WAREHOUSES);
|
|
xlsxMocks.toXlsx.mockReset();
|
|
xlsxMocks.downloadXlsx.mockReset();
|
|
xlsxMocks.toXlsx.mockResolvedValue(XLSX_BYTES);
|
|
});
|
|
|
|
// ─── data rendering ───────────────────────────────────────────────────────────
|
|
|
|
describe("movement history table — data rendering", () => {
|
|
it("shows the transaction type by name, not its code", async () => {
|
|
svc.getMovements.mockResolvedValue({
|
|
...ONE_ROW_PAGE,
|
|
content: [{ ...ONE_ROW_PAGE.content[0], trxnType: "SO" }],
|
|
});
|
|
renderPage();
|
|
|
|
expect(await screen.findByText("Sales out")).toBeInTheDocument();
|
|
expect(screen.queryByText("SO")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("renders all expected columns for a row (date, warehouse, sku, type, in, out, batch, ref, remark)", async () => {
|
|
renderPage();
|
|
|
|
// trxnDate
|
|
expect(await screen.findByText("1 Sep 2026")).toBeInTheDocument();
|
|
// trxnType
|
|
expect(screen.getByText("STOCK_IN")).toBeInTheDocument();
|
|
// quantityIn
|
|
expect(screen.getByText("50")).toBeInTheDocument();
|
|
// batchNumber
|
|
expect(screen.getByText("B001")).toBeInTheDocument();
|
|
// refNo
|
|
expect(screen.getByText("SI-0001")).toBeInTheDocument();
|
|
// remark
|
|
expect(screen.getByText("Initial stock")).toBeInTheDocument();
|
|
// SKU column: resolves skuVariationId "SV-001" → "BB-001 — Baby Milk (100g)" (code — name
|
|
// (variation), not raw id; the variation suffix is fix-stock-report-paging-and-sku-labels)
|
|
// BABYBOO-54: name (+ variation) on the first line, code on a muted second line.
|
|
expect(screen.getByText(/^Baby Milk.*100g/)).toBeInTheDocument();
|
|
expect(screen.queryByText("BB-001 — Baby Milk (100g)")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("SV-001")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the warehouse name with the code on a second muted line (BABYBOO-54)", async () => {
|
|
renderPage();
|
|
|
|
const name = await screen.findByText("MYB-Master store");
|
|
expect(screen.queryByText("MYB-M — MYB-Master store")).not.toBeInTheDocument();
|
|
const cell = name.closest("td")!;
|
|
const code = within(cell).getByText("MYB-M");
|
|
expect(code).toHaveClass("text-muted-foreground");
|
|
expect(code).not.toBe(name);
|
|
});
|
|
|
|
it("shows the SKU code on a second muted line under the name and variation (BABYBOO-54)", async () => {
|
|
renderPage();
|
|
|
|
const name = await screen.findByText(/^Baby Milk.*100g/);
|
|
const code = within(name.closest("td")!).getByText("BB-001");
|
|
expect(code).toHaveClass("text-muted-foreground");
|
|
expect(code).not.toBe(name);
|
|
});
|
|
|
|
it("shows empty state when content is empty", async () => {
|
|
svc.getMovements.mockResolvedValue({
|
|
content: [],
|
|
number: 0,
|
|
size: 20,
|
|
totalElements: 0,
|
|
totalPages: 0,
|
|
});
|
|
renderPage();
|
|
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenCalled());
|
|
expect(await screen.findByText(/no movement/i)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// ─── filter controls ──────────────────────────────────────────────────────────
|
|
|
|
describe("filter controls", () => {
|
|
it("calls getMovements with warehouseId when a warehouse is selected", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
const warehouseFilter = await screen.findByRole("combobox", { name: /warehouse filter/i });
|
|
await user.click(warehouseFilter);
|
|
await user.click(await screen.findByRole("option", { name: /MYB-HQ/i }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { warehouseId?: string };
|
|
expect(lastCall.warehouseId).toBe("10");
|
|
});
|
|
});
|
|
|
|
it("calls getMovements without warehouseId when All warehouses selected", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
const warehouseFilter = await screen.findByRole("combobox", { name: /warehouse filter/i });
|
|
await user.click(warehouseFilter);
|
|
await user.click(await screen.findByRole("option", { name: /MYB-HQ/i }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { warehouseId?: string };
|
|
expect(lastCall.warehouseId).toBe("10");
|
|
});
|
|
|
|
await user.click(warehouseFilter);
|
|
await user.click(await screen.findByRole("option", { name: /all warehouses/i }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { warehouseId?: string };
|
|
expect(lastCall.warehouseId).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// The trxnType filter is a <Select> of known enum codes so an invalid code is impossible.
|
|
// Selecting "Transfer" must forward trxnType=TRF (the enum code), not "Transfer" or "STOCK_IN".
|
|
it("forwards the exact enum code (e.g. TRF) when a transaction type is selected", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
// Wait for the page to load.
|
|
await screen.findByText("1 Sep 2026");
|
|
|
|
const typeFilter = screen.getByRole("combobox", { name: /transaction type filter/i });
|
|
await user.click(typeFilter);
|
|
await user.click(await screen.findByRole("option", { name: /^Transfer/i }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { trxnType?: string };
|
|
expect(lastCall.trxnType).toBe("TRF");
|
|
});
|
|
});
|
|
|
|
it("clears trxnType when All types is selected", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
await screen.findByText("1 Sep 2026");
|
|
|
|
// Select a type first.
|
|
const typeFilter = screen.getByRole("combobox", { name: /transaction type filter/i });
|
|
await user.click(typeFilter);
|
|
await user.click(await screen.findByRole("option", { name: /^Stock in/i }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { trxnType?: string };
|
|
expect(lastCall.trxnType).toBe("STI");
|
|
});
|
|
|
|
// Now clear it.
|
|
await user.click(typeFilter);
|
|
await user.click(await screen.findByRole("option", { name: /all types/i }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { trxnType?: string };
|
|
expect(lastCall.trxnType).toBeUndefined();
|
|
});
|
|
});
|
|
});
|
|
|
|
// ─── pagination ───────────────────────────────────────────────────────────────
|
|
|
|
describe("pagination", () => {
|
|
// fit-admin-listing-pages: the shared pager is the only "Page x of y" on screen.
|
|
it("shows the page count once, in the shared pager", async () => {
|
|
svc.getMovements.mockResolvedValue(TWO_PAGE_RESULT);
|
|
renderPage();
|
|
await screen.findByText("TRANSFER_OUT");
|
|
expect(document.body.textContent!.match(/Page\s*1\s*of\s*2/g)).toHaveLength(1);
|
|
});
|
|
|
|
it("shows Next button enabled when totalPages > 1", async () => {
|
|
svc.getMovements.mockResolvedValue(TWO_PAGE_RESULT);
|
|
renderPage();
|
|
|
|
await screen.findByText("TRANSFER_OUT");
|
|
const nextBtn = screen.getByRole("button", { name: /next/i });
|
|
expect(nextBtn).not.toBeDisabled();
|
|
});
|
|
|
|
it("fetches page 2 when Next is clicked", async () => {
|
|
const user = userEvent.setup();
|
|
svc.getMovements.mockResolvedValue(TWO_PAGE_RESULT);
|
|
renderPage();
|
|
|
|
await screen.findByText("TRANSFER_OUT");
|
|
|
|
const nextBtn = screen.getByRole("button", { name: /next/i });
|
|
await user.click(nextBtn);
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
const lastCall = calls[calls.length - 1][0] as { page?: number };
|
|
expect(lastCall.page).toBe(1);
|
|
});
|
|
});
|
|
});
|
|
|
|
// ─── Excel export ─────────────────────────────────────────────────────────────
|
|
|
|
describe("Excel export", () => {
|
|
it("calls getMovements, toXlsx, and downloadXlsx when Export .xlsx is clicked", async () => {
|
|
const user = userEvent.setup();
|
|
svc.getMovements.mockResolvedValue(ONE_ROW_PAGE);
|
|
renderPage();
|
|
|
|
await screen.findByText("1 Sep 2026");
|
|
|
|
const exportBtn = screen.getByRole("button", { name: /export \.xlsx/i });
|
|
await user.click(exportBtn);
|
|
|
|
await waitFor(() => expect(xlsxMocks.downloadXlsx).toHaveBeenCalledOnce());
|
|
expect(xlsxMocks.toXlsx).toHaveBeenCalledOnce();
|
|
expect(xlsxMocks.downloadXlsx).toHaveBeenCalledWith("movement-history.xlsx", XLSX_BYTES);
|
|
});
|
|
|
|
it("keeps the one-line 'code — name' labels in the export rows (BABYBOO-54)", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
await screen.findByText("1 Sep 2026");
|
|
|
|
await user.click(screen.getByRole("button", { name: /export \.xlsx/i }));
|
|
|
|
await waitFor(() => expect(xlsxMocks.toXlsx).toHaveBeenCalledOnce());
|
|
const rows = xlsxMocks.toXlsx.mock.calls[0][0] as Array<Record<string, unknown>>;
|
|
expect(rows[0].warehouseName).toBe("MYB-M — MYB-Master store");
|
|
expect(rows[0].skuLabel).toBe("BB-001 — Baby Milk (100g)");
|
|
});
|
|
});
|
|
|
|
// ─── Inventory page hooks (merge-inventory-page) ──────────────────────────────
|
|
|
|
describe("inventory page hooks", () => {
|
|
it("refetches when reloadKey changes", async () => {
|
|
const { rerender } = render(<MovementHistoryReport reloadKey={0} />);
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenCalledTimes(1));
|
|
|
|
rerender(<MovementHistoryReport reloadKey={1} />);
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenCalledTimes(2));
|
|
});
|
|
|
|
it("starts filtered to the mv.warehouse URL param", async () => {
|
|
memoryRouter.reset("/inventory", "mv.warehouse=10");
|
|
render(<MovementHistoryReport reloadKey={0} />);
|
|
await waitFor(() =>
|
|
expect(svc.getMovements).toHaveBeenCalledWith(expect.objectContaining({ warehouseId: "10" })),
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── SKU picker (merge-inventory-page) ────────────────────────────────────────
|
|
|
|
async function openSkuPicker(user: ReturnType<typeof userEvent.setup>) {
|
|
const box = await screen.findByRole("combobox", { name: "SKU filter" });
|
|
await user.click(box);
|
|
return box;
|
|
}
|
|
|
|
describe("SKU filter", () => {
|
|
it("filters by a SKU picked by code and name", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
await openSkuPicker(user);
|
|
await user.click(await screen.findByRole("option", { name: "BB-002 — Baby Lotion (50ml)" }));
|
|
|
|
await waitFor(() =>
|
|
expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ skuVariationId: "SV-002" })),
|
|
);
|
|
});
|
|
|
|
it("typing romp lists only matching SKUs, and picking one sends skuVariationId", async () => {
|
|
const user = userEvent.setup();
|
|
svc.getSkuCatalog.mockResolvedValue([
|
|
...SKU_CATALOG,
|
|
{ skuVariationId: "SV-003", skuCode: "BB-003", skuName: "Baby Romper", variation: null },
|
|
]);
|
|
renderPage();
|
|
|
|
const box = await openSkuPicker(user);
|
|
await user.type(box, "romp");
|
|
|
|
expect(await screen.findByRole("option", { name: "BB-003 — Baby Romper" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("option", { name: /Baby Milk/ })).not.toBeInTheDocument();
|
|
await user.click(screen.getByRole("option", { name: "BB-003 — Baby Romper" }));
|
|
|
|
await waitFor(() =>
|
|
expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ skuVariationId: "SV-003" })),
|
|
);
|
|
expect(memoryRouter.getSearch().get("mv.sku")).toBe("SV-003");
|
|
});
|
|
|
|
// fix-stock-on-hand-row-identity: View movements passes the row's own sku variation id, so
|
|
// History filters by it directly instead of resolving a (repeatable) SKU code.
|
|
it("a deep-linked SKU is an active filter: Clear filters shows and returns to all SKUs", async () => {
|
|
const user = userEvent.setup();
|
|
memoryRouter.reset("/inventory", "mv.sku=SV-002");
|
|
render(<MovementHistoryReport reloadKey={0} />);
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Clear filters" }));
|
|
|
|
await waitFor(() =>
|
|
expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ skuVariationId: undefined })),
|
|
);
|
|
expect(memoryRouter.getSearch().toString()).toBe("");
|
|
});
|
|
|
|
it("shows the raw value, not the All SKUs placeholder, while the catalogue loads", async () => {
|
|
memoryRouter.reset("/inventory", "mv.sku=SV-002");
|
|
svc.getSkuCatalog.mockReturnValue(new Promise(() => {}));
|
|
renderPage();
|
|
|
|
expect(await screen.findByRole("combobox", { name: "SKU filter" })).toHaveValue("SV-002");
|
|
});
|
|
|
|
it("starts filtered to the mv.sku URL param on the first load", async () => {
|
|
memoryRouter.reset("/inventory", "mv.sku=SV-002");
|
|
render(<MovementHistoryReport reloadKey={0} />);
|
|
|
|
await waitFor(() =>
|
|
expect(svc.getMovements).toHaveBeenCalledWith(expect.objectContaining({ skuVariationId: "SV-002" })),
|
|
);
|
|
expect(svc.getMovements).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
|
|
// ─── variation names (fix-stock-report-paging-and-sku-labels) ─────────────────
|
|
|
|
describe("SKU filter names each variation", () => {
|
|
it("lists variations of one SKU as distinct options, and a single-variation SKU without a suffix", async () => {
|
|
const user = userEvent.setup();
|
|
svc.getSkuCatalog.mockResolvedValue([
|
|
{ skuVariationId: "17", skuCode: "BA-002", skuName: "Nursing Bra", variation: "Colour: Black" },
|
|
{ skuVariationId: "18", skuCode: "BA-002", skuName: "Nursing Bra", variation: "Colour: Blue" },
|
|
{ skuVariationId: "11", skuCode: "ZZPOS", skuName: "POS Sku", variation: null },
|
|
]);
|
|
renderPage();
|
|
|
|
await openSkuPicker(user);
|
|
expect(await screen.findByRole("option", { name: "BA-002 — Nursing Bra (Colour: Black)" })).toBeInTheDocument();
|
|
expect(screen.getByRole("option", { name: "BA-002 — Nursing Bra (Colour: Blue)" })).toBeInTheDocument();
|
|
expect(screen.getByRole("option", { name: "ZZPOS — POS Sku" })).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// ─── standard filter bar (standardize-admin-list-filters) ─────────────────────
|
|
|
|
describe("filter bar", () => {
|
|
afterEach(() => vi.useRealTimers());
|
|
|
|
it("a selected type writes the URL and requests page 0", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
await screen.findByText("1 Sep 2026");
|
|
|
|
await user.click(screen.getByRole("combobox", { name: /transaction type filter/i }));
|
|
await user.click(await screen.findByRole("option", { name: "Void delivery order" }));
|
|
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ trxnType: "VDO", page: 0 })));
|
|
expect(memoryRouter.getSearch().get("mv.type")).toBe("VDO");
|
|
});
|
|
|
|
it("the type list offers no Sales return or Stock count, but an old SR row still reads Stock return", async () => {
|
|
const user = userEvent.setup();
|
|
svc.getMovements.mockResolvedValue({ ...ONE_ROW_PAGE, content: [{ ...ONE_ROW_PAGE.content[0], trxnType: "SR" }] });
|
|
renderPage();
|
|
expect(await screen.findByText("Stock return")).toBeInTheDocument();
|
|
|
|
await user.click(screen.getByRole("combobox", { name: /transaction type filter/i }));
|
|
expect(await screen.findByRole("option", { name: "Void delivery order" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("option", { name: /stock count|stock return|sales return/i })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("populates the request from the URL on mount", async () => {
|
|
memoryRouter.reset("/inventory", "mv.type=TRF&mv.warehouse=10&mv.from=2026-09-01&mv.to=2026-09-30");
|
|
renderPage();
|
|
|
|
await waitFor(() =>
|
|
expect(svc.getMovements).toHaveBeenCalledWith(
|
|
expect.objectContaining({ trxnType: "TRF", warehouseId: "10", dateFrom: "2026-09-01", dateTo: "2026-09-30" }),
|
|
),
|
|
);
|
|
});
|
|
|
|
it("Clear filters empties the URL and there is no Apply button", async () => {
|
|
memoryRouter.reset("/inventory", "mv.type=TRF&mv.warehouse=10");
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
await user.click(await screen.findByRole("button", { name: "Clear filters" }));
|
|
|
|
expect(memoryRouter.getSearch().toString()).toBe("");
|
|
expect(screen.queryByRole("button", { name: /apply/i })).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// ─── BABYBOO-54: server-side header sorting ───────────────────────────────────
|
|
// Assumes useTableSort("mv.") so the sort lives in mv.sortBy / mv.sortDir beside the mv.* filters.
|
|
|
|
describe("movement history — header sorting", () => {
|
|
it("clicking Date sends sortBy=trxnDate&sortDir=asc, kept under the mv. prefix", async () => {
|
|
const user = userEvent.setup();
|
|
memoryRouter.reset("/inventory", "mv.page=2");
|
|
renderPage();
|
|
await screen.findByText("1 Sep 2026");
|
|
svc.getMovements.mockClear();
|
|
await user.click(screen.getByRole("columnheader", { name: /Date/ }).querySelector("button")!);
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: "trxnDate", sortDir: "asc" })));
|
|
expect(memoryRouter.getSearch().get("mv.sortBy")).toBe("trxnDate");
|
|
expect(memoryRouter.getSearch().get("mv.sortDir")).toBe("asc");
|
|
expect(memoryRouter.getSearch().has("sortBy")).toBe(false);
|
|
expect(memoryRouter.getSearch().has("mv.page")).toBe(false);
|
|
});
|
|
|
|
it.each([
|
|
[/Warehouse/, "warehouse"],
|
|
[/^Sku/i, "sku"],
|
|
])("clicking the %s header sorts by %s, asc then desc, under the mv. prefix", async (name, key) => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
await screen.findByText("1 Sep 2026");
|
|
const btn = () => screen.getByRole("columnheader", { name }).querySelector("button")!;
|
|
expect(btn()).toBeTruthy();
|
|
svc.getMovements.mockClear();
|
|
await user.click(btn());
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: key, sortDir: "asc" })));
|
|
expect(memoryRouter.getSearch().get("mv.sortBy")).toBe(key);
|
|
await user.click(btn());
|
|
await waitFor(() => expect(svc.getMovements).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: key, sortDir: "desc" })));
|
|
});
|
|
});
|
|
|
|
// ─── BABYBOO-59: closed-event (inactive) warehouses stay findable ─────────────
|
|
|
|
describe("inactive warehouses (closed events)", () => {
|
|
const CLOSED_EVENT = { id: 77, code: "EVT-MV-EXPO-001", name: "BABYBOO MV EXPO 16 - 19 SEP", type: "W", parentId: null, status: "N" };
|
|
const CLOSED_LABEL = "EVT-MV-EXPO-001 — BABYBOO MV EXPO 16 - 19 SEP (inactive)";
|
|
|
|
beforeEach(() => {
|
|
warehouseSvc.listAdminWarehouses.mockResolvedValue([...WAREHOUSES, CLOSED_EVENT]);
|
|
});
|
|
|
|
it("lists the inactive warehouse in the filter, marked inactive; active ones are unmarked", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
await user.click(await screen.findByRole("combobox", { name: /warehouse filter/i }));
|
|
expect(await screen.findByRole("option", { name: CLOSED_LABEL })).toBeInTheDocument();
|
|
expect(screen.getByRole("option", { name: "MYB-W — MYB-HQ" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("requests movements with the inactive warehouse id when chosen", async () => {
|
|
const user = userEvent.setup();
|
|
renderPage();
|
|
|
|
await user.click(await screen.findByRole("combobox", { name: /warehouse filter/i }));
|
|
await user.click(await screen.findByRole("option", { name: CLOSED_LABEL }));
|
|
|
|
await waitFor(() => {
|
|
const calls = svc.getMovements.mock.calls;
|
|
expect((calls[calls.length - 1][0] as { warehouseId?: string }).warehouseId).toBe("77");
|
|
});
|
|
});
|
|
|
|
it("labels a row from an inactive warehouse by name and code, not the raw id", async () => {
|
|
svc.getMovements.mockResolvedValue({
|
|
...ONE_ROW_PAGE,
|
|
content: [{ ...ONE_ROW_PAGE.content[0], warehouseId: "77" }],
|
|
});
|
|
renderPage();
|
|
|
|
const name = await screen.findByText("BABYBOO MV EXPO 16 - 19 SEP");
|
|
expect(within(name.closest("td")!).getByText("EVT-MV-EXPO-001")).toBeInTheDocument();
|
|
expect(screen.queryByText("77")).not.toBeInTheDocument();
|
|
});
|
|
});
|