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
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { render, screen, fireEvent } from "@testing-library/react";
|
|
import type { SortingState } from "@tanstack/react-table";
|
|
import { Table, TableHeader, TableRow } from "./table";
|
|
import { SortableHead } from "./sortable-head";
|
|
|
|
function renderHead(sorting: SortingState, onSortingChange = vi.fn()) {
|
|
render(
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<SortableHead label="Amount" sortKey="amount" sorting={sorting} onSortingChange={onSortingChange} />
|
|
</TableRow>
|
|
</TableHeader>
|
|
</Table>,
|
|
);
|
|
return onSortingChange;
|
|
}
|
|
|
|
describe("SortableHead", () => {
|
|
it.each([
|
|
[[], "none"],
|
|
[[{ id: "amount", desc: false }], "ascending"],
|
|
[[{ id: "amount", desc: true }], "descending"],
|
|
[[{ id: "other", desc: false }], "none"],
|
|
] as [SortingState, string][])("aria-sort for %j is %s", (sorting, expected) => {
|
|
renderHead(sorting);
|
|
expect(screen.getByRole("columnheader")).toHaveAttribute("aria-sort", expected);
|
|
});
|
|
|
|
it("cycles none -> asc", () => {
|
|
const fn = renderHead([]);
|
|
fireEvent.click(screen.getByRole("button", { name: /Amount/ }));
|
|
expect(fn).toHaveBeenCalledWith([{ id: "amount", desc: false }]);
|
|
});
|
|
|
|
it("cycles asc -> desc", () => {
|
|
const fn = renderHead([{ id: "amount", desc: false }]);
|
|
fireEvent.click(screen.getByRole("button", { name: /Amount/ }));
|
|
expect(fn).toHaveBeenCalledWith([{ id: "amount", desc: true }]);
|
|
});
|
|
|
|
it("cycles desc -> none", () => {
|
|
const fn = renderHead([{ id: "amount", desc: true }]);
|
|
fireEvent.click(screen.getByRole("button", { name: /Amount/ }));
|
|
expect(fn).toHaveBeenCalledWith([]);
|
|
});
|
|
|
|
it("sorting by another column starts at asc", () => {
|
|
const fn = renderHead([{ id: "other", desc: true }]);
|
|
fireEvent.click(screen.getByRole("button", { name: /Amount/ }));
|
|
expect(fn).toHaveBeenCalledWith([{ id: "amount", desc: false }]);
|
|
});
|
|
});
|