-
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.
Add and pass regression tests for PerseusItem parser (#1907)
Issue: LEMS-2582 ## Test plan: `yarn test` Author: benchristel Reviewers: jeremywiebe, benchristel, anakaren-rojas, catandthemachines, nishasy 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), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1907
- Loading branch information
1 parent
841551a
commit 3dbca96
Showing
28 changed files
with
3,148 additions
and
75 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": patch | ||
--- | ||
|
||
Internal: add and pass regression tests for `PerseusItem` parser. |
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
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
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
17 changes: 17 additions & 0 deletions
17
packages/perseus/src/util/parse-perseus-json/perseus-parsers/images-map.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,17 @@ | ||
import {number, object, record, string} from "../general-purpose-parsers"; | ||
import {defaulted} from "../general-purpose-parsers/defaulted"; | ||
|
||
import type {PerseusImageDetail} from "../../../perseus-types"; | ||
import type {Parser} from "../parser-types"; | ||
|
||
export const parseImages: Parser<{[key: string]: PerseusImageDetail}> = | ||
defaulted( | ||
record( | ||
string, | ||
object({ | ||
width: number, | ||
height: number, | ||
}), | ||
), | ||
() => ({}), | ||
); |
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
53 changes: 24 additions & 29 deletions
53
packages/perseus/src/util/parse-perseus-json/perseus-parsers/perseus-renderer.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 |
---|---|---|
@@ -1,37 +1,32 @@ | ||
import { | ||
array, | ||
number, | ||
object, | ||
optional, | ||
record, | ||
string, | ||
} from "../general-purpose-parsers"; | ||
import {array, object, optional, string} from "../general-purpose-parsers"; | ||
import {defaulted} from "../general-purpose-parsers/defaulted"; | ||
|
||
import {parseImages} from "./images-map"; | ||
import {parseWidgetsMap} from "./widgets-map"; | ||
|
||
import type {PerseusRenderer} from "../../../perseus-types"; | ||
import type {Parser} from "../parser-types"; | ||
|
||
export const parsePerseusRenderer: Parser<PerseusRenderer> = object({ | ||
content: string, | ||
// This module has an import cycle with parseWidgetsMap, because the | ||
// `group` widget can contain another renderer. | ||
// The anonymous function below ensures that we don't try to access | ||
// parseWidgetsMap before it's defined. | ||
widgets: defaulted( | ||
(rawVal, ctx) => parseWidgetsMap(rawVal, ctx), | ||
() => ({}), | ||
), | ||
metadata: optional(array(string)), | ||
images: defaulted( | ||
record( | ||
string, | ||
object({ | ||
width: number, | ||
height: number, | ||
}), | ||
export const parsePerseusRenderer: Parser<PerseusRenderer> = defaulted( | ||
object({ | ||
// TODO(benchristel): content is also defaulted to empty string in | ||
// renderer.tsx. See if we can remove one default or the other. | ||
content: defaulted(string, () => ""), | ||
// This module has an import cycle with parseWidgetsMap, because the | ||
// `group` widget can contain another renderer. | ||
// The anonymous function below ensures that we don't try to access | ||
// parseWidgetsMap before it's defined. | ||
widgets: defaulted( | ||
(rawVal, ctx) => parseWidgetsMap(rawVal, ctx), | ||
() => ({}), | ||
), | ||
() => ({}), | ||
), | ||
}); | ||
metadata: optional(array(string)), | ||
images: parseImages, | ||
}), | ||
// Default value | ||
() => ({ | ||
content: "", | ||
widgets: {}, | ||
images: {}, | ||
}), | ||
); |
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
Oops, something went wrong.