mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
The client bundle carries only the active locale — resolved on the server and handed to the provider with no hydration flash, halving the dashboard route to under a megabyte parsed (288 KiB gzip). The auth shell renders the app chrome immediately instead of a spinner while the session resolves in parallel, the widgets request folds into the snapshot it duplicated, and insight pills prefetch their sub-pages — a first visit to a sub-page lands in about ninety milliseconds instead of nearly a second.
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
|
|
/**
|
|
* v1.4.15 phase A2: the `/admin` overview no longer renders the
|
|
* `StatusCardGrid` (the section-card grid the maintainer described as redundant
|
|
* with the sidebar nav). The status-card component itself was removed
|
|
* from the codebase. This test guards the *new* overview composition:
|
|
* a welcome card, the system snapshot, and the recent-audit preview.
|
|
*
|
|
* The file kept its old name so git history follows it. Nothing else
|
|
* imports `status-card-grid`.
|
|
*/
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
|
|
usePathname: () => "/admin",
|
|
}));
|
|
|
|
vi.mock("@tanstack/react-query", () => ({
|
|
useQuery: () => ({
|
|
data: null,
|
|
isLoading: false,
|
|
isError: false,
|
|
refetch: vi.fn(),
|
|
}),
|
|
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
|
useMutation: () => ({
|
|
mutate: vi.fn(),
|
|
isPending: false,
|
|
isError: false,
|
|
error: null,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/hooks/use-auth", () => ({
|
|
useAuth: () => ({
|
|
user: {
|
|
id: "u1",
|
|
username: "testuser",
|
|
email: "user@example.com",
|
|
role: "ADMIN",
|
|
},
|
|
isAuthenticated: true,
|
|
isLoading: false,
|
|
refetch: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
import AdminOverviewPage from "@/app/admin/page";
|
|
import { SystemStatusSummary } from "../system-status-summary";
|
|
import { RecentAuditPreview } from "../recent-audit-preview";
|
|
|
|
function render(node: React.ReactElement) {
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale="en">{node}</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("/admin overview composition", () => {
|
|
it("does NOT render the legacy section-card grid", () => {
|
|
const html = render(<AdminOverviewPage />);
|
|
// The old grid surfaced six card titles ("Users", "Integrations",
|
|
// "Monitoring", "Backups", "Maintenance", "Audit log") in headings.
|
|
// The redesigned overview must not paint that grid anymore.
|
|
expect(html).not.toContain(">Maintenance<");
|
|
expect(html).not.toContain(">Monitoring<");
|
|
// No "Manage users"/"Open backups" CTAs from the StatusCard CTAs.
|
|
expect(html).not.toContain("Manage users");
|
|
expect(html).not.toContain("Open backups");
|
|
});
|
|
|
|
it("renders the welcome card with the admin's username", () => {
|
|
const html = render(<AdminOverviewPage />);
|
|
// `welcomeTitle` interpolates the username; the mocked auth hook
|
|
// returns "testuser".
|
|
expect(html).toContain("Welcome, testuser");
|
|
expect(html).toContain("admin-overview-welcome-heading");
|
|
});
|
|
|
|
it("renders the system snapshot section heading", () => {
|
|
const html = render(<SystemStatusSummary />);
|
|
expect(html).toContain("System snapshot");
|
|
expect(html).toContain("admin-overview-snapshot-heading");
|
|
});
|
|
|
|
it("renders the recent-activity section with a 'View all' link", () => {
|
|
const html = render(<RecentAuditPreview />);
|
|
expect(html).toContain("Recent activity");
|
|
expect(html).toContain("admin-overview-audit-heading");
|
|
expect(html).toContain('href="/admin/login-overview"');
|
|
expect(html).toContain("View all");
|
|
});
|
|
});
|