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
76 lines
3.4 KiB
TypeScript
76 lines
3.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, within, fireEvent } from "@testing-library/react";
|
|
import type { BankCountry, BankRow } from "@/app/lib/types";
|
|
|
|
// BABYBOO-54 task 1.1: the bank list sorts in the browser; the Actions column does not sort.
|
|
|
|
const svc = vi.hoisted(() => ({ listBankCountries: vi.fn(), listBanks: vi.fn(), createBank: vi.fn(), updateBank: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminBank", () => ({
|
|
listBankCountries: () => svc.listBankCountries(),
|
|
listBanks: (c: string) => svc.listBanks(c),
|
|
createBank: (p: unknown) => svc.createBank(p),
|
|
updateBank: (id: number, p: unknown) => svc.updateBank(id, p),
|
|
}));
|
|
|
|
import { BankPanel } from "./BankPanel";
|
|
|
|
const countries: BankCountry[] = [{ id: 2, code: "MY", name: "Malaysia" }];
|
|
// API order is deliberately sorted by none of the columns.
|
|
const banks: BankRow[] = [
|
|
{ id: 5, code: "MBB", name: "Maybank", swiftCode: "MBBEMYKL", bnmCode: "27", bankid: "MBB0228", messageTag: "bank.MBB" },
|
|
{ id: 6, code: "CIMB", name: "CIMB Bank", swiftCode: "CIBBMYKL", bnmCode: "35", bankid: "CIM0001", messageTag: "bank.CIMB" },
|
|
{ id: 7, code: "HLB", name: "Hong Leong", swiftCode: "HLBBMYKL", bnmCode: "11", bankid: "HLB0099", messageTag: "bank.HLB" },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
Object.values(svc).forEach((f) => f.mockReset());
|
|
svc.listBankCountries.mockResolvedValue(countries);
|
|
svc.listBanks.mockResolvedValue(banks);
|
|
});
|
|
|
|
async function table() {
|
|
render(<BankPanel adding={false} onAddingChange={vi.fn()} />);
|
|
await screen.findByText("Maybank");
|
|
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("BankPanel - client-side header sorting", () => {
|
|
it("Code header reorders asc then desc", async () => {
|
|
const t = await table();
|
|
expect(column(t, "Code")).toEqual(["MBB", "CIMB", "HLB"]);
|
|
click(t, "Code");
|
|
expect(column(t, "Code")).toEqual(["CIMB", "HLB", "MBB"]);
|
|
expect(t.getByRole("columnheader", { name: "Code" })).toHaveAttribute("aria-sort", "ascending");
|
|
click(t, "Code");
|
|
expect(column(t, "Code")).toEqual(["MBB", "HLB", "CIMB"]);
|
|
expect(t.getByRole("columnheader", { name: "Code" })).toHaveAttribute("aria-sort", "descending");
|
|
});
|
|
|
|
it.each([
|
|
["Name", ["CIMB Bank", "Hong Leong", "Maybank"]],
|
|
["SWIFT", ["CIBBMYKL", "HLBBMYKL", "MBBEMYKL"]],
|
|
["BNM code", ["11", "27", "35"]],
|
|
["Bank ID", ["CIM0001", "HLB0099", "MBB0228"]],
|
|
["Message tag", ["bank.CIMB", "bank.HLB", "bank.MBB"]],
|
|
])("%s header reorders asc then desc", async (header, asc) => {
|
|
const t = await table();
|
|
click(t, header);
|
|
expect(column(t, header)).toEqual(asc);
|
|
click(t, header);
|
|
expect(column(t, header)).toEqual([...asc].reverse());
|
|
});
|
|
|
|
it("Actions 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(svc.listBanks).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|