-
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 Dropdown (#2166)
## Summary: Adds a function that takes Dropdown's full widget options and filters out answer data. It also adds this function to Dropdown's widget export and adds a test confirming the function does what is expected. Issue: LEMS-2757 ## Test plan: - Confirm all checks pass - Confirm Dropdown still works as expected Author: Myranae Reviewers: benchristel, jeremywiebe, handeyeco Required Reviewers: Approved By: benchristel 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), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x) Pull Request URL: #2166
- Loading branch information
Showing
6 changed files
with
74 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,6 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
"@khanacademy/perseus-core": minor | ||
--- | ||
|
||
Implement a widget export function to filter out rubric data from widget options for the Dropdown 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
32 changes: 32 additions & 0 deletions
32
packages/perseus-core/src/widgets/dropdown/dropdown-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 getDropdownPublicWidgetOptions from "./dropdown-util"; | ||
|
||
import type {PerseusDropdownWidgetOptions} from "../../data-schema"; | ||
|
||
describe("getDropdownPublicWidgetOptions", () => { | ||
it("should return the correct public options without any answer data", () => { | ||
// Arrange | ||
const options: PerseusDropdownWidgetOptions = { | ||
choices: [ | ||
{content: "1", correct: false}, | ||
{content: "2", correct: false}, | ||
{content: "3", correct: true}, | ||
], | ||
placeholder: "Select an option", | ||
static: false, | ||
visibleLabel: "Test Label", | ||
ariaLabel: "Test Aria Label", | ||
}; | ||
|
||
// Act | ||
const publicWidgetOptions = getDropdownPublicWidgetOptions(options); | ||
|
||
// Assert | ||
expect(publicWidgetOptions).toEqual({ | ||
choices: [{content: "1"}, {content: "2"}, {content: "3"}], | ||
placeholder: "Select an option", | ||
static: false, | ||
visibleLabel: "Test Label", | ||
ariaLabel: "Test Aria Label", | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/perseus-core/src/widgets/dropdown/dropdown-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,31 @@ | ||
import type {PerseusDropdownWidgetOptions} from "@khanacademy/perseus-core"; | ||
|
||
/** | ||
* For details on the individual options, see the | ||
* PerseusDropdownWidgetOptions type | ||
*/ | ||
type DropdownPublicWidgetOptions = { | ||
choices: ReadonlyArray<{content: string}>; | ||
placeholder: PerseusDropdownWidgetOptions["placeholder"]; | ||
static: PerseusDropdownWidgetOptions["static"]; | ||
visibleLabel?: PerseusDropdownWidgetOptions["visibleLabel"]; | ||
ariaLabel?: PerseusDropdownWidgetOptions["ariaLabel"]; | ||
}; | ||
|
||
/** | ||
* Given a PerseusDropdownWidgetOptions object, return a new object with only | ||
* the public options that should be exposed to the client. | ||
*/ | ||
function getDropdownPublicWidgetOptions( | ||
options: PerseusDropdownWidgetOptions, | ||
): DropdownPublicWidgetOptions { | ||
return { | ||
choices: options.choices.map((choice) => ({content: choice.content})), | ||
placeholder: options.placeholder, | ||
static: options.static, | ||
visibleLabel: options.visibleLabel, | ||
ariaLabel: options.ariaLabel, | ||
}; | ||
} | ||
|
||
export default getDropdownPublicWidgetOptions; |
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