Skip to content

Commit

Permalink
Numeric-Input: Extract validation from scorer (#1882)
Browse files Browse the repository at this point in the history
## Summary:

This PR extracts validation from the `numeric-input`'s scorer function. In reality, it's an empty function, but it follows our conventions for having the scorer call a validator first. I've created the standard tests to ensure that scorer calls the validator.

Issue: LEMS-2607

## Test plan:

`yarn test`
`yarn typecheck`

Author: jeremywiebe

Reviewers: handeyeco, jeremywiebe, Myranae

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ gerald, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (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), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1882
  • Loading branch information
jeremywiebe authored Nov 21, 2024
1 parent 55a5321 commit 40d2ebb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-avocados-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

Introduces a validation function for the numeric-input widget (extracted from numeric-input scoring function).
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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.",
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 40d2ebb

Please sign in to comment.