-
Notifications
You must be signed in to change notification settings - Fork 359
Add validateUserInput for client-side validation #3089
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
Draft
handeyeco
wants to merge
7
commits into
main
Choose a base branch
from
LEMS-3731/client-side-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.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1248a50
[LEMS-3731/client-side-validation] add validateUserInput
handeyeco 900e902
[LEMS-3731/client-side-validation] cleanup
handeyeco 5c5db1c
[LEMS-3731/client-side-validation] more cleanup
handeyeco 827a400
[LEMS-3731/client-side-validation] more cleanup
handeyeco 9f2eaf6
[LEMS-3731/client-side-validation] abstract out helpers
handeyeco 84126b6
[LEMS-3731/client-side-validation] docs(changeset): Add new validateU…
handeyeco 79d2b77
[LEMS-3731/client-side-validation] Merge branch 'main' into LEMS-3731…
handeyeco 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 hidden or 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,6 @@ | ||
| --- | ||
| "@khanacademy/perseus-core": major | ||
| "@khanacademy/perseus-score": minor | ||
| --- | ||
|
|
||
| Add new validateUserInput function to perseus-score |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,124 +4,9 @@ import { | |
| type UserInputMap, | ||
| } from "@khanacademy/perseus-core"; | ||
|
|
||
| import {flattenScores, scorePerseusItem, scoreWidgetsFunctional} from "./score"; | ||
| import {scorePerseusItem, scoreWidgetsFunctional} from "./score"; | ||
| import {getExpressionWidget, getTestDropdownWidget} from "./util/test-helpers"; | ||
|
|
||
| describe("flattenScores", () => { | ||
|
Contributor
Author
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. Moved |
||
| it("defaults to an empty score", () => { | ||
| const result = flattenScores({}); | ||
|
|
||
| expect(result).toHaveBeenAnsweredCorrectly({shouldHavePoints: false}); | ||
| expect(result).toEqual({ | ||
| type: "points", | ||
| total: 0, | ||
| earned: 0, | ||
| message: null, | ||
| }); | ||
| }); | ||
|
|
||
| it("defaults to single score if there is only one", () => { | ||
| const result = flattenScores({ | ||
| "radio 1": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toHaveBeenAnsweredCorrectly(); | ||
| expect(result).toEqual({ | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }); | ||
| }); | ||
|
|
||
| it("returns an invalid score if any are invalid", () => { | ||
| const result = flattenScores({ | ||
| "radio 1": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| "radio 2": { | ||
| type: "invalid", | ||
| message: null, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toHaveInvalidInput(); | ||
| expect(result).toEqual({ | ||
| type: "invalid", | ||
| message: null, | ||
| }); | ||
| }); | ||
|
|
||
| it("tallies scores if multiple widgets have points", () => { | ||
| const result = flattenScores({ | ||
| "radio 1": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| "radio 2": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| "radio 3": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toHaveBeenAnsweredCorrectly(); | ||
| expect(result).toEqual({ | ||
| type: "points", | ||
| total: 3, | ||
| earned: 3, | ||
| message: null, | ||
| }); | ||
| }); | ||
|
|
||
| it("doesn't count incorrect widgets", () => { | ||
| const result = flattenScores({ | ||
| "radio 1": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| "radio 2": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 1, | ||
| message: null, | ||
| }, | ||
| "radio 3": { | ||
| type: "points", | ||
| total: 1, | ||
| earned: 0, | ||
| message: null, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| type: "points", | ||
| total: 3, | ||
| earned: 2, | ||
| message: null, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("scoreWidgetsFunctional", () => { | ||
| it("returns an empty object when there's no widgets", () => { | ||
| // Arrange / Act | ||
|
|
@@ -432,6 +317,7 @@ describe("scorePerseusItem", () => { | |
| const score = scorePerseusItem(item, userInputMap, "en"); | ||
|
|
||
| // Assert: | ||
| expect(score).toHaveInvalidInput(); | ||
| expect(score).toEqual({type: "invalid", message: null}); | ||
| }); | ||
|
|
||
|
|
@@ -454,6 +340,7 @@ describe("scorePerseusItem", () => { | |
| ); | ||
|
|
||
| // Assert | ||
| expect(score).toHaveInvalidInput(); | ||
| expect(score).toEqual({type: "invalid", message: null}); | ||
| }); | ||
|
|
||
|
|
@@ -478,6 +365,7 @@ describe("scorePerseusItem", () => { | |
| ); | ||
|
|
||
| // Assert | ||
| expect(score).toHaveBeenAnsweredCorrectly(); | ||
| expect(score).toEqual({ | ||
| type: "points", | ||
| total: 2, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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 just didn't see the point of having this type and it was keeping me from reusing helpers between scoring and validation logic. Ideally in the future we could just have a AnswerfulPerseusItem and AnswerlessPerseusItem or something.