import { renderToStaticMarkup } from "react-dom/server"; import { describe, expect, it } from "vitest"; import type { CandidateQuestionnaire, SpecializationCatalog } from "../../../shared/api/schemas"; import { changeQuestionnaireSpecialization, patchQuestionnaireSpecialization, toQuestionnaireDraft, } from "../model/questionnaire-form"; import { QuestionnaireForm } from "./questionnaire-form"; const catalog: SpecializationCatalog = { directions: [ { code: "development", title: "Разработка", specializations: [ { code: "backend", title: "Backend", test_availability: { status: "available", grades: ["junior"], task_languages: ["python", "go"], note: null, }, }, ], }, { code: "data", title: "Данные", specializations: [ { code: "ds_ml", title: "DS/ML", test_availability: { status: "in_development", grades: [], task_languages: [], note: "Банк заданий готовится.", }, }, ], }, ], grades: [ { code: "intern", title: "Стажер" }, { code: "junior", title: "Junior" }, { code: "middle", title: "Middle" }, { code: "senior", title: "Senior" }, ], }; const emptyQuestionnaire: CandidateQuestionnaire = { version: 0, specializations: [], work_context: null, updated_at: null, }; function renderQuestionnaireForm(specialization: "backend" | "ds_ml"): string { const base = toQuestionnaireDraft(emptyQuestionnaire); const first = base.specializations[0]; if (!first) throw new Error("Expected the questionnaire to have one editing row."); const selected = changeQuestionnaireSpecialization(base, first.id, specialization); const draft = patchQuestionnaireSpecialization(selected, first.id, { selfAssessedGrade: specialization === "backend" ? "junior" : "senior", taskLanguages: specialization === "backend" ? ["go"] : [], }); return renderToStaticMarkup( undefined} onIssue={() => undefined} onSubmit={() => undefined} />, ); } describe("questionnaire form", () => { it("renders current Backend task language and grade options with associated hints", () => { const markup = renderQuestionnaireForm("backend"); const ids = new Set([...markup.matchAll(/\sid="([^"]+)"/g)].map((match) => match[1])); const descriptions = [...markup.matchAll(/aria-describedby="([^"]+)"/g)].flatMap((match) => (match[1] ?? "").split(/\s+/), ); expect(markup).toContain("Проверка опубликована для уровней: Junior."); expect(markup).toContain("Python"); expect(markup).toContain("Go"); expect(markup).toContain("При смене выбора самооценка"); expect(descriptions.length).toBeGreaterThan(0); expect(descriptions.every((id) => ids.has(id))).toBe(true); expect(markup).not.toMatch(/ФСП|confirmed_grade|подтвержденный грейд/i); }); it("allows an in-development specialization as a self-assessed claim without an assessment action", () => { const markup = renderQuestionnaireForm("ds_ml"); expect(markup).toContain("Проверка: в разработке"); expect(markup).toContain( "Эту специализацию можно сохранить. Начать проверку по ней пока нельзя.", ); expect(markup).toContain("Банк заданий готовится."); expect(markup).toContain('value="senior" selected=""'); expect(markup).not.toMatch(/]*>[^<]*(?:Перейти|Начать) проверку/); }); it("shows the first of four steps and keeps the other steps mounted but hidden", () => { const markup = renderQuestionnaireForm("backend"); expect(markup).toContain("Шаг 1 из 4"); expect(markup).toMatch(/]*aria-current="step"[^>]*>[\s\S]*?Направления/); // Every step is in the markup, so field ids and server errors stay valid; // only the first one is shown. expect(markup.match(/]*hidden=""/g)).toHaveLength(3); expect(markup).toContain("Моя оценка уровня"); expect(markup).toContain(">Далее<"); expect(markup).not.toContain("Сохранить анкету"); }); });