-
Notifications
You must be signed in to change notification settings - Fork 351
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 Sorter (#2154)
## Summary: Adds a function that takes Sorter's full widget options and filters out answer data. It also adds this function to Sorter's widget export and adds a test confirming the function does what is expected. Issue: LEMS-2765 ## Test plan: - Confirm all checks pass - Confirm Sorter still works as expected Author: Myranae Reviewers: Myranae, benchristel, handeyeco, jeremywiebe Required Reviewers: Approved By: jeremywiebe 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), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: #2154
- Loading branch information
Showing
6 changed files
with
69 additions
and
2 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,6 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
"@khanacademy/perseus-core": minor | ||
--- | ||
|
||
Implement a widget export function to filter out rubric data from widget options for the Sorter 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
24 changes: 24 additions & 0 deletions
24
packages/perseus-core/src/widgets/sorter/sorter-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,24 @@ | ||
import getSorterPublicWidgetOptions from "./sorter-util"; | ||
|
||
import type {PerseusSorterWidgetOptions} from "../../data-schema"; | ||
|
||
describe("getSorterPublicWidgetOptions", () => { | ||
it("should return the correct public options without any answer data", () => { | ||
// Arrange | ||
const options: PerseusSorterWidgetOptions = { | ||
correct: ["$15$ grams", "$55$ grams", "$0.005$ kilograms"], | ||
layout: "horizontal", | ||
padding: true, | ||
}; | ||
|
||
// Act | ||
const publicWidgetOptions = getSorterPublicWidgetOptions(options); | ||
|
||
// Assert | ||
expect(publicWidgetOptions).toEqual({ | ||
correct: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"], | ||
layout: "horizontal", | ||
padding: true, | ||
}); | ||
}); | ||
}); |
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,30 @@ | ||
import type {PerseusSorterWidgetOptions} from "@khanacademy/perseus-core"; | ||
|
||
/** | ||
* For details on the individual options, see the | ||
* PerseusSorterWidgetOptions type | ||
*/ | ||
type SorterPublicWidgetOptions = { | ||
correct: PerseusSorterWidgetOptions["correct"]; | ||
padding: PerseusSorterWidgetOptions["padding"]; | ||
layout: PerseusSorterWidgetOptions["layout"]; | ||
}; | ||
|
||
/** | ||
* Given a PerseusSorterWidgetOptions object, return a new object with only | ||
* the public options that should be exposed to the client. | ||
*/ | ||
function getSorterPublicWidgetOptions( | ||
options: PerseusSorterWidgetOptions, | ||
): SorterPublicWidgetOptions { | ||
return { | ||
// Note(Tamara): This does not provide correct answer information any longer. | ||
// To maintain compatibility with the original widget options, we are | ||
// keeping the key the same. Represents initial state of the cards here. | ||
correct: options.correct.slice().sort(), | ||
padding: options.padding, | ||
layout: options.layout, | ||
}; | ||
} | ||
|
||
export default getSorterPublicWidgetOptions; |
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