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
85 lines
3.8 KiB
TypeScript
85 lines
3.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, within, fireEvent } from "@testing-library/react";
|
|
|
|
// BABYBOO-54 task 1.1: the rate cards list sorts in the browser; the Open column does not sort.
|
|
|
|
const ship = vi.hoisted(() => ({ listRateCards: vi.fn(), saveRateCard: vi.fn(), listZones: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminShipping", () => ship);
|
|
const xl = vi.hoisted(() => ({ toXlsx: vi.fn(), downloadXlsx: vi.fn() }));
|
|
vi.mock("@/app/lib/xlsx", () => xl);
|
|
vi.mock("./RateCardEditor", () => ({ RateCardEditor: ({ cardId }: { cardId: number }) => <p>{`editor ${cardId}`}</p> }));
|
|
|
|
import { RateCardsTab } from "./RateCardsTab";
|
|
|
|
// API order is deliberately sorted by none of the columns. Dates differ lexically vs chronologically
|
|
// only through other columns, so Effective from is asserted via Name.
|
|
const CARDS = [
|
|
{ id: 1, name: "Beta", effectiveFrom: "2026-10-05T00:00:00", status: "DRAFT", warehouseId: null, freeShippingThreshold: 200 },
|
|
{ id: 2, name: "Gamma", effectiveFrom: "2026-11-02T00:00:00", status: "ACTIVE", warehouseId: null, freeShippingThreshold: 100 },
|
|
{ id: 3, name: "Alpha", effectiveFrom: "2026-09-20T00:00:00", status: "DRAFT", warehouseId: null, freeShippingThreshold: 300 },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
ship.listRateCards.mockReset().mockResolvedValue(CARDS);
|
|
ship.listZones.mockReset().mockResolvedValue([]);
|
|
ship.saveRateCard.mockReset().mockResolvedValue({});
|
|
xl.toXlsx.mockReset().mockResolvedValue(new Uint8Array([1]));
|
|
xl.downloadXlsx.mockReset();
|
|
});
|
|
|
|
async function table() {
|
|
render(<RateCardsTab />);
|
|
await screen.findByText("Beta");
|
|
return within(screen.getByRole("table"));
|
|
}
|
|
function column(t: ReturnType<typeof within>, header: string) {
|
|
const idx = t.getAllByRole("columnheader").findIndex((h: HTMLElement) => h.textContent?.trim() === header);
|
|
return t.getAllByRole("row").slice(1).map((r: HTMLElement) => within(r).getAllByRole("cell")[idx].textContent);
|
|
}
|
|
const click = (t: ReturnType<typeof within>, header: string) => fireEvent.click(t.getByRole("button", { name: header }));
|
|
|
|
describe("RateCardsTab - client-side header sorting", () => {
|
|
it("Name header reorders asc then desc", async () => {
|
|
const t = await table();
|
|
expect(column(t, "Name")).toEqual(["Beta", "Gamma", "Alpha"]);
|
|
click(t, "Name");
|
|
expect(column(t, "Name")).toEqual(["Alpha", "Beta", "Gamma"]);
|
|
expect(t.getByRole("columnheader", { name: "Name" })).toHaveAttribute("aria-sort", "ascending");
|
|
click(t, "Name");
|
|
expect(column(t, "Name")).toEqual(["Gamma", "Beta", "Alpha"]);
|
|
expect(t.getByRole("columnheader", { name: "Name" })).toHaveAttribute("aria-sort", "descending");
|
|
});
|
|
|
|
it("Effective from header orders chronologically", async () => {
|
|
const t = await table();
|
|
click(t, "Effective from");
|
|
expect(column(t, "Name")).toEqual(["Alpha", "Beta", "Gamma"]);
|
|
click(t, "Effective from");
|
|
expect(column(t, "Name")).toEqual(["Gamma", "Beta", "Alpha"]);
|
|
});
|
|
|
|
it("Status header groups ACTIVE before DRAFT, then reverses", async () => {
|
|
const t = await table();
|
|
click(t, "Status");
|
|
expect(column(t, "Status")).toEqual(["ACTIVE", "DRAFT", "DRAFT"]);
|
|
click(t, "Status");
|
|
expect(column(t, "Status")).toEqual(["DRAFT", "DRAFT", "ACTIVE"]);
|
|
});
|
|
|
|
it("Free over (RM) header orders by amount", async () => {
|
|
const t = await table();
|
|
click(t, "Free over (RM)");
|
|
expect(column(t, "Name")).toEqual(["Gamma", "Beta", "Alpha"]);
|
|
click(t, "Free over (RM)");
|
|
expect(column(t, "Name")).toEqual(["Alpha", "Beta", "Gamma"]);
|
|
});
|
|
|
|
it("Open column has no sort button; sorting makes no new request", async () => {
|
|
const t = await table();
|
|
const heads = t.getAllByRole("columnheader");
|
|
expect(within(heads[heads.length - 1]).queryByRole("button")).toBeNull();
|
|
click(t, "Name");
|
|
expect(ship.listRateCards).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|