feat(assessment): keep real attempts in fullscreen and protect the task text
This commit is contained in:
1 parent
56dcf32f8c
commit
efa41d5967
46 files changed
+1940
-72
No files matched your search
@@ -0,0 +1,69 @@
|
||||
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(
|
||||
<AnswerForm
|
||||
attemptId="attempt"
|
||||
item={answered}
|
||||
isSaving={false}
|
||||
retryable={false}
|
||||
errorMessage={null}
|
||||
concealed={concealed}
|
||||
onSubmit={() => 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");
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,11 @@ type AnswerFormProps = {
|
||||
isSaving: boolean;
|
||||
retryable: boolean;
|
||||
errorMessage: string | null;
|
||||
/**
|
||||
* Renders nothing while the task is hidden. The form stays mounted, so the
|
||||
* draft in its state survives and the task content is not in the page.
|
||||
*/
|
||||
concealed?: boolean;
|
||||
onSubmit: (draft: AnswerDraft) => void;
|
||||
onRetry: () => void;
|
||||
};
|
||||
@@ -21,6 +26,7 @@ export function AnswerForm({
|
||||
isSaving,
|
||||
retryable,
|
||||
errorMessage,
|
||||
concealed = false,
|
||||
onSubmit,
|
||||
onRetry,
|
||||
}: AnswerFormProps) {
|
||||
@@ -67,6 +73,8 @@ export function AnswerForm({
|
||||
option.click();
|
||||
}
|
||||
|
||||
if (concealed) return null;
|
||||
|
||||
return (
|
||||
<form className={styles.form} onSubmit={submit} onKeyDown={handleKeyDown}>
|
||||
<fieldset
|
||||
@@ -313,6 +321,8 @@ function AnswerFields({ item, draft, setDraft }: AnswerFieldsProps) {
|
||||
autoComplete="off"
|
||||
maxLength={content.max_source_length}
|
||||
name="practice-answer"
|
||||
// A code editor: pasting is allowed, and the page records its size as a signal.
|
||||
data-paste="allowed"
|
||||
rows={16}
|
||||
spellCheck={false}
|
||||
value={draft.format === "practice" ? draft.sourceCode : ""}
|
||||
|
||||
Reference in new issue
Block a user