-
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.
Create helper to build public widget options for categorizer (#2092)
## Summary: This adds a function that takes categorizer's full widget options and filters out answer data. It also adds this function to the widget's widget export and adds a test confirming the function does what we expect. Issue: LEMS-2756 ## Test plan: - Confirm all checks pass - Confirm categorizer still works as expected Author: Myranae Reviewers: Myranae, handeyeco, jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x) Pull Request URL: #2092
- Loading branch information
Showing
6 changed files
with
88 additions
and
0 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 | ||
--- | ||
|
||
Introduce a widget export function to filter out scoring data from widget options. Implement this function for the categorizer widget. |
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
32 changes: 32 additions & 0 deletions
32
packages/perseus/src/widgets/categorizer/categorizer.util.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,32 @@ | ||
import getCategorizerPublicWidgetOptions from "./categorizer.util"; | ||
|
||
import type {PerseusCategorizerWidgetOptions} from "@khanacademy/perseus-core"; | ||
|
||
describe("getCategorizerPublicWidgetOptions", () => { | ||
it("returns an object without the answer data", () => { | ||
const categorizerTestWidgetOptions: PerseusCategorizerWidgetOptions = { | ||
values: [0, 1], | ||
items: ["apples", "oranges"], | ||
categories: ["citrus", "non-citrus"], | ||
randomizeItems: true, | ||
static: false, | ||
highlightLint: false, | ||
linterContext: { | ||
contentType: "type", | ||
paths: ["paths"], | ||
stack: ["stack"], | ||
}, | ||
}; | ||
|
||
const publicWidgetOptions = getCategorizerPublicWidgetOptions( | ||
categorizerTestWidgetOptions, | ||
); | ||
|
||
expect(publicWidgetOptions).toEqual({ | ||
items: ["apples", "oranges"], | ||
categories: ["citrus", "non-citrus"], | ||
randomizeItems: true, | ||
static: false, | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/perseus/src/widgets/categorizer/categorizer.util.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,29 @@ | ||
import type {PerseusCategorizerWidgetOptions} from "@khanacademy/perseus-core"; | ||
|
||
/** | ||
* For details on the individual options, see the | ||
* PerseusCategorizerWidgetOptions type | ||
*/ | ||
type CategorizerPublicWidgetOptions = { | ||
items: PerseusCategorizerWidgetOptions["items"]; | ||
categories: PerseusCategorizerWidgetOptions["categories"]; | ||
randomizeItems: PerseusCategorizerWidgetOptions["randomizeItems"]; | ||
static: PerseusCategorizerWidgetOptions["static"]; | ||
}; | ||
|
||
/** | ||
* Given a PerseusCategorizerWidgetOptions object, return a new object with only | ||
* the public options that should be exposed to the client. | ||
*/ | ||
function getCategorizerPublicWidgetOptions( | ||
options: PerseusCategorizerWidgetOptions, | ||
): CategorizerPublicWidgetOptions { | ||
return { | ||
items: options.items, | ||
categories: options.categories, | ||
randomizeItems: options.randomizeItems, | ||
static: options.static, | ||
}; | ||
} | ||
|
||
export default getCategorizerPublicWidgetOptions; |