@pie-lib/graphing 2.14.22 → 2.15.0-beta.2
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 +21 -72
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +15 -9
- package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
- package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
- package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
- package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
- package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
- package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
- package/src/__tests__/graph-with-controls.test.jsx +147 -0
- package/src/__tests__/graph.test.jsx +230 -0
- package/src/__tests__/grid.test.jsx +20 -0
- package/src/__tests__/labels.test.jsx +38 -0
- package/src/__tests__/mark-label.test.jsx +68 -0
- package/src/__tests__/toggle-bar.test.jsx +36 -0
- package/src/__tests__/tool-menu.test.jsx +29 -0
- package/src/__tests__/undo-redo.test.jsx +25 -0
- package/src/__tests__/use-debounce.test.js +21 -0
- package/src/__tests__/utils.js +38 -0
- package/src/__tests__/utils.test.js +151 -0
- package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
- package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
- package/src/axis/__tests__/arrow.test.jsx +39 -0
- package/src/axis/__tests__/axes.test.jsx +220 -0
- package/src/axis/axes.jsx +5 -5
- package/src/container/index.jsx +2 -4
- package/src/coordinates-label.jsx +4 -3
- package/src/graph-with-controls.jsx +8 -10
- package/src/graph.jsx +22 -10
- package/src/grid.jsx +8 -10
- package/src/index.js +2 -2
- package/src/key-legend.jsx +145 -0
- package/src/label-svg-icon.jsx +39 -0
- package/src/labels.jsx +2 -1
- package/src/mark-label.jsx +149 -52
- package/src/toggle-bar.jsx +1 -2
- package/src/tool-menu.jsx +3 -26
- package/src/tools/absolute/__tests__/component.test.jsx +54 -0
- package/src/tools/absolute/component.jsx +23 -0
- package/src/tools/absolute/index.js +31 -0
- package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
- package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
- package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
- package/src/tools/circle/__tests__/component.test.jsx +228 -0
- package/src/tools/circle/bg-circle.jsx +5 -4
- package/src/tools/circle/component.jsx +22 -8
- package/src/tools/exponential/__tests__/component.test.jsx +54 -0
- package/src/tools/exponential/component.jsx +23 -0
- package/src/tools/exponential/index.js +39 -0
- package/src/tools/index.js +38 -5
- package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
- package/src/tools/line/__tests__/component.test.jsx +36 -0
- package/src/tools/line/component.jsx +2 -1
- package/src/tools/parabola/__tests__/component.test.jsx +49 -0
- package/src/tools/parabola/component.jsx +7 -6
- package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
- package/src/tools/point/__tests__/component.test.jsx +66 -0
- package/src/tools/point/component.jsx +12 -6
- package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
- package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
- package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
- package/src/tools/polygon/__tests__/component.test.jsx +226 -0
- package/src/tools/polygon/__tests__/index.test.js +65 -0
- package/src/tools/polygon/__tests__/line.test.jsx +25 -0
- package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
- package/src/tools/polygon/component.jsx +39 -11
- package/src/tools/polygon/line.jsx +15 -7
- package/src/tools/polygon/polygon.jsx +7 -3
- package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
- package/src/tools/ray/__tests__/component.test.jsx +29 -0
- package/src/tools/ray/component.jsx +2 -1
- package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
- package/src/tools/segment/__tests__/component.test.jsx +28 -0
- package/src/tools/segment/component.jsx +2 -1
- package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
- package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
- package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
- package/src/tools/shared/icons/MissingSVG.jsx +21 -0
- package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
- package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
- package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
- package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
- package/src/tools/shared/line/index.jsx +39 -13
- package/src/tools/shared/line/line-path.jsx +18 -7
- package/src/tools/shared/line/with-root-edge.jsx +10 -3
- package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
- package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
- package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
- package/src/tools/shared/point/arrow-point.jsx +4 -1
- package/src/tools/shared/point/arrow.jsx +4 -1
- package/src/tools/shared/point/base-point.jsx +28 -3
- package/src/tools/shared/point/index.jsx +7 -2
- package/src/tools/shared/styles.js +8 -3
- package/src/tools/sine/__tests__/component.test.jsx +51 -0
- package/src/tools/sine/component.jsx +7 -7
- package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
- package/src/tools/vector/__tests__/component.test.jsx +26 -0
- package/src/tools/vector/component.jsx +2 -1
- package/src/undo-redo.jsx +0 -1
- package/src/utils.js +1 -1
- package/legacy.png +0 -0
- package/lib/axis/arrow.js +0 -115
- package/lib/axis/arrow.js.map +0 -1
- package/lib/axis/axes.js +0 -415
- package/lib/axis/axes.js.map +0 -1
- package/lib/axis/index.js +0 -26
- package/lib/axis/index.js.map +0 -1
- package/lib/bg.js +0 -139
- package/lib/bg.js.map +0 -1
- package/lib/container/actions.js +0 -24
- package/lib/container/actions.js.map +0 -1
- package/lib/container/index.js +0 -166
- package/lib/container/index.js.map +0 -1
- package/lib/container/marks.js +0 -27
- package/lib/container/marks.js.map +0 -1
- package/lib/container/middleware.js +0 -25
- package/lib/container/middleware.js.map +0 -1
- package/lib/container/reducer.js +0 -25
- package/lib/container/reducer.js.map +0 -1
- package/lib/coordinates-label.js +0 -107
- package/lib/coordinates-label.js.map +0 -1
- package/lib/graph-with-controls.js +0 -366
- package/lib/graph-with-controls.js.map +0 -1
- package/lib/graph.js +0 -354
- package/lib/graph.js.map +0 -1
- package/lib/grid-setup.js +0 -462
- package/lib/grid-setup.js.map +0 -1
- package/lib/grid.js +0 -184
- package/lib/grid.js.map +0 -1
- package/lib/index.js +0 -51
- package/lib/index.js.map +0 -1
- package/lib/labels.js +0 -298
- package/lib/labels.js.map +0 -1
- package/lib/mark-label.js +0 -210
- package/lib/mark-label.js.map +0 -1
- package/lib/toggle-bar.js +0 -337
- package/lib/toggle-bar.js.map +0 -1
- package/lib/tool-menu.js +0 -132
- package/lib/tool-menu.js.map +0 -1
- package/lib/tools/circle/bg-circle.js +0 -172
- package/lib/tools/circle/bg-circle.js.map +0 -1
- package/lib/tools/circle/component.js +0 -387
- package/lib/tools/circle/component.js.map +0 -1
- package/lib/tools/circle/index.js +0 -51
- package/lib/tools/circle/index.js.map +0 -1
- package/lib/tools/index.js +0 -79
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/line/component.js +0 -102
- package/lib/tools/line/component.js.map +0 -1
- package/lib/tools/line/index.js +0 -16
- package/lib/tools/line/index.js.map +0 -1
- package/lib/tools/parabola/component.js +0 -33
- package/lib/tools/parabola/component.js.map +0 -1
- package/lib/tools/parabola/index.js +0 -63
- package/lib/tools/parabola/index.js.map +0 -1
- package/lib/tools/point/component.js +0 -181
- package/lib/tools/point/component.js.map +0 -1
- package/lib/tools/point/index.js +0 -32
- package/lib/tools/point/index.js.map +0 -1
- package/lib/tools/polygon/component.js +0 -505
- package/lib/tools/polygon/component.js.map +0 -1
- package/lib/tools/polygon/index.js +0 -106
- package/lib/tools/polygon/index.js.map +0 -1
- package/lib/tools/polygon/line.js +0 -151
- package/lib/tools/polygon/line.js.map +0 -1
- package/lib/tools/polygon/polygon.js +0 -162
- package/lib/tools/polygon/polygon.js.map +0 -1
- package/lib/tools/ray/component.js +0 -101
- package/lib/tools/ray/component.js.map +0 -1
- package/lib/tools/ray/index.js +0 -16
- package/lib/tools/ray/index.js.map +0 -1
- package/lib/tools/segment/component.js +0 -74
- package/lib/tools/segment/component.js.map +0 -1
- package/lib/tools/segment/index.js +0 -16
- package/lib/tools/segment/index.js.map +0 -1
- package/lib/tools/shared/arrow-head.js +0 -70
- package/lib/tools/shared/arrow-head.js.map +0 -1
- package/lib/tools/shared/line/index.js +0 -567
- package/lib/tools/shared/line/index.js.map +0 -1
- package/lib/tools/shared/line/line-path.js +0 -145
- package/lib/tools/shared/line/line-path.js.map +0 -1
- package/lib/tools/shared/line/with-root-edge.js +0 -144
- package/lib/tools/shared/line/with-root-edge.js.map +0 -1
- package/lib/tools/shared/point/arrow-point.js +0 -113
- package/lib/tools/shared/point/arrow-point.js.map +0 -1
- package/lib/tools/shared/point/arrow.js +0 -96
- package/lib/tools/shared/point/arrow.js.map +0 -1
- package/lib/tools/shared/point/base-point.js +0 -139
- package/lib/tools/shared/point/base-point.js.map +0 -1
- package/lib/tools/shared/point/index.js +0 -94
- package/lib/tools/shared/point/index.js.map +0 -1
- package/lib/tools/shared/styles.js +0 -49
- package/lib/tools/shared/styles.js.map +0 -1
- package/lib/tools/shared/types.js +0 -23
- package/lib/tools/shared/types.js.map +0 -1
- package/lib/tools/sine/component.js +0 -42
- package/lib/tools/sine/component.js.map +0 -1
- package/lib/tools/sine/index.js +0 -63
- package/lib/tools/sine/index.js.map +0 -1
- package/lib/tools/vector/component.js +0 -87
- package/lib/tools/vector/component.js.map +0 -1
- package/lib/tools/vector/index.js +0 -16
- package/lib/tools/vector/index.js.map +0 -1
- package/lib/undo-redo.js +0 -124
- package/lib/undo-redo.js.map +0 -1
- package/lib/use-debounce.js +0 -32
- package/lib/use-debounce.js.map +0 -1
- package/lib/utils.js +0 -307
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { xy } from './utils';
|
|
5
|
+
|
|
6
|
+
import Graph, { removeBuildingToolIfCurrentToolDiffers } from '../graph';
|
|
7
|
+
import { toolsArr } from '@pie-lib/tools';
|
|
8
|
+
|
|
9
|
+
describe('removeBuildingToolIfCurrentToolDiffers', () => {
|
|
10
|
+
let marks = [
|
|
11
|
+
{
|
|
12
|
+
type: 'point',
|
|
13
|
+
x: 2,
|
|
14
|
+
y: 2,
|
|
15
|
+
label: 'Point',
|
|
16
|
+
showLabel: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: 'line',
|
|
20
|
+
from: { x: 0, y: 0 },
|
|
21
|
+
label: 'Line',
|
|
22
|
+
building: true,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
it('keeps all marks if currentTool is the same', () => {
|
|
27
|
+
expect(removeBuildingToolIfCurrentToolDiffers({ marks, currentTool: { type: 'line' } })).toEqual(marks);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('removes building marks if currentTool is different', () => {
|
|
31
|
+
expect(removeBuildingToolIfCurrentToolDiffers({ marks, currentTool: { type: 'different' } })).toEqual([marks[0]]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('Graph', () => {
|
|
36
|
+
let onChangeMarks = jest.fn();
|
|
37
|
+
let wrapper;
|
|
38
|
+
|
|
39
|
+
const complete = jest.fn();
|
|
40
|
+
const addPoint = jest.fn();
|
|
41
|
+
const currentTool = toolsArr[0];
|
|
42
|
+
currentTool.complete = complete;
|
|
43
|
+
currentTool.addPoint = addPoint;
|
|
44
|
+
|
|
45
|
+
const props = {
|
|
46
|
+
classes: {},
|
|
47
|
+
className: 'className',
|
|
48
|
+
onChangeMarks,
|
|
49
|
+
tools: toolsArr,
|
|
50
|
+
domain: { min: 0, max: 1, step: 1 },
|
|
51
|
+
range: { min: 0, max: 1, step: 1 },
|
|
52
|
+
size: { width: 400, height: 400 },
|
|
53
|
+
currentTool,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
wrapper = (extras, opts) => {
|
|
58
|
+
const properties = {
|
|
59
|
+
...props,
|
|
60
|
+
marks: [
|
|
61
|
+
{
|
|
62
|
+
type: 'point',
|
|
63
|
+
x: 2,
|
|
64
|
+
y: 2,
|
|
65
|
+
label: 'Point',
|
|
66
|
+
showLabel: true,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'line',
|
|
70
|
+
from: { x: 0, y: 0 },
|
|
71
|
+
label: 'Line',
|
|
72
|
+
building: true,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
...extras,
|
|
76
|
+
};
|
|
77
|
+
console.log('props', props.marks);
|
|
78
|
+
return shallow(<Graph {...properties} />, opts);
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('snapshot', () => {
|
|
83
|
+
it('renders', () => {
|
|
84
|
+
jest.spyOn(Graph.prototype, 'generateMaskId').mockReturnValue('graph-1618');
|
|
85
|
+
let w = wrapper();
|
|
86
|
+
expect(w).toMatchSnapshot();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('logic', () => {
|
|
91
|
+
describe('componentDidMount', () => {
|
|
92
|
+
it('sets the labelNode to state', () => {
|
|
93
|
+
let w = shallow(<Graph {...props} />, { disableLifecycleMethods: true });
|
|
94
|
+
|
|
95
|
+
w.instance().labelNode = {};
|
|
96
|
+
w.instance().componentDidMount();
|
|
97
|
+
expect(w.state('labelNode')).toEqual(w.instance().labelNode);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('changeMark', () => {
|
|
102
|
+
it('does not call onChangeMarks', () => {
|
|
103
|
+
const newMark = { type: 'mark', x: 2, y: 2 };
|
|
104
|
+
|
|
105
|
+
let w = wrapper();
|
|
106
|
+
w.instance().changeMark(newMark, newMark);
|
|
107
|
+
expect(onChangeMarks).not.toBeCalled();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('calls onChangeMarks', () => {
|
|
111
|
+
const newMark = { type: 'mark', x: 2, y: 2 };
|
|
112
|
+
|
|
113
|
+
let w = wrapper();
|
|
114
|
+
let marks = w.instance().props.marks;
|
|
115
|
+
|
|
116
|
+
console.log('w model', w.instance().props.marks);
|
|
117
|
+
w.instance().changeMark(marks[0], newMark);
|
|
118
|
+
expect(onChangeMarks).toHaveBeenCalledWith([newMark, marks[1]]);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('completeMark', () => {
|
|
123
|
+
it('does not call updateMarks if no building mark', () => {
|
|
124
|
+
const updateMarks = jest.fn();
|
|
125
|
+
let w = wrapper({ marks: [{ type: 'point', x: 1, y: 1 }] });
|
|
126
|
+
|
|
127
|
+
w.instance().updateMarks = updateMarks;
|
|
128
|
+
w.instance().completeMark({ x: 3, y: 3 });
|
|
129
|
+
|
|
130
|
+
expect(complete).not.toBeCalled();
|
|
131
|
+
expect(updateMarks).not.toBeCalled();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('does not call updateMarks if no current tool', () => {
|
|
135
|
+
const updateMarks = jest.fn();
|
|
136
|
+
let w = wrapper({ currentTool: null });
|
|
137
|
+
|
|
138
|
+
w.instance().updateMarks = updateMarks;
|
|
139
|
+
w.instance().completeMark({ x: 3, y: 3 });
|
|
140
|
+
|
|
141
|
+
expect(complete).not.toBeCalled();
|
|
142
|
+
expect(updateMarks).not.toBeCalled();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('calls updateMarks', () => {
|
|
146
|
+
const updateMarks = jest.fn();
|
|
147
|
+
let w = wrapper();
|
|
148
|
+
|
|
149
|
+
w.instance().updateMarks = updateMarks;
|
|
150
|
+
w.instance().completeMark({ x: 3, y: 3 });
|
|
151
|
+
|
|
152
|
+
expect(complete).toHaveBeenCalled();
|
|
153
|
+
expect(updateMarks).toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('updateMarks', () => {
|
|
158
|
+
it('calls onChangeMarks', () => {
|
|
159
|
+
const marks = [{ type: 'mark', ...xy(2, 2) }];
|
|
160
|
+
const update = { type: 'mark', ...xy(4, 4) };
|
|
161
|
+
|
|
162
|
+
wrapper({ marks })
|
|
163
|
+
.instance()
|
|
164
|
+
.updateMarks(marks[0], update, false);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('calls onChangeMarks with added mark', () => {
|
|
168
|
+
const marks = [];
|
|
169
|
+
const update = { type: 'mark', ...xy(4, 4) };
|
|
170
|
+
|
|
171
|
+
wrapper({ marks })
|
|
172
|
+
.instance()
|
|
173
|
+
.updateMarks(marks[0], [update], true);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('getComponent', () => {
|
|
178
|
+
let compMock = jest.fn();
|
|
179
|
+
|
|
180
|
+
it('returns null if no mark', () => {
|
|
181
|
+
let w = wrapper();
|
|
182
|
+
|
|
183
|
+
expect(w.instance().getComponent()).toEqual(null);
|
|
184
|
+
expect(w.instance().getComponent(undefined)).toEqual(null);
|
|
185
|
+
expect(w.instance().getComponent(null)).toEqual(null);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('returns the component', () => {
|
|
189
|
+
let w = wrapper();
|
|
190
|
+
w.instance().props.tools[0].Component = compMock;
|
|
191
|
+
|
|
192
|
+
const Comp = w.instance().getComponent({ type: toolsArr[0].type });
|
|
193
|
+
expect(Comp).toEqual(compMock);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('returns null if there is no tool', () => {
|
|
197
|
+
let w = wrapper();
|
|
198
|
+
expect(w.instance().getComponent({ type: 'mark' })).toEqual(null);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('returns null if there is no tool.Component', () => {
|
|
202
|
+
let w = wrapper();
|
|
203
|
+
w.instance().props.tools[0].Component = undefined;
|
|
204
|
+
|
|
205
|
+
expect(w.instance().getComponent({ type: toolsArr[0].type })).toEqual(null);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('onBgClick', () => {
|
|
210
|
+
it('calls updateMarks', () => {
|
|
211
|
+
const buildingMark = { type: 'mark', building: true, x: 1, y: 1 };
|
|
212
|
+
const marks = [{ type: 'mark' }, buildingMark];
|
|
213
|
+
|
|
214
|
+
const updateMarks = jest.fn();
|
|
215
|
+
|
|
216
|
+
let w = wrapper({ marks });
|
|
217
|
+
w.instance().updateMarks = updateMarks;
|
|
218
|
+
w.instance().onBgClick({ x: 3, y: 3 });
|
|
219
|
+
expect(w.instance().updateMarks).toHaveBeenCalled();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('returns early of labelModeEnabled', () => {
|
|
223
|
+
let w = wrapper({ labelModeEnabled: true });
|
|
224
|
+
w.instance().updateMarks = jest.fn();
|
|
225
|
+
w.instance().onBgClick({ x: 3, y: 3 });
|
|
226
|
+
expect(w.instance().updateMarks).not.toHaveBeenCalled();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Grid } from '../grid';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
|
|
6
|
+
describe('Grid', () => {
|
|
7
|
+
let w;
|
|
8
|
+
const wrapper = (extras) => {
|
|
9
|
+
const defaults = {
|
|
10
|
+
classes: {},
|
|
11
|
+
className: 'className',
|
|
12
|
+
graphProps: graphProps(),
|
|
13
|
+
};
|
|
14
|
+
const props = { ...defaults, ...extras };
|
|
15
|
+
return shallow(<Grid {...props} />);
|
|
16
|
+
};
|
|
17
|
+
describe('snapshot', () => {
|
|
18
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import Labels, { getTransform } from '../labels';
|
|
5
|
+
|
|
6
|
+
describe('Labels', () => {
|
|
7
|
+
let w;
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const wrapper = (extras) => {
|
|
10
|
+
const defaults = {
|
|
11
|
+
classes: {},
|
|
12
|
+
className: 'className',
|
|
13
|
+
onChange,
|
|
14
|
+
};
|
|
15
|
+
const props = { ...defaults, ...extras };
|
|
16
|
+
return shallow(<Labels {...props} />);
|
|
17
|
+
};
|
|
18
|
+
describe('snapshot', () => {
|
|
19
|
+
it('renders', () => {
|
|
20
|
+
w = wrapper();
|
|
21
|
+
expect(w).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('getTransform', () => {
|
|
27
|
+
const assertTransform = (side, expected) => {
|
|
28
|
+
it(`returns ${expected} for ${side}`, () => {
|
|
29
|
+
const r = getTransform('left', 100, 100);
|
|
30
|
+
expect(r).toEqual('translate(-20, 50), rotate(-90)');
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
assertTransform('left', 'translate(-20, 50), rotate(-90)');
|
|
35
|
+
assertTransform('right', 'translate(130, 50), rotate(90)');
|
|
36
|
+
assertTransform('top', 'translate(50, -20), rotate(0)');
|
|
37
|
+
assertTransform('bottom', 'translate(50, 130), rotate(0)');
|
|
38
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { MarkLabel, position, coordinates } from '../mark-label';
|
|
4
|
+
import { graphProps as getGraphProps } from './utils';
|
|
5
|
+
|
|
6
|
+
const xyFn = () => {
|
|
7
|
+
const out = jest.fn((n) => n);
|
|
8
|
+
out.invert = jest.fn((n) => n);
|
|
9
|
+
return out;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe('MarkLabel', () => {
|
|
13
|
+
let w;
|
|
14
|
+
let onChange = jest.fn();
|
|
15
|
+
const wrapper = (extras) => {
|
|
16
|
+
const defaults = {
|
|
17
|
+
classes: {},
|
|
18
|
+
className: 'className',
|
|
19
|
+
onChange,
|
|
20
|
+
mark: { x: 1, y: 1 },
|
|
21
|
+
graphProps: getGraphProps(0, 10, 0, 10),
|
|
22
|
+
};
|
|
23
|
+
const props = { ...defaults, ...extras };
|
|
24
|
+
return shallow(<MarkLabel {...props} />);
|
|
25
|
+
};
|
|
26
|
+
describe('snapshot', () => {
|
|
27
|
+
it('renders', () => {
|
|
28
|
+
w = wrapper();
|
|
29
|
+
expect(w).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
it('renders', () => {
|
|
32
|
+
w = wrapper({ mark: { x: 10, y: 10 } });
|
|
33
|
+
expect(w).toMatchSnapshot();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('position', () => {
|
|
39
|
+
const assertPosition = (mark, rect, expected) => {
|
|
40
|
+
it(`${mark.x},${mark.y} + ${rect.width},${rect.height} => ${expected}`, () => {
|
|
41
|
+
// we set range.min to a value because in pixels - the greater the Y the lower down on the screen.
|
|
42
|
+
const graphProps = getGraphProps(0, 12, 12, 0);
|
|
43
|
+
const result = position(graphProps, mark, rect);
|
|
44
|
+
expect(result).toEqual(expected);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
assertPosition({ x: 0, y: 0 }, { width: 10, height: 10 }, 'top-left');
|
|
49
|
+
assertPosition({ x: 0, y: 0 }, { width: 1, height: 1 }, 'bottom-right');
|
|
50
|
+
assertPosition({ x: 0, y: 0 }, { width: 10, height: 0 }, 'bottom-left');
|
|
51
|
+
assertPosition({ x: 0, y: 0 }, { width: 0, height: 10 }, 'top-right');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('coordinates', () => {
|
|
55
|
+
const assertCoordinates = (mark, rect, pos, expected) => {
|
|
56
|
+
it(`${mark.x}, ${mark.y} -> ${pos} = ${expected.left}, ${expected.top}`, () => {
|
|
57
|
+
const result = coordinates(getGraphProps(), mark, rect, pos);
|
|
58
|
+
expect(result).toEqual(expected);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'top-left', { left: -5, top: -5 });
|
|
62
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'bottom-left', { left: -5, top: 5 });
|
|
63
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'top-right', { left: 5, top: -5 });
|
|
64
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'bottom-right', {
|
|
65
|
+
left: 5,
|
|
66
|
+
top: 5,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { ToggleBar } from '../toggle-bar';
|
|
5
|
+
|
|
6
|
+
describe('ToggleBar', () => {
|
|
7
|
+
let w;
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const wrapper = (extras) => {
|
|
10
|
+
const defaults = {
|
|
11
|
+
classes: {},
|
|
12
|
+
className: 'className',
|
|
13
|
+
onChange,
|
|
14
|
+
options: ['one', 'two'],
|
|
15
|
+
};
|
|
16
|
+
const props = { ...defaults, ...extras };
|
|
17
|
+
return shallow(<ToggleBar {...props} />);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('snapshot', () => {
|
|
21
|
+
it('renders', () => {
|
|
22
|
+
w = wrapper();
|
|
23
|
+
expect(w).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('logic', () => {
|
|
28
|
+
describe('select', () => {
|
|
29
|
+
it('calls onChange', () => {
|
|
30
|
+
w = wrapper();
|
|
31
|
+
w.instance().select({ target: { textContent: 'two' } });
|
|
32
|
+
expect(onChange).toHaveBeenLastCalledWith('two');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import ToolMenu from '../tool-menu';
|
|
5
|
+
|
|
6
|
+
describe('ToolMenu', () => {
|
|
7
|
+
let w;
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const tools = ['one', 'two'];
|
|
10
|
+
|
|
11
|
+
const wrapper = (extras) => {
|
|
12
|
+
const defaults = {
|
|
13
|
+
classes: {},
|
|
14
|
+
className: 'className',
|
|
15
|
+
onChange,
|
|
16
|
+
currentTool: tools[0],
|
|
17
|
+
tools,
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return shallow(<ToolMenu {...props} />);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('snapshot', () => {
|
|
24
|
+
it('renders', () => {
|
|
25
|
+
w = wrapper();
|
|
26
|
+
expect(w).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import UndoRedo from '../undo-redo';
|
|
4
|
+
|
|
5
|
+
describe('UndoRedo', () => {
|
|
6
|
+
let w;
|
|
7
|
+
let onUndo = jest.fn();
|
|
8
|
+
let onRedo = jest.fn();
|
|
9
|
+
let onReset = jest.fn();
|
|
10
|
+
const wrapper = (extras) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
onUndo,
|
|
13
|
+
onRedo,
|
|
14
|
+
onReset,
|
|
15
|
+
};
|
|
16
|
+
const props = { ...defaults, ...extras };
|
|
17
|
+
return shallow(<UndoRedo {...props} />);
|
|
18
|
+
};
|
|
19
|
+
describe('snapshot', () => {
|
|
20
|
+
it('renders', () => {
|
|
21
|
+
w = wrapper();
|
|
22
|
+
expect(w).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useDebounce } from '../use-debounce';
|
|
3
|
+
|
|
4
|
+
jest.useFakeTimers();
|
|
5
|
+
|
|
6
|
+
jest.mock('react', () => ({
|
|
7
|
+
useState: jest.fn(),
|
|
8
|
+
useEffect: jest.fn((fn, deps) => fn()),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe('useDebounce', () => {
|
|
12
|
+
it('..', () => {
|
|
13
|
+
const debouncedValue = null;
|
|
14
|
+
const setDebouncedValue = jest.fn();
|
|
15
|
+
|
|
16
|
+
useState.mockReturnValue([debouncedValue, setDebouncedValue]);
|
|
17
|
+
useDebounce('foo', 1000);
|
|
18
|
+
jest.runAllTimers();
|
|
19
|
+
expect(setDebouncedValue).toHaveBeenCalledWith('foo');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const scaleMock = () => {
|
|
2
|
+
const fn = jest.fn((n) => n);
|
|
3
|
+
fn.invert = jest.fn((n) => n);
|
|
4
|
+
return fn;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
8
|
+
scale: {
|
|
9
|
+
x: scaleMock(),
|
|
10
|
+
y: scaleMock(),
|
|
11
|
+
},
|
|
12
|
+
snap: {
|
|
13
|
+
x: jest.fn((n) => n),
|
|
14
|
+
y: jest.fn((n) => n),
|
|
15
|
+
},
|
|
16
|
+
domain: {
|
|
17
|
+
min: dmin,
|
|
18
|
+
max: dmax,
|
|
19
|
+
step: 1,
|
|
20
|
+
},
|
|
21
|
+
range: {
|
|
22
|
+
min: rmin,
|
|
23
|
+
max: rmax,
|
|
24
|
+
step: 1,
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
width: 400,
|
|
28
|
+
height: 400,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const xy = (x, y, index) => {
|
|
33
|
+
const out = { x, y, index };
|
|
34
|
+
if (!Number.isFinite(index)) {
|
|
35
|
+
delete out.index;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as utils from '../utils';
|
|
2
|
+
|
|
3
|
+
const xy = (x, y) => ({ x, y });
|
|
4
|
+
|
|
5
|
+
const tick = (isMajor, v) => ({
|
|
6
|
+
major: isMajor,
|
|
7
|
+
value: v,
|
|
8
|
+
x: v,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const major = tick.bind(null, true);
|
|
12
|
+
const minor = tick.bind(null, false);
|
|
13
|
+
|
|
14
|
+
describe('utils', () => {
|
|
15
|
+
describe('polygonToArea', () => {
|
|
16
|
+
const assertPolygon = (points, area) => {
|
|
17
|
+
it(`converts ${points} -> ${area}`, () => {
|
|
18
|
+
const result = utils.polygonToArea(points);
|
|
19
|
+
expect(result).toEqual(area);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
assertPolygon([xy(0, 0), xy(1, 1), xy(1, -1)], {
|
|
23
|
+
left: 0,
|
|
24
|
+
top: 1,
|
|
25
|
+
bottom: -1,
|
|
26
|
+
right: 1,
|
|
27
|
+
});
|
|
28
|
+
assertPolygon([xy(0, 0), xy(3, 0), xy(2, -1), xy(4, -3), xy(1, -4), xy(2, -2)], {
|
|
29
|
+
left: 0,
|
|
30
|
+
top: 0,
|
|
31
|
+
bottom: -4,
|
|
32
|
+
right: 4,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('lineToArea', () => {
|
|
37
|
+
const assertLine = (from, to, expected) => {
|
|
38
|
+
it(`${from},${to} => ${expected}`, () => {
|
|
39
|
+
const result = utils.lineToArea(from, to);
|
|
40
|
+
expect(result).toEqual(expected);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
assertLine(xy(1, 1), xy(2, 2), { left: 1, top: 2, bottom: 1, right: 2 });
|
|
45
|
+
assertLine(xy(-1, 4), xy(4, -3), {
|
|
46
|
+
left: -1,
|
|
47
|
+
top: 4,
|
|
48
|
+
bottom: -3,
|
|
49
|
+
right: 4,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('getTickValues', () => {
|
|
54
|
+
const assertGetTickValues = (props, expected) => {
|
|
55
|
+
it(` => ${expected}`, () => {
|
|
56
|
+
const result = utils.getTickValues(props);
|
|
57
|
+
expect(result).toEqual(expected);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
assertGetTickValues({ min: 0, max: 10, step: 1 }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
62
|
+
assertGetTickValues({ min: 0, max: 3, step: 0.5 }, [0, 0.5, 1, 1.5, 2, 2.5, 3]);
|
|
63
|
+
assertGetTickValues({ min: -0.2, max: 2, step: 0.6 }, [0, 0.6, 1.2, 1.8]);
|
|
64
|
+
assertGetTickValues({ min: -3.4, max: 6.2, step: 1.2 }, [0, -1.2, -2.4, 1.2, 2.4, 3.6, 4.8, 6]);
|
|
65
|
+
|
|
66
|
+
assertGetTickValues({ min: 0.6, max: 4.8, step: 0.3 }, [
|
|
67
|
+
0.6,
|
|
68
|
+
0.9,
|
|
69
|
+
1.2,
|
|
70
|
+
1.5,
|
|
71
|
+
1.8,
|
|
72
|
+
2.1,
|
|
73
|
+
2.4,
|
|
74
|
+
2.7,
|
|
75
|
+
3.0,
|
|
76
|
+
3.3,
|
|
77
|
+
3.6,
|
|
78
|
+
3.9,
|
|
79
|
+
4.2,
|
|
80
|
+
4.5,
|
|
81
|
+
4.8,
|
|
82
|
+
]);
|
|
83
|
+
assertGetTickValues({ min: 0.5, max: 4.9, step: 0.3 }, [
|
|
84
|
+
0.6,
|
|
85
|
+
0.9,
|
|
86
|
+
1.2,
|
|
87
|
+
1.5,
|
|
88
|
+
1.8,
|
|
89
|
+
2.1,
|
|
90
|
+
2.4,
|
|
91
|
+
2.7,
|
|
92
|
+
3.0,
|
|
93
|
+
3.3,
|
|
94
|
+
3.6,
|
|
95
|
+
3.9,
|
|
96
|
+
4.2,
|
|
97
|
+
4.5,
|
|
98
|
+
4.8,
|
|
99
|
+
]);
|
|
100
|
+
assertGetTickValues({ min: 0, max: 3, step: 0.125 }, [
|
|
101
|
+
0,
|
|
102
|
+
0.125,
|
|
103
|
+
0.25,
|
|
104
|
+
0.375,
|
|
105
|
+
0.5,
|
|
106
|
+
0.625,
|
|
107
|
+
0.75,
|
|
108
|
+
0.875,
|
|
109
|
+
1,
|
|
110
|
+
1.125,
|
|
111
|
+
1.25,
|
|
112
|
+
1.375,
|
|
113
|
+
1.5,
|
|
114
|
+
1.625,
|
|
115
|
+
1.75,
|
|
116
|
+
1.875,
|
|
117
|
+
2,
|
|
118
|
+
2.125,
|
|
119
|
+
2.25,
|
|
120
|
+
2.375,
|
|
121
|
+
2.5,
|
|
122
|
+
2.625,
|
|
123
|
+
2.75,
|
|
124
|
+
2.875,
|
|
125
|
+
3,
|
|
126
|
+
]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('countWords', () => {
|
|
130
|
+
it('should return 1 if label is undefined', () => {
|
|
131
|
+
const label = undefined;
|
|
132
|
+
const result = utils.countWords(label);
|
|
133
|
+
|
|
134
|
+
expect(result).toEqual(1);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should return 1 if label is null', () => {
|
|
138
|
+
const label = null;
|
|
139
|
+
const result = utils.countWords(label);
|
|
140
|
+
|
|
141
|
+
expect(result).toEqual(1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should return 3 if label has 3 words', () => {
|
|
145
|
+
const label = 'Number of months';
|
|
146
|
+
const result = utils.countWords(label);
|
|
147
|
+
|
|
148
|
+
expect(result).toEqual(3);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Arrow snapshot down 1`] = `
|
|
4
|
+
<path
|
|
5
|
+
className="className"
|
|
6
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
7
|
+
transform="translate(0, 15) rotate(270)"
|
|
8
|
+
/>
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
exports[`Arrow snapshot left 1`] = `
|
|
12
|
+
<path
|
|
13
|
+
className="className"
|
|
14
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
15
|
+
transform="translate(-15, 0) rotate(0)"
|
|
16
|
+
/>
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
exports[`Arrow snapshot right 1`] = `
|
|
20
|
+
<path
|
|
21
|
+
className="className"
|
|
22
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
23
|
+
transform="translate(15, 0) rotate(180)"
|
|
24
|
+
/>
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
exports[`Arrow snapshot up 1`] = `
|
|
28
|
+
<path
|
|
29
|
+
className="className"
|
|
30
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
31
|
+
transform="translate(0, -15) rotate(90)"
|
|
32
|
+
/>
|
|
33
|
+
`;
|