diff --git a/.changeset/honest-avocados-accept.md b/.changeset/honest-avocados-accept.md new file mode 100644 index 0000000000..4d7d3129cf --- /dev/null +++ b/.changeset/honest-avocados-accept.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/perseus": minor +--- + +Introduces a validation function for the numeric-input widget (extracted from numeric-input scoring function). diff --git a/packages/perseus/src/widgets/numeric-input/score-numeric-input.test.ts b/packages/perseus/src/widgets/numeric-input/score-numeric-input.test.ts index c6ee90ec2c..de2a226656 100644 --- a/packages/perseus/src/widgets/numeric-input/score-numeric-input.test.ts +++ b/packages/perseus/src/widgets/numeric-input/score-numeric-input.test.ts @@ -28,11 +28,11 @@ describe("static function validate", () => { coefficient: true, }; - const useInput = { + const userInput = { currentValue: "1", } as const; - const score = scoreNumericInput(useInput, rubric, mockStrings); + const score = scoreNumericInput(userInput, rubric, mockStrings); expect(score).toHaveBeenAnsweredCorrectly(); }); @@ -52,11 +52,11 @@ describe("static function validate", () => { coefficient: true, }; - const useInput = { + const userInput = { currentValue: "sadasdfas", } as const; - const score = scoreNumericInput(useInput, rubric, mockStrings); + const score = scoreNumericInput(userInput, rubric, mockStrings); expect(score).toHaveInvalidInput( "We could not understand your answer. Please check your answer for extra text or symbols.", @@ -143,11 +143,11 @@ describe("static function validate", () => { coefficient: true, }; - const useInput = { + const userInput = { currentValue: "1.0", } as const; - const score = scoreNumericInput(useInput, rubric, mockStrings); + const score = scoreNumericInput(userInput, rubric, mockStrings); expect(score).toHaveBeenAnsweredCorrectly(); }); @@ -167,11 +167,11 @@ describe("static function validate", () => { coefficient: true, }; - const useInput = { + const userInput = { currentValue: "1.3", } as const; - const score = scoreNumericInput(useInput, rubric, mockStrings); + const score = scoreNumericInput(userInput, rubric, mockStrings); expect(score).toHaveBeenAnsweredIncorrectly(); }); @@ -191,11 +191,11 @@ describe("static function validate", () => { coefficient: true, }; - const useInput = { + const userInput = { currentValue: "1.12", } as const; - const score = scoreNumericInput(useInput, rubric, mockStrings); + const score = scoreNumericInput(userInput, rubric, mockStrings); expect(score).toHaveBeenAnsweredCorrectly(); }); diff --git a/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts b/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts index 46a98eaf12..d4637185ec 100644 --- a/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts +++ b/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts @@ -61,7 +61,7 @@ export function maybeParsePercentInput( return value / 100; } - // Otherwise, we return input valuÄe (number) stripped of the "%". + // Otherwise, we return input value (number) stripped of the "%". return value; }