-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Orderer: Extract validation out of scoring (#1869)
## Summary: To complete server-side scoring, we are separating out validation logic from scoring logic. This separates that logic and updates associated tests. Issue: LEMS-2603 ## Test plan: - Confirm all checks pass - Confirm widget still works as expected Author: Myranae Reviewers: jeremywiebe, handeyeco, Myranae Required Reviewers: Approved By: jeremywiebe, handeyeco Checks: ✅ 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), ✅ 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), ✅ 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: #1869
- Loading branch information
Showing
5 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Split out validation function for the `orderer` widget. This can be used to check if the user has ordered at least one option, confirming the question is ready to be scored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/perseus/src/widgets/orderer/validate-orderer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import validateOrderer from "./validate-orderer"; | ||
|
||
import type {PerseusOrdererUserInput} from "../../validation.types"; | ||
|
||
describe("validateOrderer", () => { | ||
it("is invalid when the user has not started ordering the options and current is empty", () => { | ||
// Arrange | ||
const userInput: PerseusOrdererUserInput = { | ||
current: [], | ||
}; | ||
|
||
// Act | ||
const result = validateOrderer(userInput); | ||
|
||
// Assert | ||
expect(result).toHaveInvalidInput(); | ||
}); | ||
|
||
it("is null when the user has started ordering the options and current has at least one option", () => { | ||
// Arrange | ||
const userInput: PerseusOrdererUserInput = { | ||
current: ["$10.9$"], | ||
}; | ||
|
||
// Act | ||
const result = validateOrderer(userInput); | ||
|
||
// Assert | ||
expect(result).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type {PerseusScore} from "../../types"; | ||
import type {PerseusOrdererUserInput} from "../../validation.types"; | ||
|
||
/** | ||
* Checks user input from the orderer widget to see if the user has started | ||
* ordering the options, making the widget scorable. | ||
* @param userInput | ||
* @see `scoreOrderer` for more details. | ||
*/ | ||
function validateOrderer( | ||
userInput: PerseusOrdererUserInput, | ||
): Extract<PerseusScore, {type: "invalid"}> | null { | ||
if (userInput.current.length === 0) { | ||
return { | ||
type: "invalid", | ||
message: null, | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export default validateOrderer; |