feat(frontend): add cabinet shells, brand tokens, and state primitives
This commit is contained in:
1 parent
dda3825786
commit
0e2a3b02ab
85 files changed
+3313
-113
No files matched your search
@@ -0,0 +1,134 @@
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { StaticRouterProvider, createStaticHandler, createStaticRouter } from "react-router-dom";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createQueryClient } from "../providers/query-client";
|
||||
import { routes } from "./routes";
|
||||
|
||||
// Node has no DOM in this project's Vitest setup, so routes are rendered
|
||||
// through React Router's static handler: the same route tree, loaders, and
|
||||
// layouts as in the browser, checked as server-rendered HTML.
|
||||
async function render(path: string): Promise<string | Response> {
|
||||
const handler = createStaticHandler(routes);
|
||||
const context = await handler.query(new Request(`http://localhost${path}`));
|
||||
if (context instanceof Response) {
|
||||
return context;
|
||||
}
|
||||
const router = createStaticRouter(handler.dataRoutes, context);
|
||||
return renderToString(
|
||||
<QueryClientProvider client={createQueryClient()}>
|
||||
<StaticRouterProvider router={router} context={context} hydrate={false} />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
async function renderHtml(path: string): Promise<string> {
|
||||
const result = await render(path);
|
||||
if (typeof result !== "string") {
|
||||
throw new Error(`Expected HTML for ${path}, got a ${result.status} response.`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function count(html: string, pattern: RegExp): number {
|
||||
return html.match(new RegExp(pattern.source, "g"))?.length ?? 0;
|
||||
}
|
||||
|
||||
function currentLinkText(html: string): string[] {
|
||||
return [...html.matchAll(/<a[^>]*aria-current="page"[^>]*>(.*?)<\/a>/g)].map(
|
||||
(match) => match[1] ?? "",
|
||||
);
|
||||
}
|
||||
|
||||
describe("route groups", () => {
|
||||
it.each([
|
||||
["/", "Протокол подтвержденных навыков", "Публичные разделы"],
|
||||
["/login", "Вход", "Публичные разделы"],
|
||||
["/register", "Регистрация", "Публичные разделы"],
|
||||
["/verify-email", "Подтверждение почты", "Публичные разделы"],
|
||||
["/support", "Поддержка", "Публичные разделы"],
|
||||
["/candidate", "Главная", "Разделы кабинета кандидата"],
|
||||
["/candidate/profile", "Профиль", "Разделы кабинета кандидата"],
|
||||
["/candidate/onboarding", "Первые шаги", "Разделы кабинета кандидата"],
|
||||
["/employer/company", "Компания и команда", "Разделы кабинета работодателя"],
|
||||
["/employer/candidates", "Кандидаты", "Разделы кабинета работодателя"],
|
||||
])("renders %s in its shell with one h1 and landmarks", async (path, heading, navLabel) => {
|
||||
const html = await renderHtml(path);
|
||||
|
||||
expect(count(html, /<h1[\s>]/)).toBe(1);
|
||||
expect(html).toMatch(new RegExp(`<h1[^>]*>${heading}</h1>`));
|
||||
expect(html).toMatch(new RegExp(`<nav[^>]*aria-label="${navLabel}"`));
|
||||
expect(count(html, /<main[\s>]/)).toBe(1);
|
||||
expect(html).toMatch(/<main[^>]*id="main-content"[^>]*tabindex="-1"/i);
|
||||
expect(html).toContain(`<title>${heading} - Lincodex</title>`);
|
||||
});
|
||||
|
||||
it("puts the skip link before any other link and points it at main", async () => {
|
||||
for (const path of ["/", "/candidate", "/employer/needs"]) {
|
||||
const html = await renderHtml(path);
|
||||
const firstLink = html.match(/<a[^>]*>(.*?)<\/a>/);
|
||||
|
||||
expect(firstLink?.[0]).toContain('href="#main-content"');
|
||||
expect(firstLink?.[1]).toBe("Перейти к основному содержимому");
|
||||
}
|
||||
});
|
||||
|
||||
it("marks the active cabinet section with aria-current", async () => {
|
||||
expect(currentLinkText(await renderHtml("/candidate"))).toEqual(["Главная"]);
|
||||
expect(currentLinkText(await renderHtml("/candidate/results"))).toEqual(["Результаты"]);
|
||||
expect(currentLinkText(await renderHtml("/employer/invitations"))).toEqual(["Приглашения"]);
|
||||
});
|
||||
|
||||
it("separates the cabinets: each shell shows only its own navigation", async () => {
|
||||
const candidate = await renderHtml("/candidate");
|
||||
const employer = await renderHtml("/employer/company");
|
||||
|
||||
expect(candidate).not.toContain("Разделы кабинета работодателя");
|
||||
expect(candidate).not.toContain("Публичные разделы");
|
||||
expect(employer).not.toContain("Разделы кабинета кандидата");
|
||||
expect(employer).not.toContain("Публичные разделы");
|
||||
});
|
||||
|
||||
it("sends the employer cabinet root to the company screen", async () => {
|
||||
const result = await render("/employer");
|
||||
|
||||
expect(result).toBeInstanceOf(Response);
|
||||
expect((result as Response).status).toBe(302);
|
||||
expect((result as Response).headers.get("Location")).toBe("/employer/company");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["/missing", "/", "На главную"],
|
||||
["/candidate/missing", "/candidate", "В кабинет кандидата"],
|
||||
["/employer/missing", "/employer/company", "В кабинет работодателя"],
|
||||
])("shows a not-found page for %s inside the matching shell", async (path, home, label) => {
|
||||
const html = await renderHtml(path);
|
||||
|
||||
expect(html).toMatch(/<h1[^>]*>Страница не найдена<\/h1>/);
|
||||
expect(html).toMatch(new RegExp(`<a[^>]*href="${home}"[^>]*>${label}</a>`));
|
||||
});
|
||||
});
|
||||
|
||||
describe("product readiness", () => {
|
||||
it("presents the root page as a scaffold, not as a working product", async () => {
|
||||
const html = await renderHtml("/");
|
||||
|
||||
expect(html).toContain("Сейчас доступен только каркас интерфейса");
|
||||
// The API liveness check lives on the technical page, not on the landing.
|
||||
expect(html).not.toContain("healthz");
|
||||
expect(html).toMatch(/<a[^>]*href="\/status"[^>]*>Технический статус<\/a>/);
|
||||
});
|
||||
|
||||
it("labels the status page as technical", async () => {
|
||||
const html = await renderHtml("/status");
|
||||
|
||||
expect(html).toContain("Служебная страница");
|
||||
expect(html).toContain("Это не показатель готовности продукта");
|
||||
});
|
||||
|
||||
it("labels every cabinet screen as a placeholder", async () => {
|
||||
for (const path of ["/candidate", "/candidate/privacy", "/employer/needs"]) {
|
||||
expect(await renderHtml(path)).toContain("Экран будет реализован в одной из следующих задач");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { redirect, type RouteObject } from "react-router-dom";
|
||||
import { NotFoundPage } from "../../pages/not-found";
|
||||
import { PlaceholderPage } from "../../pages/placeholder";
|
||||
import { StatusPage } from "../../pages/status";
|
||||
import { WelcomePage } from "../../pages/welcome";
|
||||
import { paths } from "../../shared/config";
|
||||
import { CandidateShell } from "../../widgets/candidate-shell";
|
||||
import { EmployerShell } from "../../widgets/employer-shell";
|
||||
import { PublicShell } from "../../widgets/public-shell";
|
||||
import { RootLayout } from "../ui/root-layout";
|
||||
import { RouteErrorPage } from "../ui/route-error-page";
|
||||
|
||||
/**
|
||||
* Route tree with three groups: public pages, the candidate cabinet, and the
|
||||
* employer cabinet. Each group has its own shell and its own not-found page.
|
||||
* Access control is not implemented yet; the server will enforce it.
|
||||
*/
|
||||
export const routes: RouteObject[] = [
|
||||
{
|
||||
element: <RootLayout />,
|
||||
errorElement: <RouteErrorPage />,
|
||||
children: [
|
||||
{
|
||||
element: <PublicShell />,
|
||||
children: [
|
||||
{ index: true, element: <WelcomePage /> },
|
||||
{ path: paths.login, element: <PlaceholderPage screen="login" /> },
|
||||
{ path: paths.register, element: <PlaceholderPage screen="register" /> },
|
||||
{ path: paths.verifyEmail, element: <PlaceholderPage screen="verifyEmail" /> },
|
||||
{ path: paths.support, element: <PlaceholderPage screen="support" /> },
|
||||
{ path: paths.status, element: <StatusPage /> },
|
||||
{ path: "*", element: <NotFoundPage /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
path: paths.candidate.root,
|
||||
element: <CandidateShell />,
|
||||
children: [
|
||||
{ index: true, element: <PlaceholderPage screen="candidateHome" /> },
|
||||
{
|
||||
path: paths.candidate.onboarding,
|
||||
element: <PlaceholderPage screen="candidateOnboarding" />,
|
||||
},
|
||||
{ path: paths.candidate.profile, element: <PlaceholderPage screen="candidateProfile" /> },
|
||||
{
|
||||
path: paths.candidate.assessment,
|
||||
element: <PlaceholderPage screen="candidateAssessment" />,
|
||||
},
|
||||
{ path: paths.candidate.results, element: <PlaceholderPage screen="candidateResults" /> },
|
||||
{
|
||||
path: paths.candidate.invitations,
|
||||
element: <PlaceholderPage screen="candidateInvitations" />,
|
||||
},
|
||||
{ path: paths.candidate.privacy, element: <PlaceholderPage screen="candidatePrivacy" /> },
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.candidate.root} homeLabel="В кабинет кандидата" />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: paths.employer.root,
|
||||
element: <EmployerShell />,
|
||||
children: [
|
||||
// The employer flow starts with the company profile.
|
||||
{ index: true, loader: () => redirect(paths.employer.company) },
|
||||
{ path: paths.employer.company, element: <PlaceholderPage screen="employerCompany" /> },
|
||||
{ path: paths.employer.needs, element: <PlaceholderPage screen="employerNeeds" /> },
|
||||
{
|
||||
path: paths.employer.candidates,
|
||||
element: <PlaceholderPage screen="employerCandidates" />,
|
||||
},
|
||||
{
|
||||
path: paths.employer.invitations,
|
||||
element: <PlaceholderPage screen="employerInvitations" />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.employer.company} homeLabel="В кабинет работодателя" />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user