feat(frontend): add cabinet shells, brand tokens, and state primitives

This commit is contained in:
shira committed 2026-10-06 01:09:08 +03:00
1 parent dda3825786
commit 0e2a3b02ab
85 files changed
+3313 -113

No files matched your search

+134
View File
@@ -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("Экран будет реализован в одной из следующих задач");
}
});
});