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
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { render, renderHook } from "@testing-library/react";
|
|
|
|
// vitest.setup.ts pins useFitPageSize to 20 for page tests; this file tests the real hook.
|
|
vi.unmock("@/app/lib/hooks/useFitPageSize");
|
|
import { fitPageSize, useFitPageSize } from "./useFitPageSize";
|
|
|
|
// fit-admin-listing-pages: a listing requests as many rows as fit between its table's top and the
|
|
// bottom of the screen, 10 to 50.
|
|
describe("fitPageSize", () => {
|
|
it("fits more rows on a taller screen", () => {
|
|
// Rows are sized as two-line rows (49px, a member code above a name) so they never overflow.
|
|
expect(fitPageSize(1080, 200)).toBe(15);
|
|
expect(fitPageSize(1440, 300)).toBe(20);
|
|
});
|
|
|
|
it("never goes below 10 or above 50", () => {
|
|
expect(fitPageSize(400, 300)).toBe(10);
|
|
expect(fitPageSize(5000, 0)).toBe(50);
|
|
});
|
|
});
|
|
|
|
describe("useFitPageSize", () => {
|
|
const original = window.innerHeight;
|
|
afterEach(() => {
|
|
Object.defineProperty(window, "innerHeight", { value: original, configurable: true });
|
|
});
|
|
const setHeight = (h: number) => Object.defineProperty(window, "innerHeight", { value: h, configurable: true });
|
|
|
|
it("measures from the table's top once the table is attached", () => {
|
|
setHeight(1440);
|
|
let size: number | null = null;
|
|
function Listing() {
|
|
const { tableRef, pageSize } = useFitPageSize();
|
|
size = pageSize;
|
|
return <div ref={tableRef} data-testid="table" />;
|
|
}
|
|
vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockReturnValue({ top: 300 } as DOMRect);
|
|
render(<Listing />);
|
|
expect(size).toBe(20);
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("estimates the table's top when no table is attached", () => {
|
|
setHeight(900);
|
|
const { result } = renderHook(() => useFitPageSize());
|
|
expect(result.current.pageSize).toBe(10);
|
|
});
|
|
|
|
it("measures once per mount, so a resize does not change the page size", () => {
|
|
setHeight(900);
|
|
const { result, rerender } = renderHook(() => useFitPageSize());
|
|
setHeight(1800);
|
|
rerender();
|
|
expect(result.current.pageSize).toBe(10);
|
|
});
|
|
});
|