Files
co-lite/solvway-customer-portal/app/attendance/page.test.tsx
T
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

50 lines
2.1 KiB
TypeScript

import { render, screen, waitFor } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import type { AttendanceRecord } from "@/app/lib/types";
vi.mock("@/app/lib/ThemeContext", () => ({ useTheme: () => ({ isDark: false, toggle: vi.fn() }) }));
vi.mock("@/app/lib/clientApi", () => ({ apiGet: vi.fn() }));
import AttendancePage from "./page";
import { apiGet } from "@/app/lib/clientApi";
const mockApiGet = apiGet as unknown as ReturnType<typeof vi.fn>;
beforeEach(() => mockApiGet.mockReset());
describe("AttendancePage", () => {
it("renders the count and one row per check-in with booth names", async () => {
const records: AttendanceRecord[] = [
{ stockistName: "Booth Beta", stockistUuid: 202, eventUuid: 901, checkInDateTime: "2026-07-03T15:30:00", checkInDate: "2026-07-03" },
{ stockistName: "Booth Alpha", stockistUuid: 101, eventUuid: 900, checkInDateTime: "2026-07-01T10:00:00", checkInDate: "2026-07-01" },
];
mockApiGet.mockResolvedValue(records);
render(<AttendancePage />);
expect(await screen.findByText("Booth Beta")).toBeInTheDocument();
expect(screen.getByText("Booth Alpha")).toBeInTheDocument();
const rows = screen.getAllByTestId("attendance-row");
expect(rows).toHaveLength(2);
// header shows the count
expect(screen.getByText(/2\s*check-ins/i)).toBeInTheDocument();
});
it("renders a booth fallback label when the name is absent", async () => {
mockApiGet.mockResolvedValue([
{ stockistUuid: 303, eventUuid: 902, checkInDateTime: "2026-07-04T09:00:00", checkInDate: "2026-07-04" },
] as AttendanceRecord[]);
render(<AttendancePage />);
expect(await screen.findByText("Booth")).toBeInTheDocument();
expect(screen.getAllByTestId("attendance-row")).toHaveLength(1);
});
it("renders an empty state when there are no check-ins", async () => {
mockApiGet.mockResolvedValue([]);
render(<AttendancePage />);
await waitFor(() => expect(screen.getByTestId("attendance-empty")).toBeInTheDocument());
expect(screen.queryByTestId("attendance-row")).toBeNull();
});
});