feat(demo): add the jury guide and demonstration markers to the demo stand build
This commit is contained in:
1 parent
d365a05c96
commit
41206abbcf
32 files changed
+1096
-141
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { renderToString } from "react-dom/server";
|
||||
import {
|
||||
StaticRouterProvider,
|
||||
createStaticHandler,
|
||||
createStaticRouter,
|
||||
matchRoutes,
|
||||
} from "react-router-dom";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { guideRoles } from "../../pages/jury-guide";
|
||||
import { createRoutes } from "./routes";
|
||||
|
||||
async function renderPath(path: string, demo: boolean): Promise<string> {
|
||||
const handler = createStaticHandler(createRoutes({ demo }));
|
||||
const context = await handler.query(new Request(`http://localhost${path}`));
|
||||
if (context instanceof Response) throw new Error(`Unexpected response for ${path}`);
|
||||
const router = createStaticRouter(handler.dataRoutes, context);
|
||||
return renderToString(<StaticRouterProvider router={router} context={context} hydrate={false} />);
|
||||
}
|
||||
|
||||
describe("demonstration stand routes", () => {
|
||||
it("serves the jury guide and the banner only in a demo build", async () => {
|
||||
expect(await renderPath("/demo", true)).toMatch(/<h1[^>]*>Гид для жюри<\/h1>/);
|
||||
expect(await renderPath("/demo", false)).toMatch(/<h1[^>]*>Страница не найдена<\/h1>/);
|
||||
|
||||
expect(await renderPath("/", true)).toContain("Демонстрационный стенд.");
|
||||
expect(await renderPath("/", false)).not.toContain("Демонстрационный стенд.");
|
||||
});
|
||||
|
||||
it("links the jury guide from the landing page only in a demo build", async () => {
|
||||
const demo = await renderPath("/", true);
|
||||
const production = await renderPath("/", false);
|
||||
|
||||
expect(demo).toMatch(/<a[^>]*href="\/demo"[^>]*>Открыть гид для жюри<\/a>/);
|
||||
expect(production).not.toContain("Открыть гид для жюри");
|
||||
expect(production).not.toContain('href="/demo"');
|
||||
});
|
||||
|
||||
it("keeps the skip link as the first link of a demo page", async () => {
|
||||
const html = await renderPath("/", true);
|
||||
const firstLink = html.match(/<a[^>]*>(.*?)<\/a>/);
|
||||
|
||||
expect(firstLink?.[0]).toContain('href="#main-content"');
|
||||
});
|
||||
|
||||
it("resolves every link of the guide to a page of the router, not to not-found", () => {
|
||||
const routes = createRoutes({ demo: true });
|
||||
const links = guideRoles.flatMap((role) =>
|
||||
role.steps.flatMap((step) => (step.link ? [step.link.to] : [])),
|
||||
);
|
||||
|
||||
expect(links.length).toBeGreaterThan(0);
|
||||
for (const to of links) {
|
||||
const matches = matchRoutes(routes, to);
|
||||
expect(matches, to).not.toBeNull();
|
||||
expect(matches?.at(-1)?.route.path, to).not.toBe("*");
|
||||
}
|
||||
});
|
||||
});
|
||||
+128
-117
@@ -12,6 +12,7 @@ import { PrivacyPage } from "../../pages/privacy";
|
||||
import { SessionGate } from "../../entities/session";
|
||||
import { MatchesPage } from "../../pages/matches";
|
||||
import { InvitationComposePage } from "../../pages/invitation-compose";
|
||||
import { JuryGuidePage } from "../../pages/jury-guide";
|
||||
import { NotFoundPage } from "../../pages/not-found";
|
||||
import { NeedEditorPage } from "../../pages/need-editor";
|
||||
import { NeedListPage } from "../../pages/needs";
|
||||
@@ -27,7 +28,7 @@ import {
|
||||
SupportCasesPage,
|
||||
} from "../../pages/support-cases";
|
||||
import { WelcomePage } from "../../pages/welcome";
|
||||
import { paths } from "../../shared/config";
|
||||
import { paths, standMode, type StandMode } from "../../shared/config";
|
||||
import { CandidateShell } from "../../widgets/candidate-shell";
|
||||
import { EmployerShell } from "../../widgets/employer-shell";
|
||||
import { PublicShell } from "../../widgets/public-shell";
|
||||
@@ -38,120 +39,130 @@ import { SupportRoute } from "./support-route";
|
||||
|
||||
/**
|
||||
* Route tree with public pages and role-specific cabinets. Protected shells
|
||||
* restore the server session before they render any cabinet child.
|
||||
* restore the server session before they render any cabinet child. The jury
|
||||
* guide and the demonstration banner exist only in a demo build; elsewhere
|
||||
* the guide path answers with the not-found page.
|
||||
*/
|
||||
export const routes: RouteObject[] = [
|
||||
{
|
||||
element: <RootLayout />,
|
||||
errorElement: <RouteErrorPage />,
|
||||
children: [
|
||||
{
|
||||
element: <PublicShell />,
|
||||
children: [
|
||||
{ index: true, element: <WelcomePage /> },
|
||||
{ path: paths.login, element: <LoginPage /> },
|
||||
{ path: paths.register, element: <RegisterPage /> },
|
||||
{ path: paths.verifyEmail, element: <VerifyEmailPage /> },
|
||||
{ path: paths.support, element: <SupportRoute /> },
|
||||
{ path: paths.status, element: <StatusPage /> },
|
||||
{ path: "*", element: <NotFoundPage /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
path: paths.candidate.root,
|
||||
element: <CandidateShell />,
|
||||
children: [
|
||||
{
|
||||
element: <SessionGate scenario="candidate" />,
|
||||
children: [
|
||||
{ index: true, element: <CandidateHomeRoute /> },
|
||||
{ path: paths.candidate.onboarding, element: <CandidateOnboardingPage /> },
|
||||
{
|
||||
path: paths.candidate.profile,
|
||||
element: <ProfilePage />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.questionnaire,
|
||||
element: <QuestionnairePage />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.assessment,
|
||||
element: <AssessmentPage />,
|
||||
},
|
||||
{
|
||||
path: `${paths.candidate.assessment}/:attemptId`,
|
||||
element: <AssessmentAttemptPage />,
|
||||
},
|
||||
{ path: paths.candidate.results, element: <AssessmentResultsPage /> },
|
||||
{ path: `${paths.candidate.results}/:attemptId`, element: <AssessmentResultPage /> },
|
||||
{ path: paths.candidate.invitations, element: <CandidateInvitationsPage /> },
|
||||
{
|
||||
path: `${paths.candidate.invitations}/:invitationId`,
|
||||
element: <CandidateInvitationPage />,
|
||||
},
|
||||
{ path: paths.candidate.notifications, element: <CandidateNotificationsPage /> },
|
||||
{
|
||||
path: paths.candidate.privacy,
|
||||
element: <PrivacyPage />,
|
||||
},
|
||||
{ path: paths.candidate.supportCases, element: <SupportCasesPage /> },
|
||||
{ path: paths.candidate.supportNew, element: <CreateSupportCasePage /> },
|
||||
{ path: paths.candidate.supportManual, element: <ManualAssessmentPage /> },
|
||||
{
|
||||
path: `${paths.candidate.supportCases}/:caseId`,
|
||||
element: <SupportCaseDetailPage />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.candidate.root} homeLabel="В кабинет кандидата" />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: paths.employer.root,
|
||||
element: <EmployerShell />,
|
||||
children: [
|
||||
{
|
||||
element: <SessionGate scenario="employer" />,
|
||||
children: [
|
||||
{ index: true, loader: () => redirect(paths.employer.company) },
|
||||
{
|
||||
path: paths.employer.company,
|
||||
element: <CompanyPage />,
|
||||
},
|
||||
{ path: paths.employer.needs, element: <NeedListPage /> },
|
||||
{ path: `${paths.employer.needs}/new`, element: <NeedEditorPage /> },
|
||||
{ path: `${paths.employer.needs}/:needId`, element: <NeedEditorPage /> },
|
||||
{ path: paths.employer.supportCases, element: <SupportCasesPage /> },
|
||||
{ path: paths.employer.supportNew, element: <CreateSupportCasePage /> },
|
||||
{
|
||||
path: `${paths.employer.supportCases}/:caseId`,
|
||||
element: <SupportCaseDetailPage />,
|
||||
},
|
||||
{ path: paths.employer.candidates, element: <MatchesPage /> },
|
||||
{
|
||||
path: paths.employer.invitations,
|
||||
element: <PlaceholderPage screen="employerInvitations" />,
|
||||
},
|
||||
{ path: paths.employer.invitationNew, element: <InvitationComposePage /> },
|
||||
{ path: paths.employer.notifications, element: <EmployerNotificationsPage /> },
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage
|
||||
homePath={paths.employer.company}
|
||||
homeLabel="В кабинет работодателя"
|
||||
/>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
export function createRoutes(stand: StandMode = standMode): RouteObject[] {
|
||||
return [
|
||||
{
|
||||
element: <RootLayout demoStand={stand.demo} />,
|
||||
errorElement: <RouteErrorPage />,
|
||||
children: [
|
||||
{
|
||||
element: <PublicShell />,
|
||||
children: [
|
||||
{ index: true, element: <WelcomePage demoStand={stand.demo} /> },
|
||||
{ path: paths.login, element: <LoginPage /> },
|
||||
{ path: paths.register, element: <RegisterPage /> },
|
||||
{ path: paths.verifyEmail, element: <VerifyEmailPage /> },
|
||||
{ path: paths.support, element: <SupportRoute /> },
|
||||
{ path: paths.status, element: <StatusPage /> },
|
||||
...(stand.demo ? [{ path: paths.demoGuide, element: <JuryGuidePage /> }] : []),
|
||||
{ path: "*", element: <NotFoundPage /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
path: paths.candidate.root,
|
||||
element: <CandidateShell />,
|
||||
children: [
|
||||
{
|
||||
element: <SessionGate scenario="candidate" />,
|
||||
children: [
|
||||
{ index: true, element: <CandidateHomeRoute /> },
|
||||
{ path: paths.candidate.onboarding, element: <CandidateOnboardingPage /> },
|
||||
{
|
||||
path: paths.candidate.profile,
|
||||
element: <ProfilePage />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.questionnaire,
|
||||
element: <QuestionnairePage />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.assessment,
|
||||
element: <AssessmentPage />,
|
||||
},
|
||||
{
|
||||
path: `${paths.candidate.assessment}/:attemptId`,
|
||||
element: <AssessmentAttemptPage />,
|
||||
},
|
||||
{ path: paths.candidate.results, element: <AssessmentResultsPage /> },
|
||||
{
|
||||
path: `${paths.candidate.results}/:attemptId`,
|
||||
element: <AssessmentResultPage />,
|
||||
},
|
||||
{ path: paths.candidate.invitations, element: <CandidateInvitationsPage /> },
|
||||
{
|
||||
path: `${paths.candidate.invitations}/:invitationId`,
|
||||
element: <CandidateInvitationPage />,
|
||||
},
|
||||
{ path: paths.candidate.notifications, element: <CandidateNotificationsPage /> },
|
||||
{
|
||||
path: paths.candidate.privacy,
|
||||
element: <PrivacyPage />,
|
||||
},
|
||||
{ path: paths.candidate.supportCases, element: <SupportCasesPage /> },
|
||||
{ path: paths.candidate.supportNew, element: <CreateSupportCasePage /> },
|
||||
{ path: paths.candidate.supportManual, element: <ManualAssessmentPage /> },
|
||||
{
|
||||
path: `${paths.candidate.supportCases}/:caseId`,
|
||||
element: <SupportCaseDetailPage />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.candidate.root} homeLabel="В кабинет кандидата" />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: paths.employer.root,
|
||||
element: <EmployerShell />,
|
||||
children: [
|
||||
{
|
||||
element: <SessionGate scenario="employer" />,
|
||||
children: [
|
||||
{ index: true, loader: () => redirect(paths.employer.company) },
|
||||
{
|
||||
path: paths.employer.company,
|
||||
element: <CompanyPage />,
|
||||
},
|
||||
{ path: paths.employer.needs, element: <NeedListPage /> },
|
||||
{ path: `${paths.employer.needs}/new`, element: <NeedEditorPage /> },
|
||||
{ path: `${paths.employer.needs}/:needId`, element: <NeedEditorPage /> },
|
||||
{ path: paths.employer.supportCases, element: <SupportCasesPage /> },
|
||||
{ path: paths.employer.supportNew, element: <CreateSupportCasePage /> },
|
||||
{
|
||||
path: `${paths.employer.supportCases}/:caseId`,
|
||||
element: <SupportCaseDetailPage />,
|
||||
},
|
||||
{ path: paths.employer.candidates, element: <MatchesPage /> },
|
||||
{
|
||||
path: paths.employer.invitations,
|
||||
element: <PlaceholderPage screen="employerInvitations" />,
|
||||
},
|
||||
{ path: paths.employer.invitationNew, element: <InvitationComposePage /> },
|
||||
{ path: paths.employer.notifications, element: <EmployerNotificationsPage /> },
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage
|
||||
homePath={paths.employer.company}
|
||||
homeLabel="В кабинет работодателя"
|
||||
/>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export const routes: RouteObject[] = createRoutes();
|
||||
Reference in new issue
Block a user