@khanacademy/perseus-editor 4.1.5 → 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.
- package/dist/es/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +9 -6
- package/.babelrc.js +0 -8
- package/.eslintrc.js +0 -12
- package/CHANGELOG.md +0 -1155
- package/src/README.md +0 -7
- package/src/__stories__/editor-page.stories.tsx +0 -65
- package/src/__stories__/editor.stories.tsx +0 -134
- package/src/__stories__/item-editor.stories.tsx +0 -41
- package/src/__stories__/tex-error-view.stories.tsx +0 -26
- package/src/__testdata__/input-number.testdata.ts +0 -27
- package/src/__tests__/editor.test.tsx +0 -142
- package/src/__tests__/hint-editor.test.tsx +0 -83
- package/src/__tests__/i18n.test.ts +0 -501
- package/src/__tests__/integration.test.ts +0 -5
- package/src/__tests__/item-extras-editor.test.tsx +0 -85
- package/src/__tests__/traversal.test.ts +0 -377
- package/src/all-editors.test.ts +0 -16
- package/src/all-editors.ts +0 -83
- package/src/all-widgets.ts +0 -7
- package/src/article-editor.tsx +0 -438
- package/src/components/__stories__/blur-input.stories.tsx +0 -22
- package/src/components/__stories__/section-control-button.stories.tsx +0 -26
- package/src/components/__tests__/blur-input.test.tsx +0 -67
- package/src/components/blur-input.tsx +0 -69
- package/src/components/checkbox.tsx +0 -194
- package/src/components/device-framer.tsx +0 -90
- package/src/components/drag-target.tsx +0 -87
- package/src/components/dropdown-option.tsx +0 -311
- package/src/components/form-wrapped-text-field.tsx +0 -245
- package/src/components/graph-points-count-selector.tsx +0 -31
- package/src/components/graph-settings.tsx +0 -627
- package/src/components/graph-type-selector.tsx +0 -31
- package/src/components/hover-behavior.ts +0 -177
- package/src/components/json-editor.tsx +0 -121
- package/src/components/link.ts +0 -173
- package/src/components/section-control-button.tsx +0 -53
- package/src/components/segment-count-selector.tsx +0 -27
- package/src/components/simple-button.tsx +0 -85
- package/src/components/sortable.tsx +0 -187
- package/src/components/util.ts +0 -38
- package/src/components/viewport-resizer.tsx +0 -72
- package/src/components/widget-editor.tsx +0 -222
- package/src/components/widget-select.tsx +0 -48
- package/src/diffs/__stories__/perseus-diff-wrapper.tsx +0 -11
- package/src/diffs/__stories__/structured-item-diff.stories.tsx +0 -855
- package/src/diffs/__stories__/tags-diff.stories.tsx +0 -36
- package/src/diffs/__stories__/text-diff.stories.tsx +0 -35
- package/src/diffs/__tests__/split-diff.test.ts +0 -33
- package/src/diffs/__tests__/string-array-diff.test.ts +0 -73
- package/src/diffs/__tests__/structured-item-diff.test.ts +0 -433
- package/src/diffs/__tests__/widget-diff-performer.test.ts +0 -43
- package/src/diffs/article-diff.tsx +0 -69
- package/src/diffs/item-diff.tsx +0 -76
- package/src/diffs/renderer-diff.tsx +0 -137
- package/src/diffs/split-diff.ts +0 -31
- package/src/diffs/string-array-diff.ts +0 -74
- package/src/diffs/structured-item-diff.tsx +0 -275
- package/src/diffs/tags-diff.tsx +0 -49
- package/src/diffs/text-diff.tsx +0 -193
- package/src/diffs/widget-diff-performer.ts +0 -69
- package/src/diffs/widget-diff.tsx +0 -290
- package/src/editor-page.tsx +0 -325
- package/src/editor.tsx +0 -1099
- package/src/hint-editor.tsx +0 -469
- package/src/i18n.ts +0 -140
- package/src/iframe-content-renderer.tsx +0 -188
- package/src/index.ts +0 -30
- package/src/item-editor.tsx +0 -158
- package/src/item-extras-editor.tsx +0 -230
- package/src/katex-mhchem/index.js +0 -73
- package/src/katex-mhchem/parser.js +0 -2659
- package/src/multirenderer-editor.tsx +0 -1061
- package/src/stateful-article-editor.tsx +0 -173
- package/src/stateful-editor-page.tsx +0 -88
- package/src/styles/perseus-editor.less +0 -1321
- package/src/testing-widgets.ts +0 -11
- package/src/tex-error-view.tsx +0 -90
- package/src/util/points.test.ts +0 -24
- package/src/util/points.ts +0 -13
- package/src/util/register-all-widgets-and-editors-for-testing.test.ts +0 -17
- package/src/util/register-all-widgets-and-editors-for-testing.ts +0 -17
- package/src/version.ts +0 -10
- package/src/widgets/__stories__/categorizer-editor.stories.tsx +0 -24
- package/src/widgets/__stories__/definition-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/dropdown-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/explanation-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/expression-editor.stories.tsx +0 -122
- package/src/widgets/__stories__/image-editor.stories.tsx +0 -72
- package/src/widgets/__stories__/input-number-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/interaction-editor.stories.tsx +0 -37
- package/src/widgets/__stories__/label-image-editor.stories.tsx +0 -99
- package/src/widgets/__stories__/matcher-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/number-line-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/numeric-input-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/radio-editor.stories.tsx +0 -116
- package/src/widgets/__stories__/sorter-editor.stories.tsx +0 -18
- package/src/widgets/__tests__/categorizer-editor.test.tsx +0 -51
- package/src/widgets/__tests__/definition-editor.test.tsx +0 -41
- package/src/widgets/__tests__/dropdown-editor.test.tsx +0 -57
- package/src/widgets/__tests__/explanation-editor.test.tsx +0 -59
- package/src/widgets/__tests__/expression-editor.test.tsx +0 -403
- package/src/widgets/__tests__/input-number-editor.test.tsx +0 -128
- package/src/widgets/__tests__/matcher-editor.test.tsx +0 -47
- package/src/widgets/__tests__/number-line-editor.test.tsx +0 -144
- package/src/widgets/__tests__/numeric-input-editor.test.tsx +0 -177
- package/src/widgets/__tests__/radio-editor.test.tsx +0 -118
- package/src/widgets/__tests__/sorter-editor.test.tsx +0 -55
- package/src/widgets/categorizer-editor.tsx +0 -104
- package/src/widgets/cs-program-editor.tsx +0 -256
- package/src/widgets/definition-editor.tsx +0 -77
- package/src/widgets/deprecated-standin-editor.tsx +0 -29
- package/src/widgets/dropdown-editor.tsx +0 -211
- package/src/widgets/example-graphie-widget-editor.tsx +0 -70
- package/src/widgets/example-graphie-widget.tsx +0 -172
- package/src/widgets/example-widget-editor.tsx +0 -62
- package/src/widgets/example-widget.tsx +0 -154
- package/src/widgets/explanation-editor.tsx +0 -92
- package/src/widgets/expression-editor.tsx +0 -557
- package/src/widgets/graded-group-editor.tsx +0 -161
- package/src/widgets/graded-group-set-editor.tsx +0 -104
- package/src/widgets/grapher-editor.tsx +0 -155
- package/src/widgets/group-editor.tsx +0 -83
- package/src/widgets/iframe-editor.tsx +0 -202
- package/src/widgets/image-editor.tsx +0 -367
- package/src/widgets/input-number-editor.tsx +0 -288
- package/src/widgets/interaction-editor/constraint-editor.tsx +0 -134
- package/src/widgets/interaction-editor/function-editor.tsx +0 -108
- package/src/widgets/interaction-editor/index.ts +0 -3
- package/src/widgets/interaction-editor/interaction-editor.tsx +0 -749
- package/src/widgets/interaction-editor/label-editor.tsx +0 -87
- package/src/widgets/interaction-editor/line-editor.tsx +0 -125
- package/src/widgets/interaction-editor/mathquill-input.tsx +0 -81
- package/src/widgets/interaction-editor/movable-line-editor.tsx +0 -121
- package/src/widgets/interaction-editor/movable-point-editor.tsx +0 -89
- package/src/widgets/interaction-editor/parametric-editor.tsx +0 -117
- package/src/widgets/interaction-editor/point-editor.tsx +0 -72
- package/src/widgets/interaction-editor/rectangle-editor.tsx +0 -96
- package/src/widgets/interactive-graph-editor.tsx +0 -571
- package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +0 -82
- package/src/widgets/label-image/__stories__/behavior.stories.tsx +0 -31
- package/src/widgets/label-image/__stories__/marker.stories.tsx +0 -75
- package/src/widgets/label-image/__stories__/question-markers.stories.tsx +0 -107
- package/src/widgets/label-image/__stories__/select-image.stories.tsx +0 -59
- package/src/widgets/label-image/answer-choices.tsx +0 -231
- package/src/widgets/label-image/behavior.tsx +0 -122
- package/src/widgets/label-image/marker.tsx +0 -290
- package/src/widgets/label-image/question-markers.tsx +0 -176
- package/src/widgets/label-image/select-image.tsx +0 -81
- package/src/widgets/label-image-editor.tsx +0 -252
- package/src/widgets/lights-puzzle-editor.tsx +0 -278
- package/src/widgets/matcher-editor.tsx +0 -149
- package/src/widgets/matrix-editor.tsx +0 -156
- package/src/widgets/measurer-editor.tsx +0 -253
- package/src/widgets/molecule-editor.tsx +0 -64
- package/src/widgets/number-line-editor.tsx +0 -512
- package/src/widgets/numeric-input-editor.tsx +0 -536
- package/src/widgets/orderer-editor.tsx +0 -172
- package/src/widgets/passage-editor.tsx +0 -117
- package/src/widgets/passage-ref-editor.tsx +0 -80
- package/src/widgets/passage-ref-target-editor.tsx +0 -49
- package/src/widgets/plotter-editor.tsx +0 -542
- package/src/widgets/radio/editor.tsx +0 -398
- package/src/widgets/reaction-diagram-editor.tsx +0 -131
- package/src/widgets/sequence-editor.tsx +0 -205
- package/src/widgets/simple-markdown-tester-editor.tsx +0 -86
- package/src/widgets/simple-markdown-tester.tsx +0 -92
- package/src/widgets/simulator-editor.tsx +0 -146
- package/src/widgets/sorter-editor.tsx +0 -103
- package/src/widgets/table-editor.tsx +0 -164
- package/src/widgets/unit-editor.tsx +0 -299
- package/src/widgets/video-editor.tsx +0 -73
- package/tsconfig-build.json +0 -22
- package/tsconfig-build.tsbuildinfo +0 -1
|
@@ -1,144 +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 NumberLineEditor from "../number-line-editor";
|
|
10
|
-
|
|
11
|
-
describe("number-line-editor", () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
|
|
14
|
-
testDependencies,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should render", async () => {
|
|
19
|
-
render(<NumberLineEditor onChange={() => undefined} />);
|
|
20
|
-
|
|
21
|
-
expect(await screen.findByText("Correct x")).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const relationships = ["lt", "gt", "le", "ge", "eq"];
|
|
25
|
-
relationships.forEach((rel) => {
|
|
26
|
-
it(`should be possible to set relationship to: ${rel}`, async () => {
|
|
27
|
-
const onChangeMock = jest.fn();
|
|
28
|
-
|
|
29
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
30
|
-
|
|
31
|
-
const select = screen.getByRole("combobox", {
|
|
32
|
-
name: "Select relationship",
|
|
33
|
-
});
|
|
34
|
-
userEvent.selectOptions(select, rel);
|
|
35
|
-
|
|
36
|
-
expect(onChangeMock).toBeCalledWith(
|
|
37
|
-
expect.objectContaining({correctRel: rel}),
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should be possible to update the answer", async () => {
|
|
43
|
-
const onChangeMock = jest.fn();
|
|
44
|
-
|
|
45
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
46
|
-
|
|
47
|
-
const input = screen.getByPlaceholderText("answer");
|
|
48
|
-
userEvent.type(input, "1");
|
|
49
|
-
|
|
50
|
-
expect(onChangeMock).toBeCalledWith({correctX: 1});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should be possible to update position", async () => {
|
|
54
|
-
const onChangeMock = jest.fn();
|
|
55
|
-
|
|
56
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
57
|
-
|
|
58
|
-
const input = screen.getByRole("textbox", {name: "Position: ∈"});
|
|
59
|
-
userEvent.type(input, "1");
|
|
60
|
-
|
|
61
|
-
expect(onChangeMock).toBeCalledWith({initialX: 1});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const styles = {
|
|
65
|
-
decimal: "Decimals",
|
|
66
|
-
improper: "Improper fractions",
|
|
67
|
-
mixed: "Mixed numbers",
|
|
68
|
-
"non-reduced": "Non-reduced",
|
|
69
|
-
};
|
|
70
|
-
Object.entries(styles).forEach(([key, title]) => {
|
|
71
|
-
it(`should be possible to update style: ${title}`, async () => {
|
|
72
|
-
const onChangeMock = jest.fn();
|
|
73
|
-
|
|
74
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
75
|
-
|
|
76
|
-
userEvent.click(screen.getByTitle(title));
|
|
77
|
-
|
|
78
|
-
expect(onChangeMock).toBeCalledWith({labelStyle: key});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("should be possible to change show tick controller", async () => {
|
|
83
|
-
const onChangeMock = jest.fn();
|
|
84
|
-
|
|
85
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
86
|
-
|
|
87
|
-
userEvent.click(
|
|
88
|
-
screen.getByRole("checkbox", {name: "Show tick controller"}),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(onChangeMock).toBeCalledWith({isTickCtrl: true});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("should be possible to change show label tickets", async () => {
|
|
95
|
-
const onChangeMock = jest.fn();
|
|
96
|
-
|
|
97
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
98
|
-
|
|
99
|
-
userEvent.click(
|
|
100
|
-
screen.getByRole("checkbox", {name: "Show label ticks"}),
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
expect(onChangeMock).toBeCalledWith({labelTicks: false});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should be possible to change show tooltips", async () => {
|
|
107
|
-
const onChangeMock = jest.fn();
|
|
108
|
-
|
|
109
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
110
|
-
|
|
111
|
-
userEvent.click(screen.getByRole("checkbox", {name: "Show tooltips"}));
|
|
112
|
-
|
|
113
|
-
expect(onChangeMock).toBeCalledWith({showTooltips: true});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should be possible to update tick steps", async () => {
|
|
117
|
-
const onChangeMock = jest.fn();
|
|
118
|
-
|
|
119
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
120
|
-
|
|
121
|
-
const input = screen.getByRole("textbox", {
|
|
122
|
-
name: "or tick step:",
|
|
123
|
-
});
|
|
124
|
-
userEvent.type(input, "6");
|
|
125
|
-
|
|
126
|
-
expect(onChangeMock).toBeCalledWith({
|
|
127
|
-
numDivisions: null,
|
|
128
|
-
tickStep: 6,
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should be possible to update snap divisions", async () => {
|
|
133
|
-
const onChangeMock = jest.fn();
|
|
134
|
-
|
|
135
|
-
render(<NumberLineEditor onChange={onChangeMock} />);
|
|
136
|
-
|
|
137
|
-
const input = screen.getByRole("textbox", {
|
|
138
|
-
name: "Snap increments per tick:",
|
|
139
|
-
});
|
|
140
|
-
userEvent.type(input, "6");
|
|
141
|
-
|
|
142
|
-
expect(onChangeMock).toBeCalledWith({snapDivisions: 26});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,177 +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 NumericInputEditor from "../numeric-input-editor";
|
|
10
|
-
|
|
11
|
-
describe("numeric-input-editor", () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
|
|
14
|
-
testDependencies,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should render", async () => {
|
|
19
|
-
render(<NumericInputEditor onChange={() => undefined} />);
|
|
20
|
-
|
|
21
|
-
expect(await screen.findByText(/Add new answer/)).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should be possible to select normal width", async () => {
|
|
25
|
-
const onChangeMock = jest.fn();
|
|
26
|
-
|
|
27
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
28
|
-
|
|
29
|
-
userEvent.click(screen.getByRole("button", {name: "Normal (80px)"}));
|
|
30
|
-
|
|
31
|
-
expect(onChangeMock).toBeCalledWith(
|
|
32
|
-
expect.objectContaining({size: "normal"}),
|
|
33
|
-
undefined,
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should be possible to select small width", async () => {
|
|
38
|
-
const onChangeMock = jest.fn();
|
|
39
|
-
|
|
40
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
41
|
-
|
|
42
|
-
userEvent.click(screen.getByRole("button", {name: "Small (40px)"}));
|
|
43
|
-
|
|
44
|
-
expect(onChangeMock).toBeCalledWith(
|
|
45
|
-
expect.objectContaining({size: "small"}),
|
|
46
|
-
undefined,
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should be possible to select right alignment", async () => {
|
|
51
|
-
const onChangeMock = jest.fn();
|
|
52
|
-
|
|
53
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
54
|
-
|
|
55
|
-
userEvent.click(
|
|
56
|
-
screen.getByRole("checkbox", {name: "Right alignment"}),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
expect(onChangeMock).toBeCalledWith({rightAlign: true});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should be possible to select coefficient", async () => {
|
|
63
|
-
const onChangeMock = jest.fn();
|
|
64
|
-
|
|
65
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
66
|
-
|
|
67
|
-
userEvent.click(screen.getByRole("checkbox", {name: "Coefficient"}));
|
|
68
|
-
|
|
69
|
-
expect(onChangeMock).toBeCalledWith({coefficient: true});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should be possible to update label text", async () => {
|
|
73
|
-
const onChangeMock = jest.fn();
|
|
74
|
-
|
|
75
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
76
|
-
|
|
77
|
-
const input = screen.getByRole("textbox", {
|
|
78
|
-
name: "Label text:",
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
userEvent.type(input, "a");
|
|
82
|
-
|
|
83
|
-
expect(onChangeMock).toBeCalledWith(
|
|
84
|
-
expect.objectContaining({labelText: "a"}),
|
|
85
|
-
undefined,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should be possible to toggle options", async () => {
|
|
90
|
-
render(<NumericInputEditor onChange={() => {}} />);
|
|
91
|
-
|
|
92
|
-
userEvent.click(screen.getByRole("link", {name: "Toggle options"}));
|
|
93
|
-
|
|
94
|
-
expect(
|
|
95
|
-
screen.getByText("Unsimplified answers are"),
|
|
96
|
-
).toBeInTheDocument();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should be possible to set unsimplified answers to ungraded", async () => {
|
|
100
|
-
const onChangeMock = jest.fn();
|
|
101
|
-
|
|
102
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
103
|
-
|
|
104
|
-
userEvent.click(screen.getByRole("link", {name: "Toggle options"}));
|
|
105
|
-
userEvent.click(screen.getByRole("button", {name: "ungraded"}));
|
|
106
|
-
|
|
107
|
-
expect(onChangeMock).toBeCalledWith(
|
|
108
|
-
expect.objectContaining({
|
|
109
|
-
answers: expect.arrayContaining([
|
|
110
|
-
expect.objectContaining({simplify: "required"}),
|
|
111
|
-
]),
|
|
112
|
-
}),
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should be possible to set unsimplified answers to accepted", async () => {
|
|
117
|
-
const onChangeMock = jest.fn();
|
|
118
|
-
|
|
119
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
120
|
-
|
|
121
|
-
userEvent.click(screen.getByRole("link", {name: "Toggle options"}));
|
|
122
|
-
userEvent.click(screen.getByRole("button", {name: "accepted"}));
|
|
123
|
-
|
|
124
|
-
expect(onChangeMock).toBeCalledWith(
|
|
125
|
-
expect.objectContaining({
|
|
126
|
-
answers: expect.arrayContaining([
|
|
127
|
-
expect.objectContaining({simplify: "optional"}),
|
|
128
|
-
]),
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should be possible to set unsimplified answers to wrong", async () => {
|
|
134
|
-
const onChangeMock = jest.fn();
|
|
135
|
-
|
|
136
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
137
|
-
|
|
138
|
-
userEvent.click(screen.getByRole("link", {name: "Toggle options"}));
|
|
139
|
-
userEvent.click(screen.getByRole("button", {name: "wrong"}));
|
|
140
|
-
|
|
141
|
-
expect(onChangeMock).toBeCalledWith(
|
|
142
|
-
expect.objectContaining({
|
|
143
|
-
answers: expect.arrayContaining([
|
|
144
|
-
expect.objectContaining({simplify: "enforced"}),
|
|
145
|
-
]),
|
|
146
|
-
}),
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const answerFormats = {
|
|
151
|
-
integer: "Integers",
|
|
152
|
-
decimal: "Decimals",
|
|
153
|
-
proper: "Proper fractions",
|
|
154
|
-
improper: "Improper fractions",
|
|
155
|
-
mixed: "Mixed numbers",
|
|
156
|
-
pi: "Numbers with π",
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
Object.entries(answerFormats).forEach(([key, name]) => {
|
|
160
|
-
it(`should be possible to set suggested answer format to: ${name}`, async () => {
|
|
161
|
-
const onChangeMock = jest.fn();
|
|
162
|
-
|
|
163
|
-
render(<NumericInputEditor onChange={onChangeMock} />);
|
|
164
|
-
|
|
165
|
-
userEvent.click(screen.getByRole("link", {name: "Toggle options"}));
|
|
166
|
-
userEvent.click(screen.getByTitle(name));
|
|
167
|
-
|
|
168
|
-
expect(onChangeMock).toBeCalledWith(
|
|
169
|
-
expect.objectContaining({
|
|
170
|
-
answers: expect.arrayContaining([
|
|
171
|
-
expect.objectContaining({answerForms: [key]}),
|
|
172
|
-
]),
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import {Dependencies, ApiOptions} 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 RadioEditor from "../radio/editor";
|
|
10
|
-
|
|
11
|
-
describe("radio-editor", () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
|
|
14
|
-
testDependencies,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should render", async () => {
|
|
19
|
-
render(
|
|
20
|
-
<RadioEditor
|
|
21
|
-
onChange={() => undefined}
|
|
22
|
-
apiOptions={ApiOptions.defaults}
|
|
23
|
-
/>,
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
expect(
|
|
27
|
-
await screen.findByText(/Multiple selections/),
|
|
28
|
-
).toBeInTheDocument();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should toggle multiple select checkbox", () => {
|
|
32
|
-
const onChangeMock = jest.fn();
|
|
33
|
-
|
|
34
|
-
render(
|
|
35
|
-
<RadioEditor
|
|
36
|
-
onChange={onChangeMock}
|
|
37
|
-
apiOptions={ApiOptions.defaults}
|
|
38
|
-
/>,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
userEvent.click(
|
|
42
|
-
screen.getByRole("checkbox", {
|
|
43
|
-
name: "Multiple selections",
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(onChangeMock).toBeCalledWith({multipleSelect: true});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should toggle randomize order checkbox", () => {
|
|
51
|
-
const onChangeMock = jest.fn();
|
|
52
|
-
|
|
53
|
-
render(
|
|
54
|
-
<RadioEditor
|
|
55
|
-
onChange={onChangeMock}
|
|
56
|
-
apiOptions={ApiOptions.defaults}
|
|
57
|
-
/>,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
userEvent.click(
|
|
61
|
-
screen.getByRole("checkbox", {
|
|
62
|
-
name: "Randomize order",
|
|
63
|
-
}),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
expect(onChangeMock).toBeCalledWith({randomize: true});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should be possible to add answer", () => {
|
|
70
|
-
const onChangeMock = jest.fn();
|
|
71
|
-
|
|
72
|
-
render(
|
|
73
|
-
<RadioEditor
|
|
74
|
-
onChange={onChangeMock}
|
|
75
|
-
apiOptions={ApiOptions.defaults}
|
|
76
|
-
/>,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
userEvent.click(
|
|
80
|
-
screen.getAllByRole("link", {
|
|
81
|
-
name: "Add a choice",
|
|
82
|
-
})[0],
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
expect(onChangeMock).toBeCalledWith(
|
|
86
|
-
expect.objectContaining({
|
|
87
|
-
choices: [{}, {}, {isNoneOfTheAbove: false}],
|
|
88
|
-
hasNoneOfTheAbove: false,
|
|
89
|
-
}),
|
|
90
|
-
// there's some anonymous function that's also passed
|
|
91
|
-
expect.anything(),
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should be possible to delete answer", () => {
|
|
96
|
-
const onChangeMock = jest.fn();
|
|
97
|
-
|
|
98
|
-
render(
|
|
99
|
-
<RadioEditor
|
|
100
|
-
onChange={onChangeMock}
|
|
101
|
-
apiOptions={ApiOptions.defaults}
|
|
102
|
-
/>,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
userEvent.click(
|
|
106
|
-
screen.getAllByRole("link", {
|
|
107
|
-
name: "Remove this choice",
|
|
108
|
-
})[0],
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(onChangeMock).toBeCalledWith(
|
|
112
|
-
expect.objectContaining({
|
|
113
|
-
choices: [{}],
|
|
114
|
-
hasNoneOfTheAbove: false,
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,55 +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 SorterEditor from "../sorter-editor";
|
|
10
|
-
|
|
11
|
-
describe("sorter-editor", () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
|
|
14
|
-
testDependencies,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("renders", async () => {
|
|
19
|
-
render(<SorterEditor onChange={() => {}} />);
|
|
20
|
-
|
|
21
|
-
expect(screen.getByText("Correct answer:")).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should be possible to change layout to vertical", async () => {
|
|
25
|
-
const onChangeMock = jest.fn();
|
|
26
|
-
|
|
27
|
-
render(<SorterEditor onChange={onChangeMock} />);
|
|
28
|
-
|
|
29
|
-
const select = screen.getByRole("combobox", {name: "Layout:"});
|
|
30
|
-
userEvent.selectOptions(select, "vertical");
|
|
31
|
-
|
|
32
|
-
expect(onChangeMock).toBeCalledWith({layout: "vertical"});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should be possible to change layout to horizontal", async () => {
|
|
36
|
-
const onChangeMock = jest.fn();
|
|
37
|
-
|
|
38
|
-
render(<SorterEditor onChange={onChangeMock} />);
|
|
39
|
-
|
|
40
|
-
const select = screen.getByRole("combobox", {name: "Layout:"});
|
|
41
|
-
userEvent.selectOptions(select, "horizontal");
|
|
42
|
-
|
|
43
|
-
expect(onChangeMock).toBeCalledWith({layout: "horizontal"});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should be possible to change padding", async () => {
|
|
47
|
-
const onChangeMock = jest.fn();
|
|
48
|
-
|
|
49
|
-
render(<SorterEditor onChange={onChangeMock} />);
|
|
50
|
-
|
|
51
|
-
userEvent.click(screen.getByRole("checkbox", {name: "Padding:"}));
|
|
52
|
-
|
|
53
|
-
expect(onChangeMock).toBeCalledWith({padding: false});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
components,
|
|
3
|
-
ApiOptions,
|
|
4
|
-
Categorizer as CategorizerWidget,
|
|
5
|
-
Changeable,
|
|
6
|
-
EditorJsonify,
|
|
7
|
-
} from "@khanacademy/perseus";
|
|
8
|
-
import PropTypes from "prop-types";
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
import _ from "underscore";
|
|
11
|
-
|
|
12
|
-
const {PropCheckBox, TextListEditor} = components;
|
|
13
|
-
const Categorizer = CategorizerWidget.widget;
|
|
14
|
-
|
|
15
|
-
type Props = any;
|
|
16
|
-
|
|
17
|
-
class CategorizerEditor extends React.Component<Props> {
|
|
18
|
-
static propTypes = {
|
|
19
|
-
...Changeable.propTypes,
|
|
20
|
-
apiOptions: ApiOptions.propTypes,
|
|
21
|
-
items: PropTypes.arrayOf(PropTypes.string),
|
|
22
|
-
categories: PropTypes.arrayOf(PropTypes.string),
|
|
23
|
-
values: PropTypes.arrayOf(PropTypes.number),
|
|
24
|
-
randomizeItems: PropTypes.bool,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
static widgetName = "categorizer" as const;
|
|
28
|
-
|
|
29
|
-
static defaultProps: Props = {
|
|
30
|
-
items: [],
|
|
31
|
-
categories: [],
|
|
32
|
-
values: [],
|
|
33
|
-
randomizeItems: false,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
37
|
-
return Changeable.change.apply(this, args);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
serialize: () => any = () => {
|
|
41
|
-
return EditorJsonify.serialize.call(this);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
render(): React.ReactNode {
|
|
45
|
-
return (
|
|
46
|
-
<div>
|
|
47
|
-
<div className="perseus-widget-row">
|
|
48
|
-
<PropCheckBox
|
|
49
|
-
label="Randomize item order"
|
|
50
|
-
labelAlignment="right"
|
|
51
|
-
randomizeItems={this.props.randomizeItems}
|
|
52
|
-
onChange={this.props.onChange}
|
|
53
|
-
/>
|
|
54
|
-
</div>
|
|
55
|
-
Categories:
|
|
56
|
-
<TextListEditor
|
|
57
|
-
options={this.props.categories}
|
|
58
|
-
onChange={(cat) => {
|
|
59
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
|
|
60
|
-
this.change("categories", cat);
|
|
61
|
-
}}
|
|
62
|
-
layout="horizontal"
|
|
63
|
-
/>
|
|
64
|
-
Items:
|
|
65
|
-
<TextListEditor
|
|
66
|
-
options={this.props.items}
|
|
67
|
-
onChange={(items) => {
|
|
68
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
69
|
-
this.change({
|
|
70
|
-
items: items,
|
|
71
|
-
// TODO(eater): This truncates props.values so there
|
|
72
|
-
// are never more correct answers than items,
|
|
73
|
-
// ensuring the widget is possible to answer
|
|
74
|
-
// correctly. It doesn't necessarly keep each
|
|
75
|
-
// answer with its corresponding item if an item
|
|
76
|
-
// is deleted from the middle. Inconvenient, but
|
|
77
|
-
// it's at least possible for content creators to
|
|
78
|
-
// catch and fix.
|
|
79
|
-
values: _.first(this.props.values, items.length),
|
|
80
|
-
});
|
|
81
|
-
}}
|
|
82
|
-
layout="vertical"
|
|
83
|
-
/>
|
|
84
|
-
{/* There are a bunch of props that renderer.jsx passes to each widget
|
|
85
|
-
via widget-container.jsx that we aren't passing to Categorizer here.
|
|
86
|
-
See perseus-all-package/types.js#WidgetProps for details. */}
|
|
87
|
-
{/* @ts-expect-error - TS2769 - No overload matches this call. */}
|
|
88
|
-
<Categorizer
|
|
89
|
-
apiOptions={this.props.apiOptions}
|
|
90
|
-
items={this.props.items}
|
|
91
|
-
categories={this.props.categories}
|
|
92
|
-
values={this.props.values}
|
|
93
|
-
onChange={(newProps) => {
|
|
94
|
-
this.props.onChange(newProps);
|
|
95
|
-
}}
|
|
96
|
-
// eslint-disable-next-line react/jsx-no-bind
|
|
97
|
-
trackInteraction={function () {}}
|
|
98
|
-
/>
|
|
99
|
-
</div>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default CategorizerEditor;
|