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
454 lines
22 KiB
TypeScript
454 lines
22 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, within, waitFor } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { pickRange } from "@/test/pickDate";
|
|
import type { WebOrderRow, WebOrderPage as WebOrderPageData } from "@/app/lib/types";
|
|
|
|
// ─── mock AdminAuthContext (RequireModule dependency) ─────────────────────────
|
|
// Route /orders/web IS in ROUTE_MODULES (module BO_WEB_ORDERS), so RequireModule gates it.
|
|
|
|
const auth = vi.hoisted(() => ({ hasModule: vi.fn(), loading: false }));
|
|
vi.mock("@/app/lib/AdminAuthContext", () => ({
|
|
useAdminAuth: () => ({ hasModule: auth.hasModule, loading: auth.loading }),
|
|
}));
|
|
|
|
// ─── mock adminWebOrders service (keep the pure helpers real) ─────────────────
|
|
|
|
const svc = vi.hoisted(() => ({ listWebOrders: vi.fn(), downloadInvoice: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminWebOrders", async importActual => {
|
|
const actual = await importActual<typeof import("@/app/lib/services/adminWebOrders")>();
|
|
return {
|
|
...actual,
|
|
listWebOrders: (p: unknown) => svc.listWebOrders(p),
|
|
downloadInvoice: (u: string) => svc.downloadInvoice(u),
|
|
};
|
|
});
|
|
|
|
vi.mock("next/navigation", async () => (await import("@/test/memoryRouter")).navigationMock);
|
|
|
|
import { memoryRouter } from "@/test/memoryRouter";
|
|
import SalesListingPage from "./page";
|
|
|
|
// ─── fixtures ─────────────────────────────────────────────────────────────────
|
|
|
|
function row(overrides: Partial<WebOrderRow> = {}): WebOrderRow {
|
|
return {
|
|
id: "1",
|
|
uuid: "WO-1",
|
|
documentNo: "WEB2609080001",
|
|
transactionDateTime: "2026-09-08T10:00:00",
|
|
buyerCode: "BB0100",
|
|
buyerName: null,
|
|
totalAmount: null,
|
|
shippingCost: null,
|
|
buyerEmail: "buyer@example.com",
|
|
buyerType: "M",
|
|
grandTotal: "150.00",
|
|
currencySymbol: "RM",
|
|
status: "P",
|
|
saleChannel: "NORMAL",
|
|
sourcePlatform: "CP",
|
|
eventId: null,
|
|
fulfilmentMode: "DELIVERY",
|
|
totalDiscount: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function pageOf(rows: WebOrderRow[], extra: Partial<WebOrderPageData> = {}): WebOrderPageData {
|
|
return { content: rows, number: 0, size: 20, totalElements: rows.length, totalPages: 1, ...extra };
|
|
}
|
|
|
|
beforeEach(() => {
|
|
memoryRouter.reset("/orders/web");
|
|
auth.hasModule.mockReset();
|
|
auth.hasModule.mockReturnValue(true);
|
|
auth.loading = false;
|
|
svc.listWebOrders.mockReset();
|
|
svc.listWebOrders.mockResolvedValue(pageOf([row()]));
|
|
svc.downloadInvoice.mockReset();
|
|
svc.downloadInvoice.mockResolvedValue(undefined);
|
|
});
|
|
|
|
// ─── data rendering ───────────────────────────────────────────────────────────
|
|
|
|
describe("sales listing — data rendering", () => {
|
|
it("shows the shared header, formatted date, and labelled badges with an accessible invoice header", async () => {
|
|
render(<SalesListingPage />);
|
|
expect(screen.getByRole("heading", { level: 1, name: "Sales listing" })).toBeInTheDocument();
|
|
expect(await screen.findByText("8 Sep 2026, 10:00")).toBeInTheDocument();
|
|
expect(screen.getByText("Pending")).toHaveClass("text-warning");
|
|
expect(screen.getByText("Delivery")).toBeInTheDocument();
|
|
expect(screen.getByRole("columnheader", { name: "Invoice" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders rows with the order number linking to the detail page", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ id: "2", uuid: "WO-2", documentNo: "WEB2609090002", buyerEmail: "buyer2@example.com", grandTotal: "200.00" }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
|
|
const link = await screen.findByRole("link", { name: "WEB2609090002" });
|
|
expect(link).toHaveAttribute("href", "/orders/web/WO-2");
|
|
expect(screen.getByText("BB0100")).toBeInTheDocument();
|
|
expect(screen.getByText("RM 200.00")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the derived Order Type: Web for NORMAL+CP, Event for EVENT", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ id: "1", uuid: "WO-1", documentNo: "A1", saleChannel: "NORMAL", sourcePlatform: "CP" }),
|
|
row({ id: "2", uuid: "WO-2", documentNo: "A2", saleChannel: "EVENT", sourcePlatform: "BO", eventId: "7001" }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
|
|
expect(await screen.findByText("A1")).toBeInTheDocument();
|
|
expect(screen.getByText("Web")).toBeInTheDocument();
|
|
expect(screen.getByText("Event")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows order status as a full-name label, not the raw code", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ id: "1", uuid: "WO-1", documentNo: "S-P", status: "P" }),
|
|
row({ id: "2", uuid: "WO-2", documentNo: "S-Y", status: "Y" }),
|
|
row({ id: "3", uuid: "WO-3", documentNo: "S-FP", status: "FP" }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
|
|
expect(await screen.findByText("S-FP")).toBeInTheDocument();
|
|
expect(screen.getByText("Pending")).toBeInTheDocument();
|
|
expect(screen.getByText("Active")).toBeInTheDocument();
|
|
expect(screen.getByText("Failed with payment")).toBeInTheDocument();
|
|
// the raw code must not appear in the status column
|
|
expect(screen.queryByText("FP")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("offers the curated order statuses plus the stale-pending option in the status filter", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001"); // wait for the default row to load
|
|
|
|
await user.click(screen.getByRole("combobox", { name: /status filter/i }));
|
|
expect(await screen.findByRole("option", { name: "Failed with payment" })).toBeInTheDocument();
|
|
expect(screen.getByRole("option", { name: "Pending over 60 min" })).toBeInTheDocument();
|
|
expect(screen.getByRole("option", { name: "Active" })).toBeInTheDocument();
|
|
// legacy codes outside the curated list are no longer filter choices
|
|
for (const name of ["Hold", "Failed", "Cancelled", "Inactive", "Unknown"]) {
|
|
expect(screen.queryByRole("option", { name })).not.toBeInTheDocument();
|
|
}
|
|
});
|
|
|
|
it("treats an unknown type in the URL as all types", async () => {
|
|
memoryRouter.reset("/orders/web", "type=BOGUS");
|
|
render(<SalesListingPage />);
|
|
expect(await screen.findByText("WEB2609080001")).toBeInTheDocument();
|
|
expect(svc.listWebOrders).toHaveBeenCalledWith(expect.objectContaining({ saleChannel: undefined }));
|
|
});
|
|
|
|
// fit-admin-listing-pages: Wallet-style member cell — code on top linking to the member, name below;
|
|
// a guest reads Guest with their name, email or code below.
|
|
it("shows the customer as code above name, or Guest above name/email/code", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ id: "1", uuid: "WO-1", documentNo: "C1", buyerName: "IRENE LIM", buyerCode: "MY1647047" }),
|
|
row({ id: "2", uuid: "WO-2", documentNo: "C2", buyerName: null, buyerCode: "MY2222222" }),
|
|
row({ id: "3", uuid: "WO-3", documentNo: "C3", buyerType: "G", buyerName: "E2E0928 Counter Walkin", buyerCode: null }),
|
|
row({ id: "4", uuid: "WO-4", documentNo: "C4", buyerType: "G", buyerName: null, buyerEmail: "guest@example.com", buyerCode: null }),
|
|
row({ id: "5", uuid: "WO-5", documentNo: "C5", buyerType: "G", buyerName: null, buyerEmail: null, buyerCode: null }),
|
|
row({ id: "6", uuid: "WO-6", documentNo: "C6", buyerType: "G", buyerName: null, buyerEmail: null, buyerCode: "MY3333333" }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
const irene = await screen.findByRole("link", { name: "MY1647047" });
|
|
expect(irene).toHaveAttribute("href", "/members/MY1647047");
|
|
expect(within(irene.closest("td")!).getByText("IRENE LIM")).toBeInTheDocument();
|
|
expect(screen.getByRole("link", { name: "MY2222222" })).toBeInTheDocument();
|
|
const cellOf = (doc: string) => screen.getByRole("link", { name: doc }).closest("tr")!.querySelectorAll("td")[2];
|
|
expect(cellOf("C3")).toHaveTextContent("GuestE2E0928 Counter Walkin");
|
|
expect(cellOf("C4")).toHaveTextContent("Guestguest@example.com");
|
|
expect(cellOf("C5")).toHaveTextContent(/^Guest$/);
|
|
expect(cellOf("C6")).toHaveTextContent("GuestMY3333333");
|
|
expect(screen.queryByText(/\(Guest\)|\(MY/)).toBeNull();
|
|
});
|
|
|
|
it("shows Sales Amount, Delivery Charges, Discount and Total Amount in order, formatted", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ currencySymbol: null, totalAmount: "415.0", shippingCost: "0.0", totalDiscount: "45.0", grandTotal: "370.0" }),
|
|
row({ id: "2", uuid: "WO-2", documentNo: "N2", currencySymbol: null, totalAmount: null, shippingCost: null, grandTotal: null }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
const headers = screen.getAllByRole("columnheader").map(h => h.textContent);
|
|
const i = headers.indexOf("Sales Amount");
|
|
expect(headers.slice(i, i + 4)).toEqual(["Sales Amount", "Delivery Charges", "Discount", "Total Amount"]);
|
|
const cells = within(screen.getByRole("link", { name: "WEB2609080001" }).closest("tr")!).getAllByRole("cell").map(c => c.textContent);
|
|
expect(cells.slice(i, i + 4)).toEqual(["415.00", "0.00", "45.00", "370.00"]);
|
|
const empty = within(screen.getByRole("link", { name: "N2" }).closest("tr")!).getAllByRole("cell").map(c => c.textContent);
|
|
expect(empty.slice(i, i + 2)).toEqual(["—", "—"]);
|
|
});
|
|
|
|
it("shows the empty state when there are no orders", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([]));
|
|
render(<SalesListingPage />);
|
|
expect(await screen.findByText(/no orders/i)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// ─── filters ────────────────────────────────────────────────────────────────
|
|
|
|
describe("filters", () => {
|
|
it("sends the order-number filter after the debounce and resets to page 0", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.type(screen.getByRole("searchbox", { name: "Order number" }), "00067");
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(
|
|
expect.objectContaining({ documentNo: "00067", page: 0, size: 20 }),
|
|
),
|
|
);
|
|
expect(memoryRouter.getSearch().get("documentNo")).toBe("00067");
|
|
expect(svc.listWebOrders.mock.calls.filter(c => (c[0] as { documentNo?: string }).documentNo).length).toBe(1);
|
|
});
|
|
|
|
it("sends the member code or name as its own field", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
// BABYBOO-50: one Member box takes a code or a name.
|
|
expect(screen.getByRole("searchbox", { name: "Member" })).toHaveAttribute("placeholder", "Member code or name");
|
|
await user.type(screen.getByRole("searchbox", { name: "Member" }), "MY16");
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ buyerCode: "MY16", page: 0 })),
|
|
);
|
|
});
|
|
|
|
it("sends Fulfilment Pickup and puts it in the URL", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.click(screen.getByRole("combobox", { name: /fulfilment filter/i }));
|
|
await user.click(await screen.findByRole("option", { name: "Pickup" }));
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ fulfilment: "PICKUP", page: 0 })),
|
|
);
|
|
expect(memoryRouter.getSearch().get("fulfilment")).toBe("PICKUP");
|
|
});
|
|
|
|
// BABYBOO-45: a POS sale handed over at the till is "Take now", not Delivery.
|
|
it("offers Take now in the Fulfilment filter and sends TAKE_NOW", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.click(screen.getByRole("combobox", { name: /fulfilment filter/i }));
|
|
expect((await screen.findAllByRole("option")).map(o => o.textContent)).toEqual(["All", "Delivery", "Pickup", "Take now"]);
|
|
await user.click(screen.getByRole("option", { name: "Take now" }));
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ fulfilment: "TAKE_NOW", page: 0 })),
|
|
);
|
|
expect(memoryRouter.getSearch().get("fulfilment")).toBe("TAKE_NOW");
|
|
});
|
|
|
|
it("labels a TAKE_NOW row Take now", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([row({ saleChannel: "OUTLET", fulfilmentMode: "TAKE_NOW" })]));
|
|
render(<SalesListingPage />);
|
|
expect(await screen.findByText("Take now")).toBeInTheDocument();
|
|
});
|
|
|
|
it("populates the controls and the request from the URL on mount", async () => {
|
|
memoryRouter.reset("/orders/web", "status=Y&buyerCode=MY9&fulfilment=DELIVERY");
|
|
render(<SalesListingPage />);
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(
|
|
expect.objectContaining({ status: "Y", buyerCode: "MY9", fulfilment: "DELIVERY" }),
|
|
),
|
|
);
|
|
expect(screen.getByRole("searchbox", { name: "Member" })).toHaveValue("MY9");
|
|
expect(screen.getByRole("combobox", { name: /status filter/i })).toHaveTextContent("Active");
|
|
});
|
|
|
|
it("Clear filters empties the URL", async () => {
|
|
const user = userEvent.setup();
|
|
memoryRouter.reset("/orders/web", "status=Y&buyerCode=MY9");
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.click(screen.getByRole("button", { name: "Clear filters" }));
|
|
|
|
await waitFor(() => expect(memoryRouter.getSearch().toString()).toBe(""));
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ status: undefined, buyerCode: undefined })),
|
|
);
|
|
});
|
|
|
|
it("sends a picked date range as yyyy-MM-dd", async () => {
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
pickRange("Date from", "2026-09-01", "2026-09-30");
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(
|
|
expect.objectContaining({ dateFrom: "2026-09-01", dateTo: "2026-09-30", page: 0 }),
|
|
),
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── pagination ────────────────────────────────────────────────────────────────
|
|
|
|
describe("pagination", () => {
|
|
it("advances to the next page of results when Next is clicked", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([row()], { totalElements: 40, totalPages: 2 }));
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.click(screen.getByRole("button", { name: /next/i }));
|
|
|
|
await waitFor(() =>
|
|
expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ page: 1, size: 20 })),
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── per-row invoice ───────────────────────────────────────────────────────────
|
|
|
|
describe("invoice download", () => {
|
|
it("downloads the invoice for a row when its Invoice button is clicked", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.click(screen.getByRole("button", { name: /invoice/i }));
|
|
|
|
await waitFor(() => expect(svc.downloadInvoice).toHaveBeenCalledWith("WO-1"));
|
|
});
|
|
|
|
it("shows an error when the invoice download fails", async () => {
|
|
svc.downloadInvoice.mockRejectedValue(new Error("Invoice not found."));
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
|
|
await user.click(screen.getByRole("button", { name: /invoice/i }));
|
|
|
|
expect(await screen.findByText(/invoice not found/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows a spinner and marks the Invoice button busy and disabled while the download is in flight", async () => {
|
|
let finish!: () => void;
|
|
svc.downloadInvoice.mockReturnValue(new Promise<void>(res => { finish = res; }));
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
// The table re-creates its cells on every render, so re-query the button each time.
|
|
const invoiceBtn = () => screen.getByRole("button", { name: /invoice/i });
|
|
expect(invoiceBtn().querySelector(".animate-spin")).toBeNull();
|
|
|
|
await user.click(invoiceBtn());
|
|
|
|
await waitFor(() => expect(invoiceBtn()).toBeDisabled());
|
|
expect(invoiceBtn().querySelector(".animate-spin")).not.toBeNull();
|
|
expect(invoiceBtn()).toHaveAttribute("aria-busy", "true");
|
|
|
|
finish();
|
|
await waitFor(() => expect(invoiceBtn()).toBeEnabled());
|
|
expect(invoiceBtn().querySelector(".animate-spin")).toBeNull();
|
|
expect(invoiceBtn()).not.toHaveAttribute("aria-busy", "true");
|
|
});
|
|
});
|
|
|
|
// ─── gating ───────────────────────────────────────────────────────────────────
|
|
|
|
describe("module gating", () => {
|
|
it("does not fetch when the module is not granted", async () => {
|
|
auth.hasModule.mockReturnValue(false);
|
|
render(<SalesListingPage />);
|
|
await waitFor(() => expect(svc.listWebOrders).not.toHaveBeenCalled());
|
|
});
|
|
});
|
|
|
|
|
|
describe("sales listing — promotion discount (add-promotions-campaigns PR 2)", () => {
|
|
it("shows the order discount in its own column, and a dash when there is none", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ id: "5", uuid: "WO-5", documentNo: "IN5", grandTotal: "135.00", totalDiscount: "15.00" }),
|
|
row({ id: "6", uuid: "WO-6", documentNo: "IN6", grandTotal: "90.00", totalDiscount: "0.0" }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
|
|
expect(await screen.findByRole("columnheader", { name: "Discount" })).toBeInTheDocument();
|
|
const discounted = (await screen.findByRole("link", { name: "IN5" })).closest("tr")!;
|
|
expect(within(discounted).getByText("RM 15.00")).toBeInTheDocument();
|
|
const plain = screen.getByRole("link", { name: "IN6" }).closest("tr")!;
|
|
expect(within(plain).getByTestId("order-discount")).toHaveTextContent("—");
|
|
});
|
|
});
|
|
|
|
// unify-admin-listing-toolbar: an unpaid order (pending, failed, voided) has no invoice number yet;
|
|
// mobile-api returns documentNo null for it instead of its uuid placeholder.
|
|
describe("sales listing — orders without an invoice", () => {
|
|
it("labels the order Not invoiced, still links its detail, and offers no Invoice download", async () => {
|
|
svc.listWebOrders.mockResolvedValue(pageOf([
|
|
row({ id: "1", uuid: "3296202417043329024", documentNo: null, status: "V" }),
|
|
row({ id: "2", uuid: "WO-2", documentNo: "IN00000126", status: "Y" }),
|
|
]));
|
|
render(<SalesListingPage />);
|
|
|
|
const link = await screen.findByRole("link", { name: "Not invoiced" });
|
|
expect(link).toHaveAttribute("href", "/orders/web/3296202417043329024");
|
|
expect(screen.queryByText("3296202417043329024")).toBeNull();
|
|
const unpaidRow = link.closest("tr")!;
|
|
expect(within(unpaidRow).queryByRole("button", { name: "Invoice" })).toBeNull();
|
|
const paidRow = screen.getByRole("link", { name: "IN00000126" }).closest("tr")!;
|
|
expect(within(paidRow).getByRole("button", { name: "Invoice" })).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// ─── BABYBOO-54: server-side header sorting ───────────────────────────────────
|
|
|
|
describe("sales listing — header sorting", () => {
|
|
it("clicking Sales Amount sends sortBy=totalAmount&sortDir=asc, then desc", async () => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
svc.listWebOrders.mockClear();
|
|
await user.click(screen.getByRole("button", { name: "Sales Amount" }));
|
|
await waitFor(() => expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: "totalAmount", sortDir: "asc" })));
|
|
expect(memoryRouter.getSearch().get("sortBy")).toBe("totalAmount");
|
|
await user.click(screen.getByRole("button", { name: "Sales Amount" }));
|
|
await waitFor(() => expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: "totalAmount", sortDir: "desc" })));
|
|
});
|
|
|
|
it.each([
|
|
["Customer", "customer"],
|
|
["Type", "type"],
|
|
["Fulfilment", "fulfilmentMode"],
|
|
])("clicking %s sorts server-side by %s, then desc", async (header, key) => {
|
|
const user = userEvent.setup();
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
svc.listWebOrders.mockClear();
|
|
await user.click(within(screen.getByRole("columnheader", { name: new RegExp(`^${header}`) })).getByRole("button"));
|
|
await waitFor(() => expect(svc.listWebOrders).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: key, sortDir: "asc" })));
|
|
expect(memoryRouter.getSearch().get("sortBy")).toBe(key);
|
|
});
|
|
|
|
it("offers a sort on every data column but not on the invoice action column", async () => {
|
|
render(<SalesListingPage />);
|
|
await screen.findByText("WEB2609080001");
|
|
for (const name of [/Date/, /Fulfilment/, /Customer/, /^Type/]) {
|
|
expect(within(screen.getByRole("columnheader", { name })).getByRole("button")).toBeInTheDocument();
|
|
}
|
|
expect(within(screen.getByRole("columnheader", { name: "Invoice" })).queryByRole("button")).not.toBeInTheDocument();
|
|
});
|
|
});
|