import { renderToStaticMarkup } from "react-dom/server"; import { describe, expect, it } from "vitest"; import type { AssessmentItem } from "../../../shared/api/schemas"; import { AnswerForm } from "./answer-form"; const item = { id: "01928f7a-4a10-7b2c-9d3e-5f6a7b8c9d02", sequence: 1, prompt: "Выберите вариант", content: { format: "choice", multiple: false, options: [ { id: "a", text: "Первый вариант" }, { id: "b", text: "Второй вариант" }, ], }, } satisfies AssessmentItem; const numberItem = { id: "01928f7a-4a10-7b2c-9d3e-5f6a7b8c9d03", sequence: 2, prompt: "Сколько", content: { format: "number", unit: null }, } satisfies AssessmentItem; const practiceItem = { id: "01928f7a-4a10-7b2c-9d3e-5f6a7b8c9d04", sequence: 3, prompt: "Решите", content: { format: "practice", languages: ["python"], public_examples: [], max_source_length: 4096, }, } satisfies AssessmentItem; function render(concealed: boolean, answered: AssessmentItem = item): string { return renderToStaticMarkup( undefined} onRetry={() => undefined} />, ); } describe("answer form", () => { it("shows the options and the submit button", () => { const markup = render(false); expect(markup).toContain("Первый вариант"); expect(markup).toContain("Отправить ответ"); }); it("renders nothing while concealed, so no option text stays in the page", () => { expect(render(true)).toBe(""); }); it("marks only the code editor as a field where pasting is allowed", () => { expect(render(false, practiceItem)).toContain('data-paste="allowed"'); expect(render(false, numberItem)).not.toContain("data-paste"); }); });