Files
co-lite/solvway-admin-portal/vitest.setup.ts
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
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
2026-11-26 15:55:45 +08:00

65 lines
3.0 KiB
TypeScript

import "@testing-library/jest-dom";
import { configure } from "@testing-library/react";
import { vi } from "vitest";
// The Docker image runs this suite beside `next build` (parallel-portal-test-stage), so a test can
// wait well past Testing Library's 1 s default for async UI on a busy CPU. A longer limit costs
// nothing when the UI appears: findBy and waitFor resolve as soon as it does.
configure({ asyncUtilTimeout: 5000 });
// vitest has no next/font transform; stub the loader.
vi.mock("next/font/local", () => ({
default: (o: { variable: string }) => ({ variable: o.variable, className: "x" }),
}));
// Page tests are about page behaviour, not sizing: pin the fitted page size to 20.
// app/lib/hooks/useFitPageSize.test.tsx unmocks it to test the real measurement.
vi.mock("@/app/lib/hooks/useFitPageSize", async (importOriginal) => ({
...(await importOriginal<typeof import("@/app/lib/hooks/useFitPageSize")>()),
useFitPageSize: () => ({ tableRef: () => {}, pageSize: 20 }),
}));
// localise-admin-shell: server components call getServerT(), which reads next/headers. Suites that do not
// render them get the English defaults; app/lib/server/i18n.test.ts and app/layout.test.tsx vi.unmock it.
vi.mock("@/app/lib/server/i18n", async () => {
const { resolveMessage } = await import("@/app/lib/i18n/t");
return {
requestLocale: async () => ({ locale: "en_US", locales: [] }),
requestCatalog: async () => ({}),
getServerT: async () => (code: string, params?: Record<string, string | number>) => resolveMessage({}, code, params),
};
});
// Everything below patches the DOM, which only the jsdom project has.
if (typeof window !== "undefined") {
// Responsive components (the shadcn sidebar's mobile breakpoint) need matchMedia.
Object.defineProperty(window, "matchMedia", {
writable: true,
value: (query: string) => ({
matches: false, media: query, onchange: null,
addListener: () => {}, removeListener: () => {},
addEventListener: () => {}, removeEventListener: () => {},
dispatchEvent: () => false,
}),
});
// Recharts' ResponsiveContainer and Radix popups observe size changes.
class ResizeObserverStub {
observe() {}
unobserve() {}
disconnect() {}
}
window.ResizeObserver = window.ResizeObserver ?? (ResizeObserverStub as unknown as typeof ResizeObserver);
// Radix primitives (Select, DropdownMenu) drive interaction through the Pointer
// Events API and scroll the active item into view. jsdom implements neither, so
// without these stubs every dropdown interaction throws.
Element.prototype.hasPointerCapture = Element.prototype.hasPointerCapture ?? (() => false);
Element.prototype.setPointerCapture = Element.prototype.setPointerCapture ?? (() => {});
Element.prototype.releasePointerCapture = Element.prototype.releasePointerCapture ?? (() => {});
Element.prototype.scrollIntoView = Element.prototype.scrollIntoView ?? (() => {});
}
// sign-session-cookies (F32): a fixed session signing key for tests.
process.env.SESSION_SECRET ??= "vitest-session-secret";