-
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.
This is a feature-branch pull-request from `release/server-side-scori…
…ng` to `main` (#1926) ## Summary: This PR includes the following commits: - Numeric-Input: Extract validation from scorer (#1882) - Orderer: Extract validation out of scoring (#1869) - Sorter: Extract validation out of scoring (#1876) - Dropdown: Extract validation out of scoring (#1898) - Plotter: Extract validation out of scoring (#1899) - Radio: Extract validation out of scoring (#1902) - Categorizer: Extract validation out of scoring (#1862) Issue: <none> ## Test plan: Author: jeremywiebe Reviewers: lillialexis, #perseus Required Reviewers: Approved By: lillialexis Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (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 builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald, ✅ .github/dependabot.yml Pull Request URL: #1926
- Loading branch information
Showing
36 changed files
with
606 additions
and
205 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 | ||
--- | ||
|
||
Introduces a validation function for the dropdown widget (extracted from dropdown scoring function). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Introduces a validation function for the numeric-input widget (extracted from numeric-input scoring function). |
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 | ||
--- | ||
|
||
Introduces a validation function for the plotter widget (extracted from the scoring function). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Introduces a validation function for the radio widget (extracted from the scoring function), though not all validation logic can be extracted. |
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 `sorter` widget. This can be used to check if the user has made any changes to the sorting order, confirming whether or not the question can 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", () => { | ||
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; |
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
Oops, something went wrong.