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
91 lines
3.7 KiB
TypeScript
91 lines
3.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, within, fireEvent } from "@testing-library/react";
|
|
import type { LocaleRegistryRow } from "@/app/lib/types";
|
|
|
|
// BABYBOO-54 task 1.1: the /locales list sorts in the browser; the Actions column does not sort.
|
|
|
|
const auth = vi.hoisted(() => ({ hasModule: vi.fn(), loading: false }));
|
|
vi.mock("@/app/lib/AdminAuthContext", () => ({
|
|
useAdminAuth: () => ({ hasModule: auth.hasModule, loading: auth.loading }),
|
|
}));
|
|
const svc = vi.hoisted(() => ({ listLocales: vi.fn(), createLocale: vi.fn(), updateLocale: vi.fn() }));
|
|
vi.mock("@/app/lib/services/locales", () => ({
|
|
listLocales: () => svc.listLocales(),
|
|
createLocale: (p: unknown) => svc.createLocale(p),
|
|
updateLocale: (id: number, p: unknown) => svc.updateLocale(id, p),
|
|
}));
|
|
|
|
import LocalesPage from "./page";
|
|
|
|
// API order is deliberately sorted by none of the columns.
|
|
const ROWS: LocaleRegistryRow[] = [
|
|
{ id: 5, code: "ms_MY", label: "Bahasa Melayu", enabled: true, sortOrder: 5 },
|
|
{ id: 6, code: "th_TH", label: "Thai", enabled: false, sortOrder: 6 },
|
|
{ id: 1, code: "en_US", label: "English", enabled: true, sortOrder: 1 },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
auth.hasModule.mockReset().mockReturnValue(true);
|
|
svc.listLocales.mockReset().mockResolvedValue(ROWS);
|
|
});
|
|
|
|
async function table() {
|
|
await screen.findByText("Bahasa Melayu");
|
|
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("/locales - client-side header sorting", () => {
|
|
it("Code header reorders asc then desc", async () => {
|
|
render(<LocalesPage />);
|
|
const t = await table();
|
|
expect(column(t, "Code")).toEqual(["ms_MY", "th_TH", "en_US"]);
|
|
click(t, "Code");
|
|
expect(column(t, "Code")).toEqual(["en_US", "ms_MY", "th_TH"]);
|
|
expect(t.getByRole("columnheader", { name: "Code" })).toHaveAttribute("aria-sort", "ascending");
|
|
click(t, "Code");
|
|
expect(column(t, "Code")).toEqual(["th_TH", "ms_MY", "en_US"]);
|
|
expect(t.getByRole("columnheader", { name: "Code" })).toHaveAttribute("aria-sort", "descending");
|
|
});
|
|
|
|
it("Label header reorders asc then desc", async () => {
|
|
render(<LocalesPage />);
|
|
const t = await table();
|
|
click(t, "Label");
|
|
expect(column(t, "Label")).toEqual(["Bahasa Melayu", "English", "Thai"]);
|
|
click(t, "Label");
|
|
expect(column(t, "Label")).toEqual(["Thai", "English", "Bahasa Melayu"]);
|
|
});
|
|
|
|
it("Status header groups Active before Inactive, then reverses", async () => {
|
|
render(<LocalesPage />);
|
|
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("Sort order header orders numerically", async () => {
|
|
render(<LocalesPage />);
|
|
const t = await table();
|
|
click(t, "Sort order");
|
|
expect(column(t, "Sort order")).toEqual(["1", "5", "6"]);
|
|
click(t, "Sort order");
|
|
expect(column(t, "Sort order")).toEqual(["6", "5", "1"]);
|
|
});
|
|
|
|
it("Actions column has no sort button; sorting makes no new request", async () => {
|
|
render(<LocalesPage />);
|
|
const t = await table();
|
|
const heads = t.getAllByRole("columnheader");
|
|
expect(within(heads[heads.length - 1]).queryByRole("button")).toBeNull();
|
|
click(t, "Code");
|
|
expect(svc.listLocales).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|