Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric-Input: Extract validation from scorer #1882

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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