From 9426509cdcdc9c51dfd957e0e51f6bac0e11ffe5 Mon Sep 17 00:00:00 2001 From: Tamara <60857422+Myranae@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:28:54 -0500 Subject: [PATCH] Refine Matrix's Rubric and UserInput types (#1760) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: As part of the Server Side Scoring project, this refactors Matrix's Rubric type to contain only what is necessary for scoring. It also updates its UserInput type to reference Rubric, since both contain the same type of data. Finally, Matrix's validator tests are updated to reflect the new Rubric type. Issue: LEMS-2469 ## Test plan: - Confirm all checks pass - Confirm Matrix still works as expected in Storybook Author: Myranae Reviewers: handeyeco Required Reviewers: Approved By: handeyeco Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/1760 --- .changeset/twelve-beans-raise.md | 5 ++++ packages/perseus/src/validation.types.ts | 9 ++++--- .../widgets/matrix/matrix-validator.test.ts | 25 ------------------- .../src/widgets/matrix/matrix-validator.ts | 4 +-- 4 files changed, 13 insertions(+), 30 deletions(-) create mode 100644 .changeset/twelve-beans-raise.md 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 da31a9e99a..cb1747f348 100644 --- a/packages/perseus/src/validation.types.ts +++ b/packages/perseus/src/validation.types.ts @@ -7,7 +7,7 @@ import type { PerseusGraphType, PerseusGroupWidgetOptions, PerseusMatcherWidgetOptions, - PerseusMatrixWidgetOptions, + PerseusMatrixWidgetAnswers, PerseusNumberLineWidgetOptions, PerseusNumericInputAnswer, PerseusOrdererWidgetOptions, @@ -119,10 +119,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);