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
44 lines
2.0 KiB
TypeScript
44 lines
2.0 KiB
TypeScript
import { fireEvent, render } from "@testing-library/react";
|
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
import MemberQR from "./MemberQR";
|
|
|
|
afterEach(() => vi.restoreAllMocks());
|
|
|
|
const qrImg = (c: HTMLElement) => c.querySelector('img[alt="Member QR code"]') as HTMLImageElement | null;
|
|
const visibleSvg = (c: HTMLElement) =>
|
|
[...c.querySelectorAll("svg")].find((s) => (s as SVGElement).style.display !== "none") ?? null;
|
|
|
|
describe("MemberQR", () => {
|
|
it("shows the member's QR as a PNG image so browser dark modes do not recolour it", () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, "toDataURL").mockReturnValue("data:image/png;base64,QR");
|
|
const { container } = render(<MemberQR value="21305684" />);
|
|
expect(qrImg(container)?.src).toBe("data:image/png;base64,QR");
|
|
expect(visibleSvg(container)).toBeNull();
|
|
});
|
|
|
|
it("falls back to an SVG image when the browser blocks reading the canvas", () => {
|
|
// Anti-fingerprinting browsers return an empty "data:," instead of the drawn pixels.
|
|
vi.spyOn(HTMLCanvasElement.prototype, "toDataURL").mockReturnValue("data:,");
|
|
const { container } = render(<MemberQR value="43748424" />);
|
|
const img = qrImg(container)!;
|
|
expect(img.src.startsWith("data:image/svg+xml")).toBe(true);
|
|
expect(decodeURIComponent(img.src)).toContain("<path");
|
|
});
|
|
|
|
it("falls back to an SVG image when reading the canvas throws", () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, "toDataURL").mockImplementation(() => {
|
|
throw new Error("SecurityError");
|
|
});
|
|
const { container } = render(<MemberQR value="43748424" />);
|
|
expect(qrImg(container)!.src.startsWith("data:image/svg+xml")).toBe(true);
|
|
});
|
|
|
|
it("shows the plain inline QR when the image fails to load", () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, "toDataURL").mockReturnValue("data:image/png;base64,QR");
|
|
const { container } = render(<MemberQR value="43748424" />);
|
|
fireEvent.error(qrImg(container)!);
|
|
expect(qrImg(container)).toBeNull();
|
|
expect(visibleSvg(container)).not.toBeNull();
|
|
});
|
|
});
|