diff --git a/packages/perseus/src/util/parse-perseus-json/perseus-parsers/expression-widget.ts b/packages/perseus/src/util/parse-perseus-json/perseus-parsers/expression-widget.ts index f9730c79b5..a617e9dd7b 100644 --- a/packages/perseus/src/util/parse-perseus-json/perseus-parsers/expression-widget.ts +++ b/packages/perseus/src/util/parse-perseus-json/perseus-parsers/expression-widget.ts @@ -54,6 +54,20 @@ function removeInvalidAnswerForms( return valid; } +const buttonSet = enumeration( + "basic", + "basic+div", + "trig", + "prealgebra", + "logarithms", + "basic relations", + "advanced relations", +); + +// This default is copied from the default props of the Expression component. +// See parse-perseus-json/README.md for why the default is duplicated here. +const defaultButtonSets = () => ["basic", "trig", "prealgebra", "logarithms"] as const; + const version1 = object({major: constant(1), minor: number}); const parseExpressionWidgetV1: Parser = parseWidgetWithVersion( @@ -67,17 +81,7 @@ const parseExpressionWidgetV1: Parser = times: boolean, visibleLabel: optional(string), ariaLabel: optional(string), - buttonSets: array( - enumeration( - "basic", - "basic+div", - "trig", - "prealgebra", - "logarithms", - "basic relations", - "advanced relations", - ), - ), + buttonSets: defaulted(array(buttonSet), defaultButtonSets), buttonsVisible: optional(enumeration("always", "never", "focused")), }), ); @@ -94,17 +98,7 @@ const parseExpressionWidgetV0 = parseWidgetWithVersion( form: boolean, simplify: boolean, value: string, - buttonSets: array( - enumeration( - "basic", - "basic+div", - "trig", - "prealgebra", - "logarithms", - "basic relations", - "advanced relations", - ), - ), + buttonSets: defaulted(array(buttonSet), defaultButtonSets), buttonsVisible: optional(enumeration("always", "never", "focused")), }), ); diff --git a/packages/perseus/src/util/parse-perseus-json/regression-tests/data/e196808b1e15e15ec5a33aa508c2f68976e03fde9f438264d734ec767e65d540.json b/packages/perseus/src/util/parse-perseus-json/regression-tests/data/expression-missing-buttonSets.json similarity index 100% rename from packages/perseus/src/util/parse-perseus-json/regression-tests/data/e196808b1e15e15ec5a33aa508c2f68976e03fde9f438264d734ec767e65d540.json rename to packages/perseus/src/util/parse-perseus-json/regression-tests/data/expression-missing-buttonSets.json