-
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
Dropdown: Extract validation out of scoring #1898
base: main
Are you sure you want to change the base?
Conversation
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (d5bb04c) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1898 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1898 |
Size Change: +118 B (+0.01%) Total Size: 1.29 MB
ℹ️ View Unchanged
|
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
it("returns invalid for user input of 0", () => { | ||
// Arrange | ||
const userInput: PerseusDropdownUserInput = { | ||
value: 0, | ||
}; | ||
const rubric: PerseusDropdownRubric = { | ||
choices: question1.widgets["dropdown 1"].options.choices, | ||
}; | ||
|
||
// Act | ||
const result = scoreDropdown(userInput, rubric); | ||
|
||
// Assert | ||
expect(result).toHaveInvalidInput(); | ||
}); |
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.
Didn't keep a check for this in scoring test since it looks like we might be doing validation before scoring (love that)
import type {PerseusDropdownUserInput} from "../../validation.types"; | ||
|
||
describe("validateDropdown", () => { | ||
it("returns invalid for invalid input (user input of 0)", () => { |
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.
Tiny improvement suggestion as 0
is the selected index. 🤷♂️ You decide. :)
it("returns invalid for invalid input (user input of 0)", () => { | |
it("returns invalid when nothing selected (user input of 0)", () => { |
* This is shown with a userInput value / index other than 0. | ||
* @param userInput |
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 would suggest removing these two lines:
The first one documents the internal implementation of the function (how it checks validation) which you can see by reading the code. It also presents something that can easily get out of sync with the code. A great guide for comments that I was told one time was "document why, not what". :)
The @param userInput
doesn't really add any value.
Summary:
To complete server-side scoring, we are separating out validation logic from scoring logic. This PR separates that logic and updates associated tests.
Issue: LEMS-2597
Test plan: