@pie-lib/graphing 2.14.22-next.0 → 2.16.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/graph-with-controls.test.js +215 -0
- package/lib/__tests__/graph.test.js +290 -0
- package/lib/__tests__/grid.test.js +40 -0
- package/lib/__tests__/labels.test.js +59 -0
- package/lib/__tests__/mark-label.test.js +154 -0
- package/lib/__tests__/toggle-bar.test.js +54 -0
- package/lib/__tests__/tool-menu.test.js +43 -0
- package/lib/__tests__/undo-redo.test.js +42 -0
- package/lib/__tests__/use-debounce.test.js +28 -0
- package/lib/__tests__/utils.js +72 -0
- package/lib/__tests__/utils.test.js +133 -0
- package/lib/axis/__tests__/arrow.test.js +68 -0
- package/lib/axis/__tests__/axes.test.js +214 -0
- package/lib/axis/arrow.js +1 -1
- package/lib/axis/axes.js +6 -6
- package/lib/axis/index.js +1 -1
- package/lib/bg.js +1 -1
- package/lib/container/actions.js +1 -1
- package/lib/container/index.js +2 -5
- package/lib/container/marks.js +1 -1
- package/lib/container/middleware.js +1 -1
- package/lib/container/reducer.js +1 -1
- package/lib/coordinates-label.js +6 -4
- package/lib/graph-with-controls.js +9 -16
- package/lib/graph.js +30 -13
- package/lib/grid-setup.js +1 -1
- package/lib/grid.js +7 -15
- package/lib/index.js +9 -1
- package/lib/key-legend.js +246 -0
- package/lib/label-svg-icon.js +56 -0
- package/lib/labels.js +3 -2
- package/lib/mark-label.js +168 -57
- package/lib/toggle-bar.js +4 -5
- package/lib/tool-menu.js +3 -23
- package/lib/tools/absolute/__tests__/component.test.js +74 -0
- package/lib/tools/absolute/component.js +35 -0
- package/lib/tools/absolute/index.js +63 -0
- package/lib/tools/circle/__tests__/bg-circle.test.js +46 -0
- package/lib/tools/circle/__tests__/component.test.js +259 -0
- package/lib/tools/circle/bg-circle.js +5 -4
- package/lib/tools/circle/component.js +35 -16
- package/lib/tools/circle/index.js +1 -1
- package/lib/tools/exponential/__tests__/component.test.js +73 -0
- package/lib/tools/exponential/component.js +34 -0
- package/lib/tools/exponential/index.js +71 -0
- package/lib/tools/index.js +27 -7
- package/lib/tools/line/__tests__/component.test.js +56 -0
- package/lib/tools/line/component.js +3 -2
- package/lib/tools/line/index.js +1 -1
- package/lib/tools/parabola/__tests__/component.test.js +73 -0
- package/lib/tools/parabola/component.js +7 -6
- package/lib/tools/parabola/index.js +1 -1
- package/lib/tools/point/__tests__/component.test.js +97 -0
- package/lib/tools/point/component.js +15 -10
- package/lib/tools/point/index.js +1 -1
- package/lib/tools/polygon/__tests__/component.test.js +255 -0
- package/lib/tools/polygon/__tests__/index.test.js +95 -0
- package/lib/tools/polygon/__tests__/line.test.js +43 -0
- package/lib/tools/polygon/__tests__/polygon.test.js +73 -0
- package/lib/tools/polygon/component.js +26 -13
- package/lib/tools/polygon/index.js +1 -1
- package/lib/tools/polygon/line.js +13 -7
- package/lib/tools/polygon/polygon.js +7 -4
- package/lib/tools/ray/__tests__/component.test.js +48 -0
- package/lib/tools/ray/component.js +3 -2
- package/lib/tools/ray/index.js +1 -1
- package/lib/tools/segment/__tests__/component.test.js +48 -0
- package/lib/tools/segment/component.js +3 -2
- package/lib/tools/segment/index.js +1 -1
- package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
- package/lib/tools/shared/arrow-head.js +1 -1
- package/lib/tools/shared/icons/CorrectSVG.js +36 -0
- package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
- package/lib/tools/shared/icons/MissingSVG.js +35 -0
- package/lib/tools/shared/line/__tests__/index.test.js +301 -0
- package/lib/tools/shared/line/__tests__/line-path.test.js +78 -0
- package/lib/tools/shared/line/__tests__/with-root-edge.test.js +122 -0
- package/lib/tools/shared/line/index.js +52 -20
- package/lib/tools/shared/line/line-path.js +14 -8
- package/lib/tools/shared/line/with-root-edge.js +20 -9
- package/lib/tools/shared/point/__tests__/arrow-point.test.js +137 -0
- package/lib/tools/shared/point/__tests__/base-point.test.js +134 -0
- package/lib/tools/shared/point/arrow-point.js +2 -2
- package/lib/tools/shared/point/arrow.js +2 -2
- package/lib/tools/shared/point/base-point.js +44 -8
- package/lib/tools/shared/point/index.js +5 -2
- package/lib/tools/shared/styles.js +17 -8
- package/lib/tools/shared/types.js +1 -1
- package/lib/tools/sine/__tests__/component.test.js +81 -0
- package/lib/tools/sine/component.js +14 -5
- package/lib/tools/sine/index.js +1 -1
- package/lib/tools/vector/__tests__/component.test.js +45 -0
- package/lib/tools/vector/component.js +3 -2
- package/lib/tools/vector/index.js +1 -1
- package/lib/undo-redo.js +1 -2
- package/lib/use-debounce.js +1 -1
- package/lib/utils.js +2 -2
- package/package.json +7 -7
- 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-setup.jsx +9 -6
- package/src/grid.jsx +8 -10
- package/src/index.js +2 -2
- package/src/key-legend.jsx +115 -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.map +0 -1
- package/lib/axis/axes.js.map +0 -1
- package/lib/axis/index.js.map +0 -1
- package/lib/bg.js.map +0 -1
- package/lib/container/actions.js.map +0 -1
- package/lib/container/index.js.map +0 -1
- package/lib/container/marks.js.map +0 -1
- package/lib/container/middleware.js.map +0 -1
- package/lib/container/reducer.js.map +0 -1
- package/lib/coordinates-label.js.map +0 -1
- package/lib/graph-with-controls.js.map +0 -1
- package/lib/graph.js.map +0 -1
- package/lib/grid-setup.js.map +0 -1
- package/lib/grid.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/labels.js.map +0 -1
- package/lib/mark-label.js.map +0 -1
- package/lib/toggle-bar.js.map +0 -1
- package/lib/tool-menu.js.map +0 -1
- package/lib/tools/circle/bg-circle.js.map +0 -1
- package/lib/tools/circle/component.js.map +0 -1
- package/lib/tools/circle/index.js.map +0 -1
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/line/component.js.map +0 -1
- package/lib/tools/line/index.js.map +0 -1
- package/lib/tools/parabola/component.js.map +0 -1
- package/lib/tools/parabola/index.js.map +0 -1
- package/lib/tools/point/component.js.map +0 -1
- package/lib/tools/point/index.js.map +0 -1
- package/lib/tools/polygon/component.js.map +0 -1
- package/lib/tools/polygon/index.js.map +0 -1
- package/lib/tools/polygon/line.js.map +0 -1
- package/lib/tools/polygon/polygon.js.map +0 -1
- package/lib/tools/ray/component.js.map +0 -1
- package/lib/tools/ray/index.js.map +0 -1
- package/lib/tools/segment/component.js.map +0 -1
- package/lib/tools/segment/index.js.map +0 -1
- package/lib/tools/shared/arrow-head.js.map +0 -1
- package/lib/tools/shared/line/index.js.map +0 -1
- package/lib/tools/shared/line/line-path.js.map +0 -1
- package/lib/tools/shared/line/with-root-edge.js.map +0 -1
- package/lib/tools/shared/point/arrow-point.js.map +0 -1
- package/lib/tools/shared/point/arrow.js.map +0 -1
- package/lib/tools/shared/point/base-point.js.map +0 -1
- package/lib/tools/shared/point/index.js.map +0 -1
- package/lib/tools/shared/styles.js.map +0 -1
- package/lib/tools/shared/types.js.map +0 -1
- package/lib/tools/sine/component.js.map +0 -1
- package/lib/tools/sine/index.js.map +0 -1
- package/lib/tools/vector/component.js.map +0 -1
- package/lib/tools/vector/index.js.map +0 -1
- package/lib/undo-redo.js.map +0 -1
- package/lib/use-debounce.js.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { graphProps, xy } from '../../../__tests__/utils';
|
|
4
|
+
|
|
5
|
+
import { RawBaseComponent, buildLines, swap } from '../component';
|
|
6
|
+
|
|
7
|
+
const xyLabel = (x, y, index, label) => ({
|
|
8
|
+
...xy(x, y, index),
|
|
9
|
+
label,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('buildLines', () => {
|
|
13
|
+
const defaultPoints = [xy(0, 0), xy(1, 1), xy(1, 0)];
|
|
14
|
+
|
|
15
|
+
const assertBuildLines = (points, closed, expected) => {
|
|
16
|
+
it(`builds points and lines for ${points} = ${expected}`, () => {
|
|
17
|
+
const result = buildLines(points);
|
|
18
|
+
expect(result).toMatchObject([
|
|
19
|
+
{ from: xy(0, 0, 0), to: xy(1, 1, 1) },
|
|
20
|
+
{ from: xy(1, 1, 1), to: xy(1, 0, 2) },
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
assertBuildLines(defaultPoints, true, []);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('swap', () => {
|
|
29
|
+
it('swaps pairs', () => {
|
|
30
|
+
const result = swap([xy(0, 0, 0), xy(1, 1, 1), xy(2, 2, 2)], xy(0, 0, 0), xy(3, 3, 0));
|
|
31
|
+
expect(result).toEqual([xy(3, 3, 0), xy(1, 1, 1), xy(2, 2, 2)]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('RawBaseComponent', () => {
|
|
36
|
+
let w;
|
|
37
|
+
let onChange = jest.fn();
|
|
38
|
+
let onChangeProps = jest.fn();
|
|
39
|
+
const wrapper = (extras) => {
|
|
40
|
+
const defaults = {
|
|
41
|
+
classes: {},
|
|
42
|
+
className: 'className',
|
|
43
|
+
onChange,
|
|
44
|
+
onChangeProps,
|
|
45
|
+
onClosePolygon: jest.fn(),
|
|
46
|
+
graphProps: graphProps(),
|
|
47
|
+
points: [],
|
|
48
|
+
};
|
|
49
|
+
const props = { ...defaults, ...extras };
|
|
50
|
+
|
|
51
|
+
return shallow(<RawBaseComponent {...props} />);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// used to test items that have labels attached to points
|
|
55
|
+
const labelNode = document.createElement('foreignObject');
|
|
56
|
+
const points = [xyLabel(0, 0, 0, 'A'), xyLabel(2, 2, 1, 'B'), xyLabel(0, 2, 2, 'C')];
|
|
57
|
+
const wrapperWithLabels = (extras) =>
|
|
58
|
+
wrapper({
|
|
59
|
+
labelNode: labelNode,
|
|
60
|
+
points: points,
|
|
61
|
+
...extras,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('snapshot', () => {
|
|
65
|
+
it('renders', () => {
|
|
66
|
+
w = wrapper();
|
|
67
|
+
expect(w).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('renders with labels', () => {
|
|
71
|
+
w = wrapperWithLabels();
|
|
72
|
+
expect(w).toMatchSnapshot();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('logic', () => {
|
|
77
|
+
describe('dragPoint', () => {
|
|
78
|
+
it('calls onChange', () => {
|
|
79
|
+
onChange = jest.fn();
|
|
80
|
+
w = wrapper({ points: [xy(1, 1)], onChange });
|
|
81
|
+
w.instance().dragPoint(0, xy(1, 1), xy(2, 2));
|
|
82
|
+
expect(onChange).toHaveBeenCalledWith([xy(2, 2)]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('calls onChange keeping label property from point', () => {
|
|
86
|
+
onChange = jest.fn();
|
|
87
|
+
w = wrapperWithLabels(onChange);
|
|
88
|
+
|
|
89
|
+
w.instance().dragPoint(0, xy(0, 0), xy(0, 1));
|
|
90
|
+
expect(onChange).toHaveBeenCalledWith([{ x: 0, y: 1, label: 'A' }, points[1], points[2]]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('dragLine', () => {
|
|
95
|
+
it('calls onChange', () => {
|
|
96
|
+
w = wrapper({ points: [xy(1, 1, 0), xy(2, 2, 1)], onChange });
|
|
97
|
+
w.instance().dragLine({ from: xy(1, 1, 0), to: xy(2, 2, 1) }, { from: xy(2, 2, 0), to: xy(4, 4, 1) });
|
|
98
|
+
expect(onChange).toHaveBeenCalledWith([xy(2, 2, 0), xy(4, 4, 1)]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('calls onChange keeping label property from both points', () => {
|
|
102
|
+
onChange = jest.fn();
|
|
103
|
+
w = wrapperWithLabels(onChange);
|
|
104
|
+
|
|
105
|
+
w.instance().dragLine(
|
|
106
|
+
{ from: points[0], to: points[1] },
|
|
107
|
+
{
|
|
108
|
+
from: xy(0, 1, 0),
|
|
109
|
+
to: xy(2, 3, 1),
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
expect(onChange).toHaveBeenCalledWith([xyLabel(0, 1, 0, 'A'), xyLabel(2, 3, 1, 'B'), points[2]]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('dragPoly', () => {
|
|
117
|
+
it('calls onChange', () => {
|
|
118
|
+
w = wrapper({ onChange });
|
|
119
|
+
const existing = [xy(1, 1)];
|
|
120
|
+
const next = [xy(2, 2)];
|
|
121
|
+
w.instance().dragPoly(existing, next);
|
|
122
|
+
expect(onChange).toHaveBeenCalledWith([xy(2, 2)]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('calls onChange keeping label property from all points', () => {
|
|
126
|
+
onChange = jest.fn();
|
|
127
|
+
w = wrapperWithLabels(onChange);
|
|
128
|
+
|
|
129
|
+
w.instance().dragPoly(points, [xy(0, 1, 0), xy(2, 3, 1), xy(0, 3, 2)]);
|
|
130
|
+
expect(onChange).toHaveBeenCalledWith([xyLabel(0, 1, 0, 'A'), xyLabel(2, 3, 1, 'B'), xyLabel(0, 3, 2, 'C')]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('labelChange', () => {
|
|
135
|
+
it('updates "label" property for point', () => {
|
|
136
|
+
w = wrapperWithLabels();
|
|
137
|
+
|
|
138
|
+
w.instance().labelChange({ ...points[0], label: 'Label A' }, 0);
|
|
139
|
+
expect(onChangeProps).toBeCalledWith([{ ...points[0], label: 'Label A' }, points[1], points[2]]);
|
|
140
|
+
|
|
141
|
+
w.instance().labelChange({ ...points[1], label: 'Label B' }, 1);
|
|
142
|
+
expect(onChangeProps).toBeCalledWith([points[0], { ...points[1], label: 'Label B' }, points[2]]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('removes "label" property if the field is empty', () => {
|
|
146
|
+
w = wrapperWithLabels();
|
|
147
|
+
|
|
148
|
+
w.instance().labelChange({ ...points[0], label: '' }, 0);
|
|
149
|
+
expect(onChangeProps).toBeCalledWith([xy(0, 0, 0), points[1], points[2]]);
|
|
150
|
+
|
|
151
|
+
w.instance().labelChange({ ...points[1], label: '' }, 1);
|
|
152
|
+
expect(onChangeProps).toBeCalledWith([points[0], xy(2, 2, 1), points[2]]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('close', () => {
|
|
158
|
+
it('calls onClosePolygon', () => {
|
|
159
|
+
const onClosePolygon = jest.fn();
|
|
160
|
+
w = wrapper({ onClosePolygon, points: [xy(1, 1), xy(2, 2), xy(3, 3)] });
|
|
161
|
+
w.instance().close();
|
|
162
|
+
expect(onClosePolygon).toHaveBeenCalled();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('clickPoint', () => {
|
|
167
|
+
let onClick = jest.fn();
|
|
168
|
+
let onClosePolygon = jest.fn();
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
onClosePolygon.mockClear();
|
|
171
|
+
onClick.mockClear();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const assertCallback = (isToolActive, closed, index, mock) => {
|
|
175
|
+
it('calls onClosePolygon', () => {
|
|
176
|
+
const w = wrapper({
|
|
177
|
+
points: [xy(1, 1), xy(2, 2), xy(3, 3)],
|
|
178
|
+
onClosePolygon,
|
|
179
|
+
onClick,
|
|
180
|
+
isToolActive,
|
|
181
|
+
closed,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
w.instance().clickPoint(xy(1, 1, 0), index, {});
|
|
185
|
+
expect(mock).toHaveBeenCalled();
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
assertCallback(true, false, 0, onClosePolygon);
|
|
190
|
+
assertCallback(true, false, 1, onClick);
|
|
191
|
+
assertCallback(false, false, 0, onClick);
|
|
192
|
+
assertCallback(true, true, 0, onClick);
|
|
193
|
+
|
|
194
|
+
it('adds "label" property to a point', () => {
|
|
195
|
+
const onChangeProps = jest.fn();
|
|
196
|
+
const w = wrapperWithLabels({
|
|
197
|
+
labelModeEnabled: true,
|
|
198
|
+
onChangeProps,
|
|
199
|
+
points: [xy(0, 0, 0), xy(2, 2, 1), xy(0, 2, 2)],
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
w.instance().clickPoint(xy(0, 0, 0), 0, {});
|
|
203
|
+
expect(onChangeProps).toHaveBeenCalledWith([xyLabel(0, 0, 0, ''), xy(2, 2, 1), xy(0, 2, 2)]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('adds "label" property to a point when limit labeling', () => {
|
|
207
|
+
const onChangeProps = jest.fn();
|
|
208
|
+
const w = wrapperWithLabels({
|
|
209
|
+
labelModeEnabled: true,
|
|
210
|
+
onChangeProps,
|
|
211
|
+
limitLabeling: true,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
w.instance().clickPoint(xy(0, 0, 0), 0, {});
|
|
215
|
+
expect(onChangeProps).toHaveBeenCalledTimes(0);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('if point already has label, keeps that value', () => {
|
|
219
|
+
const onChangeProps = jest.fn();
|
|
220
|
+
const w = wrapperWithLabels({ labelModeEnabled: true, onChangeProps });
|
|
221
|
+
|
|
222
|
+
w.instance().clickPoint(points[0], 0, {});
|
|
223
|
+
expect(onChangeProps).toHaveBeenCalledWith(points);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { addPointToArray, tool } from '../index';
|
|
2
|
+
|
|
3
|
+
const xy = (x, y) => ({ x, y });
|
|
4
|
+
|
|
5
|
+
describe('polygon', () => {
|
|
6
|
+
describe('addPointToArray', () => {
|
|
7
|
+
const assertAddPoint = (point, arr, expected) => {
|
|
8
|
+
it(`returns ${expected} when adding ${point} to ${arr}`, () => {
|
|
9
|
+
const result = addPointToArray(point, arr);
|
|
10
|
+
expect(result).toEqual(expected);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
assertAddPoint(xy(0, 0), [], { closed: false, points: [xy(0, 0)] });
|
|
14
|
+
assertAddPoint(xy(0, 0), [xy(0, 0)], { closed: false, points: [xy(0, 0)] });
|
|
15
|
+
assertAddPoint(xy(1, 1), [xy(0, 0)], {
|
|
16
|
+
closed: false,
|
|
17
|
+
points: [xy(0, 0), xy(1, 1)],
|
|
18
|
+
});
|
|
19
|
+
assertAddPoint(xy(1, 1), [xy(0, 0)], {
|
|
20
|
+
closed: false,
|
|
21
|
+
points: [xy(0, 0), xy(1, 1)],
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('tool', () => {
|
|
27
|
+
let t;
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
t = tool();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('creates polygon type', () => {
|
|
33
|
+
expect(t.type).toEqual('polygon');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('complete', () => {
|
|
37
|
+
it('closes polygon', () => {
|
|
38
|
+
expect(t.complete()).toEqual({ building: false, closed: true });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('addPoint', () => {
|
|
43
|
+
it('creates new point', () => {
|
|
44
|
+
const mark = t.addPoint({ x: 0, y: 0 });
|
|
45
|
+
expect(mark).toEqual({
|
|
46
|
+
type: 'polygon',
|
|
47
|
+
points: [{ x: 0, y: 0 }],
|
|
48
|
+
closed: false,
|
|
49
|
+
building: true,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('adds the point', () => {
|
|
54
|
+
const mark = t.addPoint({ x: 0, y: 0 }, { points: [{ x: 1, y: 1 }] });
|
|
55
|
+
expect(mark).toEqual({
|
|
56
|
+
building: true,
|
|
57
|
+
closed: false,
|
|
58
|
+
points: [
|
|
59
|
+
{ x: 1, y: 1 },
|
|
60
|
+
{ x: 0, y: 0 },
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Line } from '../line';
|
|
4
|
+
import { graphProps } from '../../../__tests__/utils';
|
|
5
|
+
|
|
6
|
+
describe('Line', () => {
|
|
7
|
+
let w;
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const wrapper = (extras) => {
|
|
10
|
+
const defaults = {
|
|
11
|
+
classes: {},
|
|
12
|
+
className: 'className',
|
|
13
|
+
graphProps: graphProps(),
|
|
14
|
+
};
|
|
15
|
+
const props = { ...defaults, ...extras };
|
|
16
|
+
return shallow(<Line {...props} />);
|
|
17
|
+
};
|
|
18
|
+
describe('snapshot', () => {
|
|
19
|
+
it('renders', () => {
|
|
20
|
+
w = wrapper();
|
|
21
|
+
expect(w).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('logic', () => {});
|
|
25
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Polygon, getPointString } from '../polygon';
|
|
4
|
+
import { graphProps } from '../../../__tests__/utils';
|
|
5
|
+
|
|
6
|
+
const xy = (x, y) => ({ x, y });
|
|
7
|
+
|
|
8
|
+
describe('Polygon', () => {
|
|
9
|
+
let w;
|
|
10
|
+
const wrapper = (extras) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
classes: {},
|
|
13
|
+
className: 'className',
|
|
14
|
+
graphProps: graphProps(),
|
|
15
|
+
closed: false,
|
|
16
|
+
};
|
|
17
|
+
const props = { ...defaults, ...extras };
|
|
18
|
+
return shallow(<Polygon {...props} />);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe('snapshot', () => {
|
|
22
|
+
it('renders', () => {
|
|
23
|
+
w = wrapper({ points: [{ x: 1, y: 1 }] });
|
|
24
|
+
expect(w).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('getPointString', () => {
|
|
30
|
+
const assertString = (arr, expected) => {
|
|
31
|
+
it('creates: ', () => {
|
|
32
|
+
const result = getPointString(arr, {
|
|
33
|
+
x: jest.fn((n) => n),
|
|
34
|
+
y: jest.fn((n) => n),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result).toEqual(expected);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
assertString([xy(1, 1)], '1,1');
|
|
42
|
+
assertString([xy(1, 1), xy(2, 1)], '1,1 2,1');
|
|
43
|
+
assertString([xy(1, 1), xy(2, 1), xy(4, 4)], '1,1 2,1 4,4');
|
|
44
|
+
});
|
|
@@ -5,11 +5,10 @@ import { ToolPropTypeFields } from '../shared/types';
|
|
|
5
5
|
import { BasePoint } from '../shared/point';
|
|
6
6
|
import chunk from 'lodash/chunk';
|
|
7
7
|
import initial from 'lodash/initial';
|
|
8
|
-
import isEqual from 'lodash/isEqual';
|
|
9
8
|
import debug from 'debug';
|
|
10
9
|
import Line from './line';
|
|
11
10
|
import DraggablePolygon, { Polygon } from './polygon';
|
|
12
|
-
import { types
|
|
11
|
+
import { types } from '@pie-lib/plot';
|
|
13
12
|
import invariant from 'invariant';
|
|
14
13
|
import ReactDOM from 'react-dom';
|
|
15
14
|
import MarkLabel from '../../mark-label';
|
|
@@ -84,6 +83,7 @@ export class RawBaseComponent extends React.Component {
|
|
|
84
83
|
middle: PropTypes.object,
|
|
85
84
|
labelNode: PropTypes.object,
|
|
86
85
|
labelModeEnabled: PropTypes.bool,
|
|
86
|
+
limitLabeling: PropTypes.bool,
|
|
87
87
|
onChangeLabelProps: PropTypes.func,
|
|
88
88
|
onChangeProps: PropTypes.func,
|
|
89
89
|
};
|
|
@@ -165,9 +165,24 @@ export class RawBaseComponent extends React.Component {
|
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
clickPoint = (point, index, data) => {
|
|
168
|
-
const {
|
|
168
|
+
const {
|
|
169
|
+
closed,
|
|
170
|
+
disabled,
|
|
171
|
+
onClick,
|
|
172
|
+
isToolActive,
|
|
173
|
+
labelModeEnabled,
|
|
174
|
+
limitLabeling,
|
|
175
|
+
onChangeProps,
|
|
176
|
+
onChangeLabelProps,
|
|
177
|
+
points,
|
|
178
|
+
} = this.props;
|
|
169
179
|
|
|
170
180
|
if (labelModeEnabled) {
|
|
181
|
+
// limit labeling the points of the polygon
|
|
182
|
+
if (disabled || limitLabeling) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
171
186
|
if (points && index === points.length) {
|
|
172
187
|
const { a, b } = getRightestPoints(points);
|
|
173
188
|
const middle = { label: '', ...point, ...getMiddleOfTwoPoints(a, b) };
|
|
@@ -183,13 +198,16 @@ export class RawBaseComponent extends React.Component {
|
|
|
183
198
|
if (this.input[index]) {
|
|
184
199
|
this.input[index].focus();
|
|
185
200
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
201
|
+
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (isToolActive && !closed && index === 0) {
|
|
206
|
+
this.close();
|
|
207
|
+
return;
|
|
192
208
|
}
|
|
209
|
+
|
|
210
|
+
onClick(point || data);
|
|
193
211
|
};
|
|
194
212
|
|
|
195
213
|
// IMPORTANT, do not remove
|
|
@@ -264,8 +282,8 @@ export class RawBaseComponent extends React.Component {
|
|
|
264
282
|
x={p.x}
|
|
265
283
|
y={p.y}
|
|
266
284
|
onDrag={this.dragPoint.bind(this, index, p)}
|
|
267
|
-
onClick={this.clickPoint.bind(this, p, index)}
|
|
268
285
|
{...common}
|
|
286
|
+
onClick={this.clickPoint.bind(this, p, index)}
|
|
269
287
|
/>,
|
|
270
288
|
labelNode && p.hasOwnProperty('label')
|
|
271
289
|
? ReactDOM.createPortal(
|
|
@@ -349,7 +367,16 @@ export default class Component extends React.Component {
|
|
|
349
367
|
};
|
|
350
368
|
|
|
351
369
|
render() {
|
|
352
|
-
const {
|
|
370
|
+
const {
|
|
371
|
+
coordinatesOnHover,
|
|
372
|
+
mark,
|
|
373
|
+
graphProps,
|
|
374
|
+
onClick,
|
|
375
|
+
isToolActive,
|
|
376
|
+
labelNode,
|
|
377
|
+
labelModeEnabled,
|
|
378
|
+
limitLabeling,
|
|
379
|
+
} = this.props;
|
|
353
380
|
const { mark: stateMark } = this.state;
|
|
354
381
|
|
|
355
382
|
return (
|
|
@@ -367,6 +394,7 @@ export default class Component extends React.Component {
|
|
|
367
394
|
isToolActive={isToolActive}
|
|
368
395
|
labelNode={labelNode}
|
|
369
396
|
labelModeEnabled={labelModeEnabled}
|
|
397
|
+
limitLabeling={limitLabeling}
|
|
370
398
|
/>
|
|
371
399
|
);
|
|
372
400
|
}
|
|
@@ -5,7 +5,7 @@ import { types, gridDraggable } from '@pie-lib/plot';
|
|
|
5
5
|
import { color } from '@pie-lib/render-ui';
|
|
6
6
|
import * as utils from '../../utils';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
|
-
import { correct, disabled, incorrect, missing } from '../shared/styles';
|
|
8
|
+
import { correct, disabled, disabledSecondary, incorrect, missing } from '../shared/styles';
|
|
9
9
|
|
|
10
10
|
class RawLine extends React.Component {
|
|
11
11
|
static propTypes = {
|
|
@@ -32,7 +32,7 @@ class RawLine extends React.Component {
|
|
|
32
32
|
y1={scale.y(from.y)}
|
|
33
33
|
x2={scale.x(to.x)}
|
|
34
34
|
y2={scale.y(to.y)}
|
|
35
|
-
className={classNames(classes.line, disabled && classes.
|
|
35
|
+
className={classNames(classes.line, disabled && classes.disabledSecondary, className, classes[correctness])}
|
|
36
36
|
{...rest}
|
|
37
37
|
/>
|
|
38
38
|
);
|
|
@@ -41,21 +41,29 @@ class RawLine extends React.Component {
|
|
|
41
41
|
|
|
42
42
|
export const Line = withStyles(() => ({
|
|
43
43
|
line: {
|
|
44
|
-
strokeWidth:
|
|
44
|
+
strokeWidth: 3,
|
|
45
45
|
transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
|
|
46
46
|
stroke: 'transparent',
|
|
47
47
|
'&:hover': {
|
|
48
|
-
strokeWidth:
|
|
49
|
-
stroke: color.
|
|
48
|
+
strokeWidth: 4,
|
|
49
|
+
stroke: color.defaults.BLACK,
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
52
|
disabled: {
|
|
53
53
|
...disabled('stroke'),
|
|
54
54
|
strokeWidth: 2,
|
|
55
55
|
},
|
|
56
|
-
|
|
56
|
+
disabledSecondary: {
|
|
57
|
+
...disabledSecondary('stroke'),
|
|
58
|
+
strokeWidth: 2,
|
|
59
|
+
},
|
|
60
|
+
correct: correct('stroke'),
|
|
57
61
|
incorrect: incorrect('stroke'),
|
|
58
|
-
missing:
|
|
62
|
+
missing: {
|
|
63
|
+
...missing('stroke'),
|
|
64
|
+
strokeWidth: 1,
|
|
65
|
+
strokeDasharray: '4 3',
|
|
66
|
+
},
|
|
59
67
|
}))(RawLine);
|
|
60
68
|
|
|
61
69
|
export default gridDraggable({
|
|
@@ -6,7 +6,7 @@ import * as utils from '../../utils';
|
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import { color } from '@pie-lib/render-ui';
|
|
8
8
|
import { fade } from '@material-ui/core/styles/colorManipulator';
|
|
9
|
-
import { correct, disabled, incorrect } from '../shared/styles';
|
|
9
|
+
import { correct, disabled, incorrect, missing } from '../shared/styles';
|
|
10
10
|
|
|
11
11
|
export const getPointString = (points, scale) => {
|
|
12
12
|
return (points || [])
|
|
@@ -61,12 +61,12 @@ export const Polygon = withStyles((theme) => ({
|
|
|
61
61
|
closed: {
|
|
62
62
|
fill: fade(theme.palette.primary.light, 0.2), // TODO hardcoded color
|
|
63
63
|
strokeWidth: 2,
|
|
64
|
-
stroke: color.
|
|
64
|
+
stroke: color.defaults.BLACK,
|
|
65
65
|
},
|
|
66
66
|
open: {
|
|
67
67
|
fill: fade(theme.palette.primary.light, 0.0), // TODO hardcoded color
|
|
68
68
|
strokeWidth: 2,
|
|
69
|
-
stroke: color.
|
|
69
|
+
stroke: color.defaults.BLACK,
|
|
70
70
|
pointerEvents: 'none',
|
|
71
71
|
},
|
|
72
72
|
disabled: {
|
|
@@ -78,6 +78,10 @@ export const Polygon = withStyles((theme) => ({
|
|
|
78
78
|
incorrect: {
|
|
79
79
|
...incorrect('stroke'),
|
|
80
80
|
},
|
|
81
|
+
missing: {
|
|
82
|
+
...missing('stroke'),
|
|
83
|
+
stroke: 'inherit'
|
|
84
|
+
}
|
|
81
85
|
}))(RawPolygon);
|
|
82
86
|
|
|
83
87
|
export default gridDraggable({
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`RayLine snapshot renders 1`] = `
|
|
4
|
+
<g>
|
|
5
|
+
<defs>
|
|
6
|
+
<ArrowMarker
|
|
7
|
+
className=""
|
|
8
|
+
id="1-enabled"
|
|
9
|
+
size={5}
|
|
10
|
+
/>
|
|
11
|
+
</defs>
|
|
12
|
+
<line
|
|
13
|
+
className="className"
|
|
14
|
+
markerEnd="url(#1-enabled)"
|
|
15
|
+
markerId="1"
|
|
16
|
+
onChange={[MockFunction]}
|
|
17
|
+
x1={0}
|
|
18
|
+
x2={1.0375}
|
|
19
|
+
y1={0}
|
|
20
|
+
y2={1.0375}
|
|
21
|
+
/>
|
|
22
|
+
</g>
|
|
23
|
+
`;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RayLine } from '../component';
|
|
4
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
|
+
import { utils } from '@pie-lib/plot';
|
|
6
|
+
describe('RayLine', () => {
|
|
7
|
+
let w;
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const wrapper = (extras) => {
|
|
10
|
+
const defaults = {
|
|
11
|
+
classes: {},
|
|
12
|
+
className: 'className',
|
|
13
|
+
onChange,
|
|
14
|
+
markerId: '1',
|
|
15
|
+
graphProps: getGraphProps(),
|
|
16
|
+
from: utils.xy(0, 0),
|
|
17
|
+
to: utils.xy(1, 1),
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return shallow(<RayLine {...props} />);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('snapshot', () => {
|
|
24
|
+
it('renders', () => {
|
|
25
|
+
const w = wrapper();
|
|
26
|
+
expect(w).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -12,6 +12,7 @@ const rayStyles = (theme) => ({
|
|
|
12
12
|
enabledArrow: styles.arrow(theme),
|
|
13
13
|
disabledArrow: styles.disabledArrow(theme),
|
|
14
14
|
disabled: styles.disabled(theme),
|
|
15
|
+
disabledSecondary: styles.disabledSecondary(theme),
|
|
15
16
|
correct: styles.correct(theme, 'stroke'),
|
|
16
17
|
correctArrow: styles.correct(theme),
|
|
17
18
|
incorrect: styles.incorrect(theme, 'stroke'),
|
|
@@ -43,7 +44,7 @@ export const RayLine = (props) => {
|
|
|
43
44
|
x2={scale.x(aToB.x)}
|
|
44
45
|
y2={scale.y(aToB.y)}
|
|
45
46
|
{...rest}
|
|
46
|
-
className={classNames(classes.line, disabled && classes.
|
|
47
|
+
className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
|
|
47
48
|
markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
|
|
48
49
|
/>
|
|
49
50
|
</g>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Line } from '../component';
|
|
4
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
|
+
import { utils } from '@pie-lib/plot';
|
|
6
|
+
const { xy } = utils;
|
|
7
|
+
describe('Line', () => {
|
|
8
|
+
let w;
|
|
9
|
+
let onChange = jest.fn();
|
|
10
|
+
const wrapper = (extras) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
classes: {},
|
|
13
|
+
className: 'className',
|
|
14
|
+
onChange,
|
|
15
|
+
graphProps: getGraphProps(),
|
|
16
|
+
from: xy(0, 0),
|
|
17
|
+
to: xy(1, 1),
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return shallow(<Line {...props} />);
|
|
21
|
+
};
|
|
22
|
+
describe('snapshot', () => {
|
|
23
|
+
it('renders', () => {
|
|
24
|
+
const w = wrapper();
|
|
25
|
+
expect(w).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -9,6 +9,7 @@ import classNames from 'classnames';
|
|
|
9
9
|
const lineStyles = (theme) => ({
|
|
10
10
|
line: styles.line(theme),
|
|
11
11
|
disabled: styles.disabled(theme),
|
|
12
|
+
disabledSecondary: styles.disabledSecondary(theme),
|
|
12
13
|
correct: styles.correct(theme, 'stroke'),
|
|
13
14
|
incorrect: styles.incorrect(theme, 'stroke'),
|
|
14
15
|
missing: styles.missing(theme, 'stroke'),
|
|
@@ -25,7 +26,7 @@ export const Line = (props) => {
|
|
|
25
26
|
y1={scale.y(from.y)}
|
|
26
27
|
x2={scale.x(to.x)}
|
|
27
28
|
y2={scale.y(to.y)}
|
|
28
|
-
className={classNames(classes.line, disabled && classes.
|
|
29
|
+
className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
|
|
29
30
|
{...rest}
|
|
30
31
|
/>
|
|
31
32
|
);
|