@khanacademy/perseus 19.1.4 → 19.1.5
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/CHANGELOG.md +10 -0
- package/dist/components/graphie.d.ts +9 -1
- package/dist/es/index.js +255 -122
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +261 -126
- package/dist/index.js.map +1 -1
- package/dist/interactive2/interactive-util.d.ts +1 -1
- package/dist/interactive2/movable-point-options.d.ts +5 -4
- package/dist/interactive2/movable.d.ts +90 -13
- package/dist/interactive2/types.d.ts +6 -0
- package/dist/util/graphie.d.ts +5 -0
- package/dist/widgets/expression.d.ts +4 -4
- package/package.json +3 -3
- package/src/components/graphie.tsx +9 -1
- package/src/interactive2/__tests__/movable-mock.ts +42 -30
- package/src/interactive2/movable-point-options.ts +31 -19
- package/src/interactive2/movable.test.ts +249 -0
- package/src/interactive2/movable.ts +289 -131
- package/src/interactive2/types.ts +15 -0
- package/src/interactive2.ts +1 -1
- package/src/util/graphie.ts +10 -0
- package/src/util/interactive.ts +4 -2
- package/tsconfig-build.tsbuildinfo +1 -1
- package/src/interactive2/__tests__/movable.test.ts +0 -157
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/* eslint-disable testing-library/prefer-user-event */
|
|
2
|
-
import {fireEvent} from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
import {Graphie} from "../../util/graphie";
|
|
5
|
-
import Movable from "../movable";
|
|
6
|
-
|
|
7
|
-
// Yay for side-effect imports!
|
|
8
|
-
// eslint-disable-next-line import/no-unassigned-import
|
|
9
|
-
import "../../util/interactive";
|
|
10
|
-
|
|
11
|
-
describe("Movable", () => {
|
|
12
|
-
it("should be constructable", () => {
|
|
13
|
-
const movable = new Movable(
|
|
14
|
-
new Graphie(document.createElement("div")),
|
|
15
|
-
{},
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
expect(movable).toBeDefined();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should have accessor properties", () => {
|
|
22
|
-
const movable = new Movable(
|
|
23
|
-
new Graphie(document.createElement("div")),
|
|
24
|
-
{},
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
expect(typeof movable.isHovering).toBe("function");
|
|
28
|
-
expect(typeof movable.cursor).toBe("function");
|
|
29
|
-
expect(typeof movable.added).toBe("function");
|
|
30
|
-
expect(typeof movable.isHovering).toBe("function");
|
|
31
|
-
expect(typeof movable.isMouseOver).toBe("function");
|
|
32
|
-
expect(typeof movable.isDragging).toBe("function");
|
|
33
|
-
expect(typeof movable.mouseTarget).toBe("function");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("cloneState()", () => {
|
|
37
|
-
const movable = new Movable(
|
|
38
|
-
new Graphie(document.createElement("div")),
|
|
39
|
-
{},
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
expect(movable.cloneState()).toEqual(
|
|
43
|
-
expect.objectContaining({
|
|
44
|
-
id: expect.any(String),
|
|
45
|
-
add: [],
|
|
46
|
-
added: true,
|
|
47
|
-
cursor: null,
|
|
48
|
-
draw: [],
|
|
49
|
-
isDragging: false,
|
|
50
|
-
isHovering: false,
|
|
51
|
-
isMouseOver: false,
|
|
52
|
-
modify: [],
|
|
53
|
-
mouseTarget: null,
|
|
54
|
-
onClick: [],
|
|
55
|
-
onMove: [],
|
|
56
|
-
onMoveEnd: [],
|
|
57
|
-
onMoveStart: [],
|
|
58
|
-
remove: [],
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("cloneState() should copy state", () => {
|
|
64
|
-
const movable = new Movable(
|
|
65
|
-
new Graphie(document.createElement("div")),
|
|
66
|
-
{},
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(movable.cloneState()).not.toBe(movable.state);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("modify() resets movable to initial state when no params given", () => {
|
|
73
|
-
const movable = new Movable(
|
|
74
|
-
new Graphie(document.createElement("div")),
|
|
75
|
-
{},
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const state = movable.cloneState();
|
|
79
|
-
movable.state.added = false;
|
|
80
|
-
|
|
81
|
-
// It seems that all usages of this function in our production code
|
|
82
|
-
// pass the original state + mutations to modify(). However, it _does_
|
|
83
|
-
// work to pass no arguments so we'll keep this Characterization test
|
|
84
|
-
// here for now.
|
|
85
|
-
movable.modify();
|
|
86
|
-
|
|
87
|
-
expect(movable.cloneState()).toEqual(state);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("modify() retains original ID", () => {
|
|
91
|
-
const movable = new Movable(
|
|
92
|
-
new Graphie(document.createElement("div")),
|
|
93
|
-
{},
|
|
94
|
-
);
|
|
95
|
-
const id = movable.state.id;
|
|
96
|
-
|
|
97
|
-
movable.modify({added: true});
|
|
98
|
-
|
|
99
|
-
expect(movable.state.id).toBe(id);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("grab() fires onMoveStart", () => {
|
|
103
|
-
const graphie = new Graphie(document.createElement("div"));
|
|
104
|
-
graphie.init({
|
|
105
|
-
range: [
|
|
106
|
-
[-10, 10],
|
|
107
|
-
[-10, 10],
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
const onMoveStart = jest.fn();
|
|
111
|
-
const movable = new Movable(graphie, {onMoveStart});
|
|
112
|
-
|
|
113
|
-
movable.grab([0, 0]);
|
|
114
|
-
|
|
115
|
-
expect(onMoveStart).toHaveBeenCalledWith([0, 0], [0, 0]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("grab() fires onMove when mouse moves", () => {
|
|
119
|
-
const graphie = new Graphie(document.createElement("div"));
|
|
120
|
-
graphie.init({
|
|
121
|
-
range: [
|
|
122
|
-
[-10, 10],
|
|
123
|
-
[-10, 10],
|
|
124
|
-
],
|
|
125
|
-
scale: [10, 10],
|
|
126
|
-
});
|
|
127
|
-
const onMove = jest.fn();
|
|
128
|
-
const movable = new Movable(graphie, {onMove});
|
|
129
|
-
|
|
130
|
-
movable.grab([0, 0]);
|
|
131
|
-
fireEvent.mouseMove(document, {clientX: 120, clientY: 80});
|
|
132
|
-
|
|
133
|
-
expect(onMove).toHaveBeenCalledWith([2, 2], [0, 0]);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test("grab() fires onMoveEnd when mouse up", () => {
|
|
137
|
-
const dummyGraphie: any = {};
|
|
138
|
-
const onMoveEnd = jest.fn();
|
|
139
|
-
const movable = new Movable(dummyGraphie, {onMoveEnd});
|
|
140
|
-
|
|
141
|
-
movable.grab([0, 0]);
|
|
142
|
-
fireEvent.mouseUp(document);
|
|
143
|
-
|
|
144
|
-
expect(onMoveEnd).toHaveBeenCalledWith([0, 0], [0, 0]);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test("grab() fires onClick if still hovering when mouse up", () => {
|
|
148
|
-
const dummyGraphie: any = {};
|
|
149
|
-
const onClick = jest.fn();
|
|
150
|
-
const movable = new Movable(dummyGraphie, {onClick});
|
|
151
|
-
|
|
152
|
-
movable.grab([0, 0]);
|
|
153
|
-
fireEvent.mouseUp(document);
|
|
154
|
-
|
|
155
|
-
expect(onClick).toHaveBeenCalledWith([0, 0], [0, 0]);
|
|
156
|
-
});
|
|
157
|
-
});
|