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
88 lines
3.3 KiB
TypeScript
88 lines
3.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, within, fireEvent } from "@testing-library/react";
|
|
|
|
// BABYBOO-54 task 1.9: the Amounts tab is an unpaged list, so every data header sorts in the browser.
|
|
|
|
const svc = vi.hoisted(() => ({
|
|
listGiftCardAmounts: vi.fn(),
|
|
addGiftCardAmount: vi.fn(),
|
|
updateGiftCardAmount: vi.fn(),
|
|
}));
|
|
vi.mock("@/app/lib/services/adminGiftCards", async importActual => ({
|
|
...(await importActual<typeof import("@/app/lib/services/adminGiftCards")>()),
|
|
...svc,
|
|
}));
|
|
|
|
import { AmountsPanel } from "./AmountsPanel";
|
|
|
|
// API order is deliberately sorted by none of amount, status or order.
|
|
const ROWS = [
|
|
{ id: 1, amount: 100, active: "N", sortOrder: 2 },
|
|
{ id: 2, amount: 20, active: "Y", sortOrder: 3 },
|
|
{ id: 3, amount: 50, active: "Y", sortOrder: 1 },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
svc.listGiftCardAmounts.mockReset().mockResolvedValue(ROWS);
|
|
});
|
|
|
|
async function table() {
|
|
await screen.findByText("RM 100.00");
|
|
return within(screen.getByRole("table"));
|
|
}
|
|
/** Amounts in on-screen order, read from the Amount column. */
|
|
function amounts(t: ReturnType<typeof within>) {
|
|
return t.getAllByRole("row").slice(1).map((r: HTMLElement) => within(r).getAllByRole("cell")[0].textContent);
|
|
}
|
|
|
|
describe("Gift card Amounts tab - client-side header sorting", () => {
|
|
it("Amount header reorders asc then desc", async () => {
|
|
render(<AmountsPanel />);
|
|
const t = await table();
|
|
expect(amounts(t)).toEqual(["RM 100.00", "RM 20.00", "RM 50.00"]);
|
|
|
|
fireEvent.click(t.getByRole("button", { name: "Amount" }));
|
|
expect(amounts(t)).toEqual(["RM 20.00", "RM 50.00", "RM 100.00"]);
|
|
expect(t.getByRole("columnheader", { name: "Amount" })).toHaveAttribute("aria-sort", "ascending");
|
|
|
|
fireEvent.click(t.getByRole("button", { name: "Amount" }));
|
|
expect(amounts(t)).toEqual(["RM 100.00", "RM 50.00", "RM 20.00"]);
|
|
});
|
|
|
|
it("Status header groups rows by active flag", async () => {
|
|
render(<AmountsPanel />);
|
|
const t = await table();
|
|
|
|
fireEvent.click(t.getByRole("button", { name: "Status" }));
|
|
const first = amounts(t);
|
|
fireEvent.click(t.getByRole("button", { name: "Status" }));
|
|
const second = amounts(t);
|
|
|
|
// Off-sale (RM 100) sits at one end ascending and the other end descending.
|
|
expect(first[0]).not.toEqual(second[0]);
|
|
expect([first[0], first[2]]).toContain("RM 100.00");
|
|
expect([second[0], second[2]]).toContain("RM 100.00");
|
|
expect(t.getByRole("columnheader", { name: "Status" })).toHaveAttribute("aria-sort", "descending");
|
|
});
|
|
|
|
it("Order header sorts by the stored sortOrder", async () => {
|
|
render(<AmountsPanel />);
|
|
const t = await table();
|
|
|
|
fireEvent.click(t.getByRole("button", { name: "Order" }));
|
|
expect(amounts(t)).toEqual(["RM 50.00", "RM 100.00", "RM 20.00"]);
|
|
|
|
fireEvent.click(t.getByRole("button", { name: "Order" }));
|
|
expect(amounts(t)).toEqual(["RM 20.00", "RM 100.00", "RM 50.00"]);
|
|
});
|
|
|
|
it("sorting makes no new request, and the action column offers no sort", async () => {
|
|
render(<AmountsPanel />);
|
|
const t = await table();
|
|
fireEvent.click(t.getByRole("button", { name: "Amount" }));
|
|
expect(svc.listGiftCardAmounts).toHaveBeenCalledTimes(1);
|
|
const heads = t.getAllByRole("columnheader");
|
|
expect(within(heads[heads.length - 1]).queryByRole("button")).toBeNull();
|
|
});
|
|
});
|