-
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 Numeric Input (#2174)
## Summary: Adds a function that takes a Numeric Input widget's full widget options and removes correct answer information. It also adds the function to the widget's widget export and adds a test confirming the function works as expected. Issue: LEMS-2767 ## Test plan: - Confirm all checks pass - Confirm the Numeric Input widget still acts as expected Author: Myranae Reviewers: Myranae, benchristel, handeyeco, SonicScrewdriver, jeremywiebe Required Reviewers: Approved By: benchristel 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), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x) Pull Request URL: #2174
- Loading branch information
Showing
6 changed files
with
78 additions
and
1 deletion.
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 Numeric Input 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
40 changes: 40 additions & 0 deletions
40
packages/perseus-core/src/widgets/numeric-input/numeric-input-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,40 @@ | ||
import getNumericInputPublicWidgetOptions from "./numeric-input-util"; | ||
|
||
import type {PerseusNumericInputWidgetOptions} from "../../data-schema"; | ||
|
||
describe("getNumericInputPublicWidgetOptions", () => { | ||
it("should return the correct public options without any answer data", () => { | ||
// Arrange | ||
const options: PerseusNumericInputWidgetOptions = { | ||
answers: [ | ||
{ | ||
status: "correct", | ||
maxError: null, | ||
strict: false, | ||
value: 1252, | ||
simplify: "required", | ||
message: "", | ||
}, | ||
], | ||
labelText: "labelText", | ||
size: "Normal", | ||
coefficient: false, | ||
rightAlign: false, | ||
static: false, | ||
answerForms: [{simplify: "required", name: "decimal"}], | ||
}; | ||
|
||
// Act | ||
const publicWidgetOptions = getNumericInputPublicWidgetOptions(options); | ||
|
||
// Assert | ||
expect(publicWidgetOptions).toEqual({ | ||
labelText: "labelText", | ||
size: "Normal", | ||
coefficient: false, | ||
rightAlign: false, | ||
static: false, | ||
answerForms: [{simplify: "required", name: "decimal"}], | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
packages/perseus-core/src/widgets/numeric-input/numeric-input-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,27 @@ | ||
import type {PerseusNumericInputWidgetOptions} from "@khanacademy/perseus-core"; | ||
|
||
/** | ||
* For details on the individual options, see the | ||
* PerseusNumericInputWidgetOptions type | ||
*/ | ||
type NumericInputPublicWidgetOptions = { | ||
labelText?: PerseusNumericInputWidgetOptions["labelText"]; | ||
size: PerseusNumericInputWidgetOptions["size"]; | ||
coefficient: PerseusNumericInputWidgetOptions["coefficient"]; | ||
rightAlign?: PerseusNumericInputWidgetOptions["rightAlign"]; | ||
static: PerseusNumericInputWidgetOptions["static"]; | ||
answerForms?: PerseusNumericInputWidgetOptions["answerForms"]; | ||
}; | ||
|
||
/** | ||
* Given a PerseusNumericInputWidgetOptions object, return a new object with only | ||
* the public options that should be exposed to the client. | ||
*/ | ||
function getNumericInputPublicWidgetOptions( | ||
options: PerseusNumericInputWidgetOptions, | ||
): NumericInputPublicWidgetOptions { | ||
const {answers: _, ...publicWidgetOptions} = options; | ||
return publicWidgetOptions; | ||
} | ||
|
||
export default getNumericInputPublicWidgetOptions; |
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