@khanacademy/perseus-editor 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Perseus editors",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "2.10.0",
6
+ "version": "2.11.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@khanacademy/kas": "^0.3.5",
26
26
  "@khanacademy/kmath": "^0.1.6",
27
- "@khanacademy/perseus": "^13.2.0",
27
+ "@khanacademy/perseus": "^14.0.0",
28
28
  "@khanacademy/perseus-core": "1.3.0"
29
29
  },
30
30
  "devDependencies": {
@@ -0,0 +1,56 @@
1
+ import {Dependencies} from "@khanacademy/perseus";
2
+ import {render, screen} from "@testing-library/react";
3
+ import * as React from "react";
4
+
5
+ import "@testing-library/jest-dom";
6
+
7
+ import {testDependencies} from "../../../../../testing/test-dependencies";
8
+ import ExpressionEditor from "../expression-editor";
9
+
10
+ import type {PropsFor} from "@khanacademy/wonder-blocks-core";
11
+
12
+ describe("expression-editor", () => {
13
+ beforeEach(() => {
14
+ jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
15
+ testDependencies,
16
+ );
17
+ });
18
+
19
+ it("should render", async () => {
20
+ render(<ExpressionEditor onChange={() => undefined} />);
21
+
22
+ expect(await screen.findByText(/Add new answer/)).toBeInTheDocument();
23
+ });
24
+
25
+ it("should render answerForms missing a key", async () => {
26
+ const answerForms: PropsFor<typeof ExpressionEditor>["answerForms"] = [
27
+ {
28
+ value: "x\\cdot3=y",
29
+ form: true,
30
+ simplify: true,
31
+ considered: "correct",
32
+ },
33
+ {
34
+ value: "x^2=y",
35
+ form: true,
36
+ simplify: true,
37
+ considered: "wrong",
38
+ },
39
+ {
40
+ value: "x=y\\cdotπ",
41
+ form: true,
42
+ simplify: true,
43
+ considered: "wrong",
44
+ },
45
+ ];
46
+
47
+ render(
48
+ <ExpressionEditor
49
+ onChange={() => undefined}
50
+ answerForms={answerForms}
51
+ />,
52
+ );
53
+
54
+ expect(await screen.findByText(/π/)).toBeInTheDocument();
55
+ });
56
+ });
@@ -18,7 +18,6 @@ import SortableArea from "../components/sortable";
18
18
  import type {PerseusExpressionWidgetOptions} from "@khanacademy/perseus";
19
19
 
20
20
  const {InfoTip, PropCheckBox, TexButtons} = components;
21
- const {getDependencies} = Dependencies;
22
21
 
23
22
  type Props = {
24
23
  widgetId?: any;
@@ -38,11 +37,12 @@ type DefaultProps = {
38
37
  };
39
38
 
40
39
  const parseAnswerKey = ({key}: AnswerForm): number => {
41
- const parsedKey = Number.parseInt(key ?? "");
42
- if (Number.isNaN(parsedKey)) {
43
- throw new Error(`Invalid answer key: ${key}`);
44
- }
45
- return parsedKey;
40
+ // We don't throw here because there is data stored in some
41
+ // exercises/articles where the answer forms don't have a key. If we throw,
42
+ // it blocks content editors from loading the page at all.
43
+ // TODO(Jeremy): find a way to handle these answer forms that are missing
44
+ // keys more gracefully.
45
+ return Number.parseInt(key ?? "");
46
46
  };
47
47
 
48
48
  // Pick a key that isn't currently used by an answer in answerForms
@@ -182,7 +182,7 @@ class ExpressionEditor extends React.Component<Props, State> {
182
182
  },
183
183
  );
184
184
 
185
- const {TeX} = getDependencies(); // OldExpression only
185
+ const {TeX} = Dependencies.getDependencies(); // OldExpression only
186
186
 
187
187
  buttonSetChoices.splice(
188
188
  1,