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
90 lines
3.2 KiB
TypeScript
90 lines
3.2 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { DrillLink } from "./drill-link";
|
|
|
|
const auth = vi.hoisted(() => ({ modules: [] as string[] }));
|
|
vi.mock("@/app/lib/AdminAuthContext", () => ({
|
|
useAdminAuth: () => ({ hasModule: (m: string) => auth.modules.includes(m) }),
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
auth.modules = [];
|
|
});
|
|
|
|
const MEMBERS = "/members?joinDateFrom=2026-10-01&joinDateTo=2026-10-31";
|
|
|
|
describe("DrillLink", () => {
|
|
it("renders a real link with the figure announced when the admin can open the route", () => {
|
|
auth.modules = ["BO_MEMBERS"];
|
|
render(<DrillLink href={MEMBERS}><span>tile</span></DrillLink>);
|
|
|
|
const link = screen.getByRole("link");
|
|
expect(link).toHaveAttribute("href", MEMBERS);
|
|
expect(link).not.toHaveAttribute("aria-label");
|
|
expect(screen.getByRole("link", { name: /^tile.*View records$/ })).toBe(link);
|
|
expect(link).toHaveTextContent("tile");
|
|
});
|
|
|
|
it("shows a focus ring on a link", () => {
|
|
auth.modules = ["BO_MEMBERS"];
|
|
render(<DrillLink href={MEMBERS}>x</DrillLink>);
|
|
expect(screen.getByRole("link").className).toContain("focus-visible:ring-2");
|
|
});
|
|
|
|
it("renders the children as plain content when the admin lacks the module", () => {
|
|
auth.modules = ["BO_REPORTS"];
|
|
render(<DrillLink href={MEMBERS}><span>tile</span></DrillLink>);
|
|
|
|
expect(screen.queryByRole("link")).not.toBeInTheDocument();
|
|
expect(screen.getByText("tile")).toBeInTheDocument();
|
|
expect(screen.queryByText("View records")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("treats a route the module map does not know as not accessible", () => {
|
|
auth.modules = ["BO_MEMBERS", "BO_REPORTS"];
|
|
render(<DrillLink href="/no-such-route?x=1"><span>tile</span></DrillLink>);
|
|
|
|
expect(screen.queryByRole("link")).not.toBeInTheDocument();
|
|
expect(screen.getByText("tile")).toBeInTheDocument();
|
|
});
|
|
|
|
it("checks the path without its query string", () => {
|
|
auth.modules = ["BO_REPORTS"];
|
|
render(<DrillLink href="/reports?tab=rewards">x</DrillLink>);
|
|
expect(screen.getByRole("link")).toHaveAttribute("href", "/reports?tab=rewards");
|
|
});
|
|
|
|
it("renders no hover styling on the plain content when the admin lacks the module", () => {
|
|
auth.modules = ["BO_REPORTS"];
|
|
const { container } = render(
|
|
<DrillLink
|
|
href={MEMBERS}
|
|
className="rounded-xl"
|
|
linkClassName="hover:bg-primary-foreground/15"
|
|
>
|
|
<span>tile</span>
|
|
</DrillLink>,
|
|
);
|
|
expect(screen.queryByRole("link")).not.toBeInTheDocument();
|
|
const hoverEls = Array.from(container.querySelectorAll("*")).filter(e => (e.getAttribute("class") ?? "").includes("hover:"));
|
|
expect(hoverEls).toHaveLength(0);
|
|
expect(container.querySelector(".rounded-xl")).not.toBeNull();
|
|
});
|
|
|
|
it("puts layout and hover classes on the link when the admin has the module", () => {
|
|
auth.modules = ["BO_MEMBERS"];
|
|
render(
|
|
<DrillLink
|
|
href={MEMBERS}
|
|
className="rounded-xl"
|
|
linkClassName="hover:bg-primary-foreground/15"
|
|
>
|
|
<span>tile</span>
|
|
</DrillLink>,
|
|
);
|
|
const a = screen.getByRole("link");
|
|
expect(a).toHaveClass("rounded-xl");
|
|
expect(a).toHaveClass("hover:bg-primary-foreground/15");
|
|
});
|
|
});
|