f-1221 Add JSON import functionality for exercise creation and validation#1249
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a “paste/import question JSON” workflow to the Assignment Builder’s exercise creation/editing UI, including basic JSON parsing + per-exercise-type structural validation and accompanying unit tests.
Changes:
- Introduces
parseQuestionJsonInputandvalidateQuestionJsonForTypeutilities for parsing and validating pasted question JSON. - Adds an
ImportQuestionJsonModaland wires it intoCreateExercisefor create-mode import and edit-mode view/replace. - Adds Vitest coverage for the new utils, modal behavior, and CreateExercise integration points.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
bases/rsptx/assignment_server_api/assignment_builder/src/utils/importQuestionJson.ts |
New parsing + type-based required-field validation for imported question JSON. |
bases/rsptx/assignment_server_api/assignment_builder/src/utils/importQuestionJson.spec.ts |
Unit tests covering parse failures/success and per-type validation behavior. |
bases/rsptx/assignment_server_api/assignment_builder/src/components/routes/AssignmentBuilder/components/exercises/components/CreateExercise/CreateExercise.tsx |
Adds import/view-replace JSON entry points and applies imported JSON into the exercise factory initial data. |
bases/rsptx/assignment_server_api/assignment_builder/src/components/routes/AssignmentBuilder/components/exercises/components/CreateExercise/CreateExercise.spec.tsx |
Updates tests for new UI buttons and import application behavior. |
bases/rsptx/assignment_server_api/assignment_builder/src/components/routes/AssignmentBuilder/components/exercises/components/CreateExercise/components/ImportQuestionJsonModal.tsx |
New modal UI for selecting a type (when unlocked), pasting JSON, showing errors, and applying validated data. |
bases/rsptx/assignment_server_api/assignment_builder/src/components/routes/AssignmentBuilder/components/exercises/components/CreateExercise/components/ImportQuestionJsonModal.spec.tsx |
Modal tests for required type selection, parse errors, validation errors, and apply behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { field: "questionText", type: "string" }, | ||
| { field: "blanks", type: "array" } | ||
| ], | ||
| clickablearea: [{ field: "questionText", type: "string" }], |
| dragndrop: [ | ||
| { field: "left", type: "array" }, | ||
| { field: "right", type: "array" }, | ||
| { field: "correctAnswers", type: "array" } | ||
| ], | ||
| matching: [ | ||
| { field: "left", type: "array" }, | ||
| { field: "right", type: "array" }, | ||
| { field: "correctAnswers", type: "array" } | ||
| ], |
| { field: "questionText", type: "string" }, | ||
| { field: "blanks", type: "array" } | ||
| ], | ||
| clickablearea: [{ field: "questionText", type: "string" }], |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| dragndrop: [ | ||
| { field: "left", type: "array" }, | ||
| { field: "right", type: "array" }, | ||
| { field: "correctAnswers", type: "array" } | ||
| ], | ||
| matching: [ | ||
| { field: "left", type: "array" }, | ||
| { field: "right", type: "array" }, | ||
| { field: "correctAnswers", type: "array" } | ||
| ], |
| expect(errors).toHaveLength(3); | ||
| expect(errors.find((message) => message.includes("left"))).toMatch(/must be an array/i); | ||
| expect(errors.some((message) => message.includes("right"))).toBe(true); | ||
| expect(errors.some((message) => message.includes("correctAnswers"))).toBe(true); |
| @@ -70,31 +80,103 @@ export const CreateExercise = ({ | |||
| } | |||
| }; | |||
Code review — JSON import for exercise creationReviewed the diff ( 1. (High) Stale
|
Update: all three findings fixed
All affected suites green (159/159), with new regression tests confirmed to fail on the pre-fix code. 🤖 Generated with Claude Code |
Screen.Recording.2026-06-23.at.14.44.49.mov