Files
ngqileandClaude Opus 5.5 1071ddaa2a feat(admin-portal): cut babyboo portal down to Co-Lite login, users and roles
Removes every other screen, API route, component, test and the dependencies only
they used. Cookie colite_admin, Co-Lite branding, BO_USERS/BO_ROLES modules only.
The user form no longer loads branches, events or country scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 21:24:30 +08:00

68 lines
2.2 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
const mocks = vi.hoisted(() => ({
hasModule: vi.fn(),
loading: false,
}));
vi.mock("@/app/lib/AdminAuthContext", () => ({
useAdminAuth: () => ({ hasModule: mocks.hasModule, loading: mocks.loading }),
}));
import { RequireModule, NotAuthorized } from "./RequireModule";
describe("RequireModule", () => {
it("renders children when the pathname is not gated (no entry in ROUTE_MODULES)", () => {
mocks.loading = false;
render(
<RequireModule pathname="/some/ungated/route">
<div>secret</div>
</RequireModule>,
);
expect(screen.getByText("secret")).toBeInTheDocument();
});
it("renders children when the user's aclMenu has the required module", () => {
mocks.loading = false;
mocks.hasModule.mockReturnValue(true);
render(
<RequireModule pathname="/users">
<div>user list</div>
</RequireModule>,
);
expect(screen.getByText("user list")).toBeInTheDocument();
});
it("renders the not-authorised fallback, and does NOT throw, when the expected module is absent from aclMenu", () => {
mocks.loading = false;
mocks.hasModule.mockReturnValue(false);
expect(() =>
render(
<RequireModule pathname="/users">
<div>user list</div>
</RequireModule>,
),
).not.toThrow();
expect(screen.queryByText("user list")).toBeNull();
expect(screen.getByTestId("not-authorized")).toBeInTheDocument();
});
it("renders nothing (not the gated content) while the session is still loading", () => {
mocks.loading = true;
mocks.hasModule.mockReturnValue(false);
render(
<RequireModule pathname="/users">
<div>user list</div>
</RequireModule>,
);
expect(screen.queryByText("user list")).toBeNull();
expect(screen.queryByTestId("not-authorized")).toBeNull();
});
it("NotAuthorized renders standalone without crashing", () => {
expect(() => render(<NotAuthorized />)).not.toThrow();
expect(screen.getByTestId("not-authorized")).toBeInTheDocument();
expect(screen.getByRole("heading", { level: 1, name: "Not authorised" })).toHaveClass("text-xl");
});
});