-
Notifications
You must be signed in to change notification settings - Fork 352
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
Orderer: Extract validation out of scoring #1869
Open
Myranae
wants to merge
11
commits into
main
Choose a base branch
from
tb/LEMS-2603/orderer-split-out-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−12
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f8bf0cb
Remove usage of underscore
Myranae 149e71c
Split out validation logic into own function
Myranae b77fec0
Split out validation tests
Myranae fe14fbb
Add changeset
Myranae ca822d6
Merge branch 'main' into tb/LEMS-2603/orderer-split-out-validation
Myranae d8480f1
Retain test to confirm scoring function can handle invalid validation
Myranae bd03247
Switch to default export for consistency
Myranae b203d48
Add tests confirming scoring correctly handles validation results
Myranae 74bf0e6
Add comment to validation function
Myranae afbe43c
Update import syntax
Myranae 1e6f37f
Fix typo in doc comment
Myranae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ | ||
import type {PerseusScore} from "../../types"; | ||
import type {PerseusOrdererUserInput} from "../../validation.types"; | ||
|
||
export function validateOrderer( | ||
userInput: PerseusOrdererUserInput, | ||
): Extract<PerseusScore, {type: "invalid"}> | null { | ||
if (userInput.current.length === 0) { | ||
return { | ||
type: "invalid", | ||
message: null, | ||
}; | ||
} | ||
|
||
return null; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth retaining a unit test for the scorer that makes sure the score is
"invalid"
for this case. This ensures we're correctly calling and handling the result of the validator in the scorer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this back :) Do you think all scoring functions should retain a test confirming it can handle validation results? Also, I remember hearing about how it's ideal to make sure tests don't overlap so that multiple tests don't fail as a result of one piece of code failing (for example, validation). Is that why you mocked this out in your PRs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the test to mock the validation and added a test confirming scoring handles passing validation with validation mocked.