diff --git a/.changeset/twelve-beans-raise.md b/.changeset/twelve-beans-raise.md new file mode 100644 index 0000000000..e704b05560 --- /dev/null +++ b/.changeset/twelve-beans-raise.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/perseus": patch +--- + +Refine Matrix's Rubric and UserInput types diff --git a/packages/perseus/src/validation.types.ts b/packages/perseus/src/validation.types.ts index f6885891e2..f330816135 100644 --- a/packages/perseus/src/validation.types.ts +++ b/packages/perseus/src/validation.types.ts @@ -12,7 +12,7 @@ import type { PerseusImageWidgetOptions, PerseusInteractionWidgetOptions, PerseusMatcherWidgetOptions, - PerseusMatrixWidgetOptions, + PerseusMatrixWidgetAnswers, PerseusNumberLineWidgetOptions, PerseusNumericInputWidgetOptions, PerseusOrdererWidgetOptions, @@ -138,10 +138,13 @@ export type PerseusMatcherUserInput = { right: ReadonlyArray; }; -export type PerseusMatrixRubric = PerseusMatrixWidgetOptions; +export type PerseusMatrixRubric = { + // A data matrix representing the "correct" answers to be entered into the matrix + answers: PerseusMatrixWidgetAnswers; +}; export type PerseusMatrixUserInput = { - answers: ReadonlyArray>; + answers: PerseusMatrixRubric["answers"]; }; export type PerseusNumberLineRubric = PerseusNumberLineWidgetOptions & { diff --git a/packages/perseus/src/widgets/matrix/matrix-validator.test.ts b/packages/perseus/src/widgets/matrix/matrix-validator.test.ts index 5e4af99f0d..821045c1b0 100644 --- a/packages/perseus/src/widgets/matrix/matrix-validator.test.ts +++ b/packages/perseus/src/widgets/matrix/matrix-validator.test.ts @@ -11,16 +11,11 @@ describe("matrixValidator", () => { it("can be answered correctly", () => { // Arrange const rubric: PerseusMatrixRubric = { - prefix: "", - suffix: "", answers: [ [0, 1, 2], [3, 4, 5], [6, 7, 8], ], - cursorPosition: [], - matrixBoardSize: [], - static: false, }; const userInput: PerseusMatrixUserInput = { @@ -37,16 +32,11 @@ describe("matrixValidator", () => { it("can be answered incorrectly", () => { // Arrange const rubric: PerseusMatrixRubric = { - prefix: "", - suffix: "", answers: [ [0, 1, 2], [3, 4, 5], [6, 7, 8], ], - cursorPosition: [], - matrixBoardSize: [], - static: false, }; const userInput: PerseusMatrixUserInput = { @@ -67,16 +57,11 @@ describe("matrixValidator", () => { it("is invalid when there's an empty cell: null", () => { // Arrange const rubric: PerseusMatrixRubric = { - prefix: "", - suffix: "", answers: [ [0, 1, 2], [3, 4, 5], [6, 7, 8], ], - cursorPosition: [], - matrixBoardSize: [], - static: false, }; const userInput: PerseusMatrixUserInput = { @@ -100,16 +85,11 @@ describe("matrixValidator", () => { it("is invalid when there's an empty cell: empty string", () => { // Arrange const rubric: PerseusMatrixRubric = { - prefix: "", - suffix: "", answers: [ [0, 1, 2], [3, 4, 5], [6, 7, 8], ], - cursorPosition: [], - matrixBoardSize: [], - static: false, }; const userInput: PerseusMatrixUserInput = { @@ -133,16 +113,11 @@ describe("matrixValidator", () => { it("is considered incorrect when the size is wrong", () => { // Arrange const rubric: PerseusMatrixRubric = { - prefix: "", - suffix: "", answers: [ [0, 1, 2], [3, 4, 5], [6, 7, 8], ], - cursorPosition: [], - matrixBoardSize: [], - static: false, }; const correctUserInput: PerseusMatrixUserInput = { diff --git a/packages/perseus/src/widgets/matrix/matrix-validator.ts b/packages/perseus/src/widgets/matrix/matrix-validator.ts index 599224d5f6..0b7f48a8ea 100644 --- a/packages/perseus/src/widgets/matrix/matrix-validator.ts +++ b/packages/perseus/src/widgets/matrix/matrix-validator.ts @@ -12,12 +12,12 @@ import type { } from "../../validation.types"; function matrixValidator( - state: PerseusMatrixUserInput, + userInput: PerseusMatrixUserInput, rubric: PerseusMatrixRubric, strings: PerseusStrings, ): PerseusScore { const solution = rubric.answers; - const supplied = state.answers; + const supplied = userInput.answers; const solutionSize = getMatrixSize(solution); const suppliedSize = getMatrixSize(supplied);