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
62 lines
2.6 KiB
TypeScript
62 lines
2.6 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, within } from "@testing-library/react";
|
|
import type { CmsFormListItem } from "@/app/lib/cmsForms";
|
|
|
|
// add-cms-forms Task 9: the /forms list (specs/admin-portal-cms-forms-ui "The Forms List Shows Every Form").
|
|
|
|
const auth = vi.hoisted(() => ({ hasModule: vi.fn(), loading: false }));
|
|
vi.mock("@/app/lib/AdminAuthContext", () => ({
|
|
useAdminAuth: () => ({ hasModule: auth.hasModule, loading: auth.loading }),
|
|
}));
|
|
|
|
const svc = vi.hoisted(() => ({ listForms: vi.fn() }));
|
|
vi.mock("@/app/lib/services/adminForms", () => ({
|
|
listForms: () => svc.listForms(),
|
|
}));
|
|
|
|
import FormsPage from "./page";
|
|
|
|
const rows: CmsFormListItem[] = [
|
|
{ id: 3, name: "Contact us", status: "Y", fieldCount: 4, submissionCount: 2, updatedAt: "2026-10-05T10:15:00" },
|
|
{ id: 4, name: "Distributor", status: "N", fieldCount: 7, submissionCount: 0, updatedAt: "2026-10-06T08:00:00" },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
auth.hasModule.mockReset();
|
|
auth.hasModule.mockReturnValue(true);
|
|
svc.listForms.mockReset();
|
|
});
|
|
|
|
describe("/forms", () => {
|
|
it("lists each form with its counts, status and links", async () => {
|
|
svc.listForms.mockResolvedValue(rows);
|
|
render(<FormsPage />);
|
|
|
|
const table = await screen.findByRole("table", { name: "Forms" });
|
|
const contact = within(table).getByRole("row", { name: /Contact us/ });
|
|
expect(within(contact).getByRole("link", { name: "Contact us" })).toHaveAttribute("href", "/forms/3");
|
|
expect(within(contact).getByText("4")).toBeInTheDocument();
|
|
expect(within(contact).getByRole("link", { name: "2 submissions" })).toHaveAttribute("href", "/forms/3/submissions");
|
|
expect(within(contact).getByText("Visible")).toBeInTheDocument();
|
|
expect(within(contact).getByText(/5 Oct 2026/)).toBeInTheDocument();
|
|
const distributor = within(table).getByRole("row", { name: /Distributor/ });
|
|
expect(within(distributor).getByText("Hidden")).toBeInTheDocument();
|
|
expect(within(distributor).getByRole("link", { name: "0 submissions" })).toHaveAttribute("href", "/forms/4/submissions");
|
|
expect(screen.getByRole("link", { name: /new form/i })).toHaveAttribute("href", "/forms/new");
|
|
});
|
|
|
|
it("says so when there are no forms", async () => {
|
|
svc.listForms.mockResolvedValue([]);
|
|
render(<FormsPage />);
|
|
|
|
expect(await screen.findByText("No forms yet.")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows a load failure", async () => {
|
|
svc.listForms.mockRejectedValue(new Error("Boom"));
|
|
render(<FormsPage />);
|
|
|
|
expect(await screen.findByText("Boom")).toBeInTheDocument();
|
|
});
|
|
});
|