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
81 lines
3.4 KiB
TypeScript
81 lines
3.4 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 shipping zones list sorts in the browser; the Edit column does not sort.
|
|
|
|
const ship = vi.hoisted(() => ({ listZones: vi.fn(), saveZone: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminShipping", () => ship);
|
|
const api = vi.hoisted(() => ({ apiGet: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", async (orig) => ({ ...(await orig<typeof import("@/app/lib/clientApi")>()), apiGet: api.apiGet }));
|
|
|
|
import { ZonesTab } from "./ZonesTab";
|
|
|
|
// API order is deliberately sorted by none of the columns.
|
|
const ZONES = [
|
|
{ id: 1, code: "WM", name: "West Malaysia", status: "Y", geoLocationIds: [1, 2] },
|
|
{ id: 2, code: "EM", name: "East Malaysia", status: "N", geoLocationIds: [1] },
|
|
{ id: 3, code: "SG", name: "Singapore", status: "Y", geoLocationIds: [1, 2, 3] },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
ship.listZones.mockReset().mockResolvedValue(ZONES);
|
|
ship.saveZone.mockReset().mockResolvedValue({});
|
|
api.apiGet.mockReset().mockResolvedValue([]);
|
|
});
|
|
|
|
async function table() {
|
|
render(<ZonesTab />);
|
|
await screen.findByText("WM");
|
|
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("ZonesTab - client-side header sorting", () => {
|
|
it("Code header reorders asc then desc", async () => {
|
|
const t = await table();
|
|
expect(column(t, "Code")).toEqual(["WM", "EM", "SG"]);
|
|
click(t, "Code");
|
|
expect(column(t, "Code")).toEqual(["EM", "SG", "WM"]);
|
|
expect(t.getByRole("columnheader", { name: "Code" })).toHaveAttribute("aria-sort", "ascending");
|
|
click(t, "Code");
|
|
expect(column(t, "Code")).toEqual(["WM", "SG", "EM"]);
|
|
expect(t.getByRole("columnheader", { name: "Code" })).toHaveAttribute("aria-sort", "descending");
|
|
});
|
|
|
|
it("Name header reorders asc then desc", async () => {
|
|
const t = await table();
|
|
click(t, "Name");
|
|
expect(column(t, "Name")).toEqual(["East Malaysia", "Singapore", "West Malaysia"]);
|
|
click(t, "Name");
|
|
expect(column(t, "Name")).toEqual(["West Malaysia", "Singapore", "East Malaysia"]);
|
|
});
|
|
|
|
it("Status header orders by label, Active first asc then Inactive first desc", async () => {
|
|
const t = await table();
|
|
click(t, "Status");
|
|
expect(column(t, "Status")).toEqual(["Active", "Active", "Inactive"]);
|
|
click(t, "Status");
|
|
expect(column(t, "Status")).toEqual(["Inactive", "Active", "Active"]);
|
|
});
|
|
|
|
it("Regions header orders by region count", async () => {
|
|
const t = await table();
|
|
click(t, "Regions");
|
|
expect(column(t, "Code")).toEqual(["EM", "WM", "SG"]);
|
|
click(t, "Regions");
|
|
expect(column(t, "Code")).toEqual(["SG", "WM", "EM"]);
|
|
});
|
|
|
|
it("Edit 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, "Code");
|
|
expect(ship.listZones).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|