-
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
Categorizer: Extract validation out of scoring #1862
Open
Myranae
wants to merge
11
commits into
main
Choose a base branch
from
tb/LEMS-2596/categorizer-split-out-validation-with-rubric
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.
+115
−39
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e6f0b85
Split validation tests from scoring tests
Myranae 4e1f7b2
Put validation logic in own function and call it
Myranae e2552af
Add changeset
Myranae 52e6aad
Pull values (the answers) out of the validation
Myranae 28766a3
Update validationResult to validationError
Myranae 27c222e
Add test for null return
Myranae c77806a
Simplify validation check
Myranae 539b8cc
Add validation type
Myranae 109df1b
Update validator to use validateData instead of rubric
Myranae 261fcf1
Rename rubric + validation data to scoringData
Myranae 9437cfd
Add documentation to validate function
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 `categorizer` widget. This can be used to check if the user selected an answer for every row, 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
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
27 changes: 14 additions & 13 deletions
27
packages/perseus/src/widgets/categorizer/score-categorizer.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
43 changes: 43 additions & 0 deletions
43
packages/perseus/src/widgets/categorizer/validate-categorizer.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,43 @@ | ||
import {mockStrings} from "../../strings"; | ||
|
||
import validateCategorizer from "./validate-categorizer"; | ||
|
||
import type {PerseusCategorizerValidationData} from "../../validation.types"; | ||
|
||
describe("validateCategorizer", () => { | ||
it("tells the learner its not complete if not selected", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test case for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
const validationData: PerseusCategorizerValidationData = { | ||
items: ["apples", "oranges"], | ||
}; | ||
|
||
const userInput = { | ||
values: [2], | ||
} as const; | ||
const score = validateCategorizer( | ||
userInput, | ||
validationData, | ||
mockStrings, | ||
); | ||
|
||
expect(score).toHaveInvalidInput( | ||
"Make sure you select something for every row.", | ||
); | ||
}); | ||
|
||
it("returns null if the userInput is valid", () => { | ||
const validationData: PerseusCategorizerValidationData = { | ||
items: ["apples", "oranges"], | ||
}; | ||
|
||
const userInput = { | ||
values: [2, 4], | ||
} as const; | ||
const score = validateCategorizer( | ||
userInput, | ||
validationData, | ||
mockStrings, | ||
); | ||
|
||
expect(score).toBeNull(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/perseus/src/widgets/categorizer/validate-categorizer.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,34 @@ | ||
import type {PerseusStrings} from "../../strings"; | ||
import type {PerseusScore} from "../../types"; | ||
import type { | ||
PerseusCategorizerUserInput, | ||
PerseusCategorizerValidationData, | ||
} from "../../validation.types"; | ||
|
||
/** | ||
* Checks userInput from the categorizer widget to see if the user has selected | ||
* a category for each item. | ||
* @param userInput - The user's input corresponding to an array of indices that | ||
* represent the selected category for each row/item. | ||
* @param validationData - An array of strings corresponding to each row/item | ||
* @param strings - Used to provide a validation message | ||
*/ | ||
function validateCategorizer( | ||
userInput: PerseusCategorizerUserInput, | ||
validationData: PerseusCategorizerValidationData, | ||
strings: PerseusStrings, | ||
): Extract<PerseusScore, {type: "invalid"}> | null { | ||
const incomplete = validationData.items.some( | ||
(_, i) => userInput.values[i] == null, | ||
); | ||
|
||
if (incomplete) { | ||
return { | ||
type: "invalid", | ||
message: strings.invalidSelection, | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
export default validateCategorizer; |
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.
This comment was marked as outdated.
Sorry, something went wrong.
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.
We chatted on Slack, but we agreed to model the Rubric like this:
We also agreed to rename the term
Rubric
toScoringData
in the Server-Side Scoring area in a future task. :)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.
The above comment I made was from an older version of the code. I updated Rubric to be the following:
Is it also okay to rename Rubric as we go and to use the ticket for renaming any we missed? It helps my mental model to have the names updated while I'm working, but I can totally leave the name change to the very end if it's preferred to do them all at once. And if it's preferred to do them all at once, should I revert the name change in this PR?
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 started renaming things to
ScoringData
in one of my PRs. Then as I thought about it, I thought it might be more confusing to have a partial migration state inmain
. I was going to leave things as "Rubric" until we're done this pass of validation splitting and then we could do a single pass over everything to update our terms from Rubric to ScoringData. But I don't think it's a huge deal either way. :)