@khanacademy/perseus-editor 4.1.4 → 4.1.6

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.
Files changed (175) hide show
  1. package/dist/es/index.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/package.json +9 -6
  4. package/.babelrc.js +0 -8
  5. package/.eslintrc.js +0 -12
  6. package/CHANGELOG.md +0 -1146
  7. package/src/README.md +0 -7
  8. package/src/__stories__/editor-page.stories.tsx +0 -65
  9. package/src/__stories__/editor.stories.tsx +0 -134
  10. package/src/__stories__/item-editor.stories.tsx +0 -41
  11. package/src/__stories__/tex-error-view.stories.tsx +0 -26
  12. package/src/__testdata__/input-number.testdata.ts +0 -27
  13. package/src/__tests__/editor.test.tsx +0 -142
  14. package/src/__tests__/hint-editor.test.tsx +0 -83
  15. package/src/__tests__/i18n.test.ts +0 -501
  16. package/src/__tests__/integration.test.ts +0 -5
  17. package/src/__tests__/item-extras-editor.test.tsx +0 -85
  18. package/src/__tests__/traversal.test.ts +0 -377
  19. package/src/all-editors.test.ts +0 -16
  20. package/src/all-editors.ts +0 -83
  21. package/src/all-widgets.ts +0 -7
  22. package/src/article-editor.tsx +0 -438
  23. package/src/components/__stories__/blur-input.stories.tsx +0 -22
  24. package/src/components/__stories__/section-control-button.stories.tsx +0 -26
  25. package/src/components/__tests__/blur-input.test.tsx +0 -67
  26. package/src/components/blur-input.tsx +0 -69
  27. package/src/components/checkbox.tsx +0 -194
  28. package/src/components/device-framer.tsx +0 -90
  29. package/src/components/drag-target.tsx +0 -87
  30. package/src/components/dropdown-option.tsx +0 -311
  31. package/src/components/form-wrapped-text-field.tsx +0 -245
  32. package/src/components/graph-points-count-selector.tsx +0 -31
  33. package/src/components/graph-settings.tsx +0 -627
  34. package/src/components/graph-type-selector.tsx +0 -31
  35. package/src/components/hover-behavior.ts +0 -177
  36. package/src/components/json-editor.tsx +0 -121
  37. package/src/components/link.ts +0 -173
  38. package/src/components/section-control-button.tsx +0 -53
  39. package/src/components/segment-count-selector.tsx +0 -27
  40. package/src/components/simple-button.tsx +0 -85
  41. package/src/components/sortable.tsx +0 -187
  42. package/src/components/util.ts +0 -38
  43. package/src/components/viewport-resizer.tsx +0 -72
  44. package/src/components/widget-editor.tsx +0 -222
  45. package/src/components/widget-select.tsx +0 -48
  46. package/src/diffs/__stories__/perseus-diff-wrapper.tsx +0 -11
  47. package/src/diffs/__stories__/structured-item-diff.stories.tsx +0 -855
  48. package/src/diffs/__stories__/tags-diff.stories.tsx +0 -36
  49. package/src/diffs/__stories__/text-diff.stories.tsx +0 -35
  50. package/src/diffs/__tests__/split-diff.test.ts +0 -33
  51. package/src/diffs/__tests__/string-array-diff.test.ts +0 -73
  52. package/src/diffs/__tests__/structured-item-diff.test.ts +0 -433
  53. package/src/diffs/__tests__/widget-diff-performer.test.ts +0 -43
  54. package/src/diffs/article-diff.tsx +0 -69
  55. package/src/diffs/item-diff.tsx +0 -76
  56. package/src/diffs/renderer-diff.tsx +0 -137
  57. package/src/diffs/split-diff.ts +0 -31
  58. package/src/diffs/string-array-diff.ts +0 -74
  59. package/src/diffs/structured-item-diff.tsx +0 -275
  60. package/src/diffs/tags-diff.tsx +0 -49
  61. package/src/diffs/text-diff.tsx +0 -193
  62. package/src/diffs/widget-diff-performer.ts +0 -69
  63. package/src/diffs/widget-diff.tsx +0 -290
  64. package/src/editor-page.tsx +0 -325
  65. package/src/editor.tsx +0 -1099
  66. package/src/hint-editor.tsx +0 -469
  67. package/src/i18n.ts +0 -140
  68. package/src/iframe-content-renderer.tsx +0 -188
  69. package/src/index.ts +0 -30
  70. package/src/item-editor.tsx +0 -158
  71. package/src/item-extras-editor.tsx +0 -230
  72. package/src/katex-mhchem/index.js +0 -73
  73. package/src/katex-mhchem/parser.js +0 -2659
  74. package/src/multirenderer-editor.tsx +0 -1061
  75. package/src/stateful-article-editor.tsx +0 -173
  76. package/src/stateful-editor-page.tsx +0 -88
  77. package/src/styles/perseus-editor.less +0 -1321
  78. package/src/testing-widgets.ts +0 -11
  79. package/src/tex-error-view.tsx +0 -90
  80. package/src/util/points.test.ts +0 -24
  81. package/src/util/points.ts +0 -13
  82. package/src/util/register-all-widgets-and-editors-for-testing.test.ts +0 -17
  83. package/src/util/register-all-widgets-and-editors-for-testing.ts +0 -17
  84. package/src/version.ts +0 -10
  85. package/src/widgets/__stories__/categorizer-editor.stories.tsx +0 -24
  86. package/src/widgets/__stories__/definition-editor.stories.tsx +0 -18
  87. package/src/widgets/__stories__/dropdown-editor.stories.tsx +0 -18
  88. package/src/widgets/__stories__/explanation-editor.stories.tsx +0 -18
  89. package/src/widgets/__stories__/expression-editor.stories.tsx +0 -122
  90. package/src/widgets/__stories__/image-editor.stories.tsx +0 -72
  91. package/src/widgets/__stories__/input-number-editor.stories.tsx +0 -18
  92. package/src/widgets/__stories__/interaction-editor.stories.tsx +0 -37
  93. package/src/widgets/__stories__/label-image-editor.stories.tsx +0 -99
  94. package/src/widgets/__stories__/matcher-editor.stories.tsx +0 -18
  95. package/src/widgets/__stories__/number-line-editor.stories.tsx +0 -18
  96. package/src/widgets/__stories__/numeric-input-editor.stories.tsx +0 -18
  97. package/src/widgets/__stories__/radio-editor.stories.tsx +0 -116
  98. package/src/widgets/__stories__/sorter-editor.stories.tsx +0 -18
  99. package/src/widgets/__tests__/categorizer-editor.test.tsx +0 -51
  100. package/src/widgets/__tests__/definition-editor.test.tsx +0 -41
  101. package/src/widgets/__tests__/dropdown-editor.test.tsx +0 -57
  102. package/src/widgets/__tests__/explanation-editor.test.tsx +0 -59
  103. package/src/widgets/__tests__/expression-editor.test.tsx +0 -403
  104. package/src/widgets/__tests__/input-number-editor.test.tsx +0 -128
  105. package/src/widgets/__tests__/matcher-editor.test.tsx +0 -47
  106. package/src/widgets/__tests__/number-line-editor.test.tsx +0 -144
  107. package/src/widgets/__tests__/numeric-input-editor.test.tsx +0 -177
  108. package/src/widgets/__tests__/radio-editor.test.tsx +0 -118
  109. package/src/widgets/__tests__/sorter-editor.test.tsx +0 -55
  110. package/src/widgets/categorizer-editor.tsx +0 -104
  111. package/src/widgets/cs-program-editor.tsx +0 -256
  112. package/src/widgets/definition-editor.tsx +0 -77
  113. package/src/widgets/deprecated-standin-editor.tsx +0 -29
  114. package/src/widgets/dropdown-editor.tsx +0 -211
  115. package/src/widgets/example-graphie-widget-editor.tsx +0 -70
  116. package/src/widgets/example-graphie-widget.tsx +0 -172
  117. package/src/widgets/example-widget-editor.tsx +0 -62
  118. package/src/widgets/example-widget.tsx +0 -154
  119. package/src/widgets/explanation-editor.tsx +0 -92
  120. package/src/widgets/expression-editor.tsx +0 -557
  121. package/src/widgets/graded-group-editor.tsx +0 -161
  122. package/src/widgets/graded-group-set-editor.tsx +0 -104
  123. package/src/widgets/grapher-editor.tsx +0 -155
  124. package/src/widgets/group-editor.tsx +0 -83
  125. package/src/widgets/iframe-editor.tsx +0 -202
  126. package/src/widgets/image-editor.tsx +0 -367
  127. package/src/widgets/input-number-editor.tsx +0 -288
  128. package/src/widgets/interaction-editor/constraint-editor.tsx +0 -134
  129. package/src/widgets/interaction-editor/function-editor.tsx +0 -108
  130. package/src/widgets/interaction-editor/index.ts +0 -3
  131. package/src/widgets/interaction-editor/interaction-editor.tsx +0 -749
  132. package/src/widgets/interaction-editor/label-editor.tsx +0 -87
  133. package/src/widgets/interaction-editor/line-editor.tsx +0 -125
  134. package/src/widgets/interaction-editor/mathquill-input.tsx +0 -81
  135. package/src/widgets/interaction-editor/movable-line-editor.tsx +0 -121
  136. package/src/widgets/interaction-editor/movable-point-editor.tsx +0 -89
  137. package/src/widgets/interaction-editor/parametric-editor.tsx +0 -117
  138. package/src/widgets/interaction-editor/point-editor.tsx +0 -72
  139. package/src/widgets/interaction-editor/rectangle-editor.tsx +0 -96
  140. package/src/widgets/interactive-graph-editor.tsx +0 -571
  141. package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +0 -82
  142. package/src/widgets/label-image/__stories__/behavior.stories.tsx +0 -31
  143. package/src/widgets/label-image/__stories__/marker.stories.tsx +0 -75
  144. package/src/widgets/label-image/__stories__/question-markers.stories.tsx +0 -107
  145. package/src/widgets/label-image/__stories__/select-image.stories.tsx +0 -59
  146. package/src/widgets/label-image/answer-choices.tsx +0 -231
  147. package/src/widgets/label-image/behavior.tsx +0 -122
  148. package/src/widgets/label-image/marker.tsx +0 -290
  149. package/src/widgets/label-image/question-markers.tsx +0 -176
  150. package/src/widgets/label-image/select-image.tsx +0 -81
  151. package/src/widgets/label-image-editor.tsx +0 -252
  152. package/src/widgets/lights-puzzle-editor.tsx +0 -278
  153. package/src/widgets/matcher-editor.tsx +0 -149
  154. package/src/widgets/matrix-editor.tsx +0 -156
  155. package/src/widgets/measurer-editor.tsx +0 -253
  156. package/src/widgets/molecule-editor.tsx +0 -64
  157. package/src/widgets/number-line-editor.tsx +0 -512
  158. package/src/widgets/numeric-input-editor.tsx +0 -536
  159. package/src/widgets/orderer-editor.tsx +0 -172
  160. package/src/widgets/passage-editor.tsx +0 -117
  161. package/src/widgets/passage-ref-editor.tsx +0 -80
  162. package/src/widgets/passage-ref-target-editor.tsx +0 -49
  163. package/src/widgets/plotter-editor.tsx +0 -542
  164. package/src/widgets/radio/editor.tsx +0 -398
  165. package/src/widgets/reaction-diagram-editor.tsx +0 -131
  166. package/src/widgets/sequence-editor.tsx +0 -205
  167. package/src/widgets/simple-markdown-tester-editor.tsx +0 -86
  168. package/src/widgets/simple-markdown-tester.tsx +0 -92
  169. package/src/widgets/simulator-editor.tsx +0 -146
  170. package/src/widgets/sorter-editor.tsx +0 -103
  171. package/src/widgets/table-editor.tsx +0 -164
  172. package/src/widgets/unit-editor.tsx +0 -299
  173. package/src/widgets/video-editor.tsx +0 -73
  174. package/tsconfig-build.json +0 -22
  175. package/tsconfig-build.tsbuildinfo +0 -1
@@ -1,403 +0,0 @@
1
- import {Dependencies} from "@khanacademy/perseus";
2
- import {render, screen} from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
- import * as React from "react";
5
-
6
- import "@testing-library/jest-dom";
7
-
8
- import {testDependencies} from "../../../../../testing/test-dependencies";
9
- import ExpressionEditor from "../expression-editor";
10
-
11
- import type {PropsFor} from "@khanacademy/wonder-blocks-core";
12
-
13
- describe("expression-editor", () => {
14
- beforeEach(() => {
15
- jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
16
- testDependencies,
17
- );
18
- });
19
-
20
- it("should render", async () => {
21
- render(<ExpressionEditor onChange={() => undefined} />);
22
-
23
- expect(await screen.findByText(/Add new answer/)).toBeInTheDocument();
24
- });
25
-
26
- it("should render answerForms missing a key", async () => {
27
- const answerForms: PropsFor<typeof ExpressionEditor>["answerForms"] = [
28
- {
29
- value: "x\\cdot3=y",
30
- form: true,
31
- simplify: true,
32
- considered: "correct",
33
- },
34
- {
35
- value: "x^2=y",
36
- form: true,
37
- simplify: true,
38
- considered: "wrong",
39
- },
40
- {
41
- value: "x=y\\cdotπ",
42
- form: true,
43
- simplify: true,
44
- considered: "wrong",
45
- },
46
- ];
47
-
48
- render(
49
- <ExpressionEditor
50
- onChange={() => undefined}
51
- answerForms={answerForms}
52
- />,
53
- );
54
-
55
- expect(await screen.findByText(/π/)).toBeInTheDocument();
56
- });
57
-
58
- it("should toggle multiplication checkbox", () => {
59
- const onChangeMock = jest.fn();
60
-
61
- render(<ExpressionEditor onChange={onChangeMock} />);
62
-
63
- userEvent.click(
64
- screen.getByRole("checkbox", {
65
- name: "Use × for rendering multiplication instead of a center dot.",
66
- }),
67
- );
68
-
69
- expect(onChangeMock).toBeCalledWith({times: true});
70
- });
71
-
72
- it("should be possible to change function variables", () => {
73
- const onChangeMock = jest.fn();
74
-
75
- render(<ExpressionEditor onChange={onChangeMock} functions={[]} />);
76
-
77
- const input = screen.getByRole("textbox", {
78
- name: "Function variables:",
79
- });
80
-
81
- userEvent.type(input, "x");
82
-
83
- expect(onChangeMock).toBeCalledWith({functions: ["x"]});
84
- });
85
-
86
- it("should toggle division checkbox", () => {
87
- const onChangeMock = jest.fn();
88
-
89
- render(<ExpressionEditor onChange={onChangeMock} />);
90
-
91
- userEvent.click(
92
- screen.getByRole("checkbox", {
93
- name: "show \\div button",
94
- }),
95
- );
96
-
97
- expect(onChangeMock).toBeCalledWith(
98
- {
99
- answerForms: [],
100
- buttonSets: ["basic+div"],
101
- functions: ["f", "g", "h"],
102
- times: false,
103
- },
104
- undefined,
105
- );
106
- });
107
-
108
- it("should toggle trig checkbox", () => {
109
- const onChangeMock = jest.fn();
110
-
111
- render(<ExpressionEditor onChange={onChangeMock} />);
112
-
113
- userEvent.click(
114
- screen.getByRole("checkbox", {
115
- name: "trig",
116
- }),
117
- );
118
-
119
- expect(onChangeMock).toBeCalledWith({
120
- buttonSets: ["basic", "trig"],
121
- });
122
- });
123
-
124
- it("should toggle prealgebra checkbox", () => {
125
- const onChangeMock = jest.fn();
126
-
127
- render(<ExpressionEditor onChange={onChangeMock} />);
128
-
129
- userEvent.click(
130
- screen.getByRole("checkbox", {
131
- name: "prealgebra",
132
- }),
133
- );
134
-
135
- expect(onChangeMock).toBeCalledWith({
136
- buttonSets: ["basic", "prealgebra"],
137
- });
138
- });
139
-
140
- it("should toggle prealgebra checkbox", () => {
141
- const onChangeMock = jest.fn();
142
-
143
- render(<ExpressionEditor onChange={onChangeMock} />);
144
-
145
- userEvent.click(
146
- screen.getByRole("checkbox", {
147
- name: "logarithms",
148
- }),
149
- );
150
-
151
- expect(onChangeMock).toBeCalledWith({
152
- buttonSets: ["basic", "logarithms"],
153
- });
154
- });
155
-
156
- it("should toggle prealgebra checkbox", () => {
157
- const onChangeMock = jest.fn();
158
-
159
- render(<ExpressionEditor onChange={onChangeMock} />);
160
-
161
- userEvent.click(
162
- screen.getByRole("checkbox", {
163
- name: "basic relations",
164
- }),
165
- );
166
-
167
- expect(onChangeMock).toBeCalledWith({
168
- buttonSets: ["basic", "basic relations"],
169
- });
170
- });
171
-
172
- it("should toggle prealgebra checkbox", () => {
173
- const onChangeMock = jest.fn();
174
-
175
- render(<ExpressionEditor onChange={onChangeMock} />);
176
-
177
- userEvent.click(
178
- screen.getByRole("checkbox", {
179
- name: "advanced relations",
180
- }),
181
- );
182
-
183
- expect(onChangeMock).toBeCalledWith({
184
- buttonSets: ["basic", "advanced relations"],
185
- });
186
- });
187
-
188
- it("should be possible to add an answer", () => {
189
- const onChangeMock = jest.fn();
190
-
191
- render(<ExpressionEditor onChange={onChangeMock} />);
192
-
193
- userEvent.click(
194
- screen.getByRole("button", {
195
- name: "Add new answer",
196
- }),
197
- );
198
-
199
- expect(onChangeMock).toBeCalledWith(
200
- {
201
- answerForms: [
202
- {
203
- considered: "correct",
204
- form: false,
205
- key: 0,
206
- simplify: false,
207
- value: "",
208
- },
209
- ],
210
- buttonSets: ["basic"],
211
- functions: ["f", "g", "h"],
212
- times: false,
213
- },
214
- undefined,
215
- );
216
- });
217
-
218
- it("should be possible to update answer", () => {
219
- const onChangeMock = jest.fn();
220
-
221
- render(
222
- <ExpressionEditor
223
- onChange={onChangeMock}
224
- answerForms={[
225
- {
226
- considered: "correct",
227
- form: false,
228
- key: "0",
229
- simplify: false,
230
- value: "",
231
- },
232
- ]}
233
- />,
234
- );
235
-
236
- userEvent.click(
237
- screen.getByRole("switch", {
238
- name: "open math keypad",
239
- }),
240
- );
241
-
242
- userEvent.click(
243
- screen.getByRole("button", {
244
- name: "9",
245
- }),
246
- );
247
-
248
- expect(onChangeMock).toBeCalledWith(
249
- {
250
- answerForms: [
251
- {
252
- buttonSets: ["basic"],
253
- buttonsVisible: "focused",
254
- considered: "correct",
255
- form: false,
256
- functions: ["f", "g", "h"],
257
- key: "0",
258
- linterContext: {
259
- contentType: "",
260
- highlightLint: false,
261
- paths: [],
262
- stack: [],
263
- },
264
- simplify: false,
265
- times: false,
266
- value: "9",
267
- },
268
- ],
269
- buttonSets: ["basic"],
270
- functions: ["f", "g", "h"],
271
- times: false,
272
- },
273
- undefined,
274
- );
275
- });
276
-
277
- it("should be possible to toggle same form", () => {
278
- const onChangeMock = jest.fn();
279
-
280
- render(
281
- <ExpressionEditor
282
- onChange={onChangeMock}
283
- answerForms={[
284
- {
285
- considered: "correct",
286
- form: false,
287
- key: "0",
288
- simplify: false,
289
- value: "",
290
- },
291
- ]}
292
- />,
293
- );
294
-
295
- userEvent.click(
296
- screen.getByRole("checkbox", {
297
- name: "Answer expression must have the same form.",
298
- }),
299
- );
300
-
301
- expect(onChangeMock).toBeCalledWith(
302
- {
303
- answerForms: [
304
- {
305
- considered: "correct",
306
- form: true,
307
- key: "0",
308
- simplify: false,
309
- value: "",
310
- },
311
- ],
312
- buttonSets: ["basic"],
313
- functions: ["f", "g", "h"],
314
- times: false,
315
- },
316
- undefined,
317
- );
318
- });
319
-
320
- it("should be possible to toggle expanded and simplified", () => {
321
- const onChangeMock = jest.fn();
322
-
323
- render(
324
- <ExpressionEditor
325
- onChange={onChangeMock}
326
- answerForms={[
327
- {
328
- considered: "correct",
329
- form: false,
330
- key: "0",
331
- simplify: false,
332
- value: "",
333
- },
334
- ]}
335
- />,
336
- );
337
-
338
- userEvent.click(
339
- screen.getByRole("checkbox", {
340
- name: "Answer expression must be fully expanded and simplified.",
341
- }),
342
- );
343
-
344
- expect(onChangeMock).toBeCalledWith(
345
- {
346
- answerForms: [
347
- {
348
- considered: "correct",
349
- form: false,
350
- key: "0",
351
- simplify: true,
352
- value: "",
353
- },
354
- ],
355
- buttonSets: ["basic"],
356
- functions: ["f", "g", "h"],
357
- times: false,
358
- },
359
- undefined,
360
- );
361
- });
362
-
363
- it("should be possible to delete answer", () => {
364
- const onChangeMock = jest.fn();
365
-
366
- render(
367
- <ExpressionEditor
368
- onChange={onChangeMock}
369
- answerForms={[
370
- {
371
- considered: "correct",
372
- form: false,
373
- key: "0",
374
- simplify: false,
375
- value: "",
376
- },
377
- ]}
378
- />,
379
- );
380
-
381
- userEvent.click(
382
- screen.getByRole("button", {
383
- name: "Delete",
384
- }),
385
- );
386
-
387
- userEvent.click(
388
- screen.getByRole("button", {
389
- name: "I'm sure!",
390
- }),
391
- );
392
-
393
- expect(onChangeMock).toBeCalledWith(
394
- {
395
- answerForms: [],
396
- buttonSets: ["basic"],
397
- functions: ["f", "g", "h"],
398
- times: false,
399
- },
400
- undefined,
401
- );
402
- });
403
- });
@@ -1,128 +0,0 @@
1
- import {Dependencies} from "@khanacademy/perseus";
2
- import {render, screen} from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
- import * as React from "react";
5
-
6
- import "@testing-library/jest-dom";
7
-
8
- import {testDependencies} from "../../../../../testing/test-dependencies";
9
- import InputNumberEditor from "../input-number-editor";
10
-
11
- describe("input-number-editor", () => {
12
- beforeEach(() => {
13
- jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
14
- testDependencies,
15
- );
16
- });
17
-
18
- it("should render", async () => {
19
- render(<InputNumberEditor onChange={() => undefined} />);
20
-
21
- expect(await screen.findByText("Correct answer:")).toBeInTheDocument();
22
- });
23
-
24
- it("should be possible to change the correct answer", async () => {
25
- const onChangeMock = jest.fn();
26
-
27
- render(<InputNumberEditor onChange={onChangeMock} />);
28
-
29
- const input = screen.getByRole("textbox", {name: "Correct answer:"});
30
- userEvent.type(input, "1");
31
- input.blur();
32
-
33
- expect(onChangeMock).toBeCalledWith(
34
- expect.objectContaining({value: 1}),
35
- );
36
- });
37
-
38
- it("should be possible to change allow inexact answers", async () => {
39
- const onChangeMock = jest.fn();
40
-
41
- render(<InputNumberEditor onChange={onChangeMock} />);
42
-
43
- userEvent.click(
44
- screen.getByRole("checkbox", {name: "Allow inexact answers"}),
45
- );
46
-
47
- expect(onChangeMock).toBeCalledWith(
48
- expect.objectContaining({inexact: true}),
49
- );
50
- });
51
-
52
- it("should be possible to change right alignment", async () => {
53
- const onChangeMock = jest.fn();
54
-
55
- render(<InputNumberEditor onChange={onChangeMock} />);
56
-
57
- userEvent.click(
58
- screen.getByRole("checkbox", {name: "Right alignment"}),
59
- );
60
-
61
- expect(onChangeMock).toBeCalledWith(
62
- expect.objectContaining({rightAlign: true}),
63
- );
64
- });
65
-
66
- const unsimplifiedOptions = ["required", "optional", "enforced"];
67
- unsimplifiedOptions.forEach((opt) => {
68
- it(`should be possible to set unsimplified answers to: ${opt}`, async () => {
69
- const onChangeMock = jest.fn();
70
-
71
- render(<InputNumberEditor onChange={onChangeMock} />);
72
-
73
- const select = screen.getByRole("combobox", {
74
- name: "Unsimplified answers",
75
- });
76
- userEvent.selectOptions(select, opt);
77
-
78
- expect(onChangeMock).toBeCalledWith(
79
- expect.objectContaining({simplify: opt}),
80
- );
81
- });
82
- });
83
-
84
- const answerTypeOptions = [
85
- "number",
86
- "decimal",
87
- "integer",
88
- "rational",
89
- "improper",
90
- "mixed",
91
- "percent",
92
- "pi",
93
- ];
94
- answerTypeOptions.forEach((opt) => {
95
- it(`should be possible to set answer type to: ${opt}`, async () => {
96
- const onChangeMock = jest.fn();
97
-
98
- render(<InputNumberEditor onChange={onChangeMock} />);
99
-
100
- const select = screen.getByRole("combobox", {
101
- name: "Answer type",
102
- });
103
- userEvent.selectOptions(select, opt);
104
-
105
- expect(onChangeMock).toBeCalledWith(
106
- expect.objectContaining({answerType: opt}),
107
- );
108
- });
109
- });
110
-
111
- const sizeOptions = ["normal", "small"];
112
- sizeOptions.forEach((opt) => {
113
- it(`should be possible to set unsimplified answers to: ${opt}`, async () => {
114
- const onChangeMock = jest.fn();
115
-
116
- render(<InputNumberEditor onChange={onChangeMock} />);
117
-
118
- const select = screen.getByRole("combobox", {
119
- name: "Width",
120
- });
121
- userEvent.selectOptions(select, opt);
122
-
123
- expect(onChangeMock).toBeCalledWith(
124
- expect.objectContaining({size: opt}),
125
- );
126
- });
127
- });
128
- });
@@ -1,47 +0,0 @@
1
- import {Dependencies} from "@khanacademy/perseus";
2
- import {render, screen} from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
- import * as React from "react";
5
-
6
- import "@testing-library/jest-dom";
7
-
8
- import {testDependencies} from "../../../../../testing/test-dependencies";
9
- import MatcherEditor from "../matcher-editor";
10
-
11
- describe("matcher-editor", () => {
12
- beforeEach(() => {
13
- jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
14
- testDependencies,
15
- );
16
- });
17
-
18
- it("renders", async () => {
19
- render(<MatcherEditor onChange={() => {}} />);
20
-
21
- expect(screen.getByText("Correct answer:")).toBeInTheDocument();
22
- });
23
-
24
- it("is possible to change option: order of matched pairs matters", async () => {
25
- const onChangeMock = jest.fn();
26
-
27
- render(<MatcherEditor onChange={onChangeMock} />);
28
-
29
- userEvent.click(
30
- screen.getByRole("checkbox", {
31
- name: "Order of the matched pairs matters:",
32
- }),
33
- );
34
-
35
- expect(onChangeMock).toBeCalledWith({orderMatters: true});
36
- });
37
-
38
- it("should be possible to change padding", async () => {
39
- const onChangeMock = jest.fn();
40
-
41
- render(<MatcherEditor onChange={onChangeMock} />);
42
-
43
- userEvent.click(screen.getByRole("checkbox", {name: "Padding:"}));
44
-
45
- expect(onChangeMock).toBeCalledWith({padding: false});
46
- });
47
- });