-
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.
Browse files
Browse the repository at this point in the history
…tcher-split # Conflicts: # packages/perseus-core/src/index.ts # packages/perseus/src/types.ts # packages/perseus/src/widgets/sorter/sorter.tsx
- Loading branch information
Showing
10 changed files
with
143 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
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; |
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
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