@pie-lib/graphing-solution-set 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.
Files changed (151) hide show
  1. package/CHANGELOG.json +1 -0
  2. package/CHANGELOG.md +16 -0
  3. package/LICENSE.md +5 -0
  4. package/NEXT.CHANGELOG.json +1 -0
  5. package/lib/__tests__/graph-with-controls.test.js +191 -0
  6. package/lib/__tests__/graph.test.js +290 -0
  7. package/lib/__tests__/grid.test.js +40 -0
  8. package/lib/__tests__/labels.test.js +59 -0
  9. package/lib/__tests__/mark-label.test.js +154 -0
  10. package/lib/__tests__/toggle-bar.test.js +54 -0
  11. package/lib/__tests__/tool-menu.test.js +43 -0
  12. package/lib/__tests__/undo-redo.test.js +42 -0
  13. package/lib/__tests__/use-debounce.test.js +28 -0
  14. package/lib/__tests__/utils.js +72 -0
  15. package/lib/__tests__/utils.test.js +133 -0
  16. package/lib/axis/__tests__/arrow.test.js +68 -0
  17. package/lib/axis/__tests__/axes.test.js +214 -0
  18. package/lib/axis/arrow.js +115 -0
  19. package/lib/axis/axes.js +415 -0
  20. package/lib/axis/index.js +26 -0
  21. package/lib/bg.js +139 -0
  22. package/lib/container/actions.js +24 -0
  23. package/lib/container/index.js +166 -0
  24. package/lib/container/marks.js +27 -0
  25. package/lib/container/middleware.js +25 -0
  26. package/lib/container/reducer.js +25 -0
  27. package/lib/coordinates-label.js +109 -0
  28. package/lib/graph-with-controls.js +372 -0
  29. package/lib/graph.js +419 -0
  30. package/lib/grid-setup.js +462 -0
  31. package/lib/grid.js +176 -0
  32. package/lib/index.js +51 -0
  33. package/lib/labels.js +299 -0
  34. package/lib/mark-label.js +208 -0
  35. package/lib/toggle-bar.js +336 -0
  36. package/lib/tool-menu.js +325 -0
  37. package/lib/tools/index.js +29 -0
  38. package/lib/tools/line/__tests__/component.test.js +56 -0
  39. package/lib/tools/line/component.js +106 -0
  40. package/lib/tools/line/index.js +16 -0
  41. package/lib/tools/polygon/__tests__/component.test.js +245 -0
  42. package/lib/tools/polygon/__tests__/index.test.js +95 -0
  43. package/lib/tools/polygon/__tests__/line.test.js +43 -0
  44. package/lib/tools/polygon/__tests__/polygon.test.js +73 -0
  45. package/lib/tools/polygon/component.js +457 -0
  46. package/lib/tools/polygon/index.js +106 -0
  47. package/lib/tools/polygon/line.js +151 -0
  48. package/lib/tools/polygon/polygon.js +171 -0
  49. package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
  50. package/lib/tools/shared/arrow-head.js +75 -0
  51. package/lib/tools/shared/line/__tests__/index.test.js +291 -0
  52. package/lib/tools/shared/line/__tests__/line-path.test.js +78 -0
  53. package/lib/tools/shared/line/__tests__/with-root-edge.test.js +122 -0
  54. package/lib/tools/shared/line/index.js +637 -0
  55. package/lib/tools/shared/line/line-path.js +145 -0
  56. package/lib/tools/shared/line/with-root-edge.js +155 -0
  57. package/lib/tools/shared/point/__tests__/arrow-point.test.js +137 -0
  58. package/lib/tools/shared/point/__tests__/base-point.test.js +134 -0
  59. package/lib/tools/shared/point/arrow-point.js +113 -0
  60. package/lib/tools/shared/point/arrow.js +96 -0
  61. package/lib/tools/shared/point/base-point.js +151 -0
  62. package/lib/tools/shared/point/index.js +94 -0
  63. package/lib/tools/shared/styles.js +49 -0
  64. package/lib/tools/shared/types.js +19 -0
  65. package/lib/undo-redo.js +107 -0
  66. package/lib/use-debounce.js +32 -0
  67. package/lib/utils.js +314 -0
  68. package/package.json +50 -0
  69. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +114 -0
  70. package/src/__tests__/__snapshots__/graph.test.jsx.snap +213 -0
  71. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  72. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  73. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +37 -0
  74. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  75. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +35 -0
  76. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +15 -0
  77. package/src/__tests__/graph-with-controls.test.jsx +131 -0
  78. package/src/__tests__/graph.test.jsx +230 -0
  79. package/src/__tests__/grid.test.jsx +20 -0
  80. package/src/__tests__/labels.test.jsx +38 -0
  81. package/src/__tests__/mark-label.test.jsx +68 -0
  82. package/src/__tests__/toggle-bar.test.jsx +36 -0
  83. package/src/__tests__/tool-menu.test.jsx +29 -0
  84. package/src/__tests__/undo-redo.test.jsx +25 -0
  85. package/src/__tests__/use-debounce.test.js +21 -0
  86. package/src/__tests__/utils.js +38 -0
  87. package/src/__tests__/utils.test.js +151 -0
  88. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  89. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  90. package/src/axis/__tests__/arrow.test.jsx +39 -0
  91. package/src/axis/__tests__/axes.test.jsx +220 -0
  92. package/src/axis/arrow.jsx +62 -0
  93. package/src/axis/axes.jsx +307 -0
  94. package/src/axis/index.js +2 -0
  95. package/src/bg.jsx +96 -0
  96. package/src/container/actions.js +8 -0
  97. package/src/container/index.jsx +86 -0
  98. package/src/container/marks.js +14 -0
  99. package/src/container/middleware.js +7 -0
  100. package/src/container/reducer.js +5 -0
  101. package/src/coordinates-label.jsx +73 -0
  102. package/src/graph-with-controls.jsx +263 -0
  103. package/src/graph.jsx +334 -0
  104. package/src/grid-setup.jsx +427 -0
  105. package/src/grid.jsx +135 -0
  106. package/src/index.js +7 -0
  107. package/src/labels.jsx +214 -0
  108. package/src/mark-label.jsx +136 -0
  109. package/src/toggle-bar.jsx +242 -0
  110. package/src/tool-menu.jsx +294 -0
  111. package/src/tools/index.js +8 -0
  112. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  113. package/src/tools/line/__tests__/component.test.jsx +36 -0
  114. package/src/tools/line/component.jsx +77 -0
  115. package/src/tools/line/index.js +4 -0
  116. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +94 -0
  117. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +44 -0
  118. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +53 -0
  119. package/src/tools/polygon/__tests__/component.test.jsx +214 -0
  120. package/src/tools/polygon/__tests__/index.test.js +65 -0
  121. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  122. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  123. package/src/tools/polygon/component.jsx +336 -0
  124. package/src/tools/polygon/index.js +52 -0
  125. package/src/tools/polygon/line.jsx +78 -0
  126. package/src/tools/polygon/polygon.jsx +101 -0
  127. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +32 -0
  128. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  129. package/src/tools/shared/arrow-head.jsx +46 -0
  130. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  131. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +57 -0
  132. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  133. package/src/tools/shared/line/__tests__/index.test.jsx +247 -0
  134. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  135. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  136. package/src/tools/shared/line/index.jsx +473 -0
  137. package/src/tools/shared/line/line-path.jsx +88 -0
  138. package/src/tools/shared/line/with-root-edge.jsx +97 -0
  139. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +55 -0
  140. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +43 -0
  141. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  142. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  143. package/src/tools/shared/point/arrow-point.jsx +60 -0
  144. package/src/tools/shared/point/arrow.jsx +40 -0
  145. package/src/tools/shared/point/base-point.jsx +86 -0
  146. package/src/tools/shared/point/index.jsx +60 -0
  147. package/src/tools/shared/styles.js +20 -0
  148. package/src/tools/shared/types.js +8 -0
  149. package/src/undo-redo.jsx +47 -0
  150. package/src/use-debounce.js +13 -0
  151. package/src/utils.js +234 -0
@@ -0,0 +1,57 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`LinePath snapshot renders 1`] = `
4
+ <RawLinePath
5
+ className="className"
6
+ classes={
7
+ Object {
8
+ "correct": "RawLinePath-correct-5",
9
+ "disabled": "RawLinePath-disabled-4",
10
+ "dragging": "RawLinePath-dragging-3",
11
+ "drawLine": "RawLinePath-drawLine-1",
12
+ "incorrect": "RawLinePath-incorrect-6",
13
+ "line": "RawLinePath-line-2",
14
+ "missing": "RawLinePath-missing-7",
15
+ }
16
+ }
17
+ from={
18
+ Object {
19
+ "x": 0,
20
+ "y": 0,
21
+ }
22
+ }
23
+ graphProps={
24
+ Object {
25
+ "domain": Object {
26
+ "max": 1,
27
+ "min": 0,
28
+ "step": 1,
29
+ },
30
+ "range": Object {
31
+ "max": 1,
32
+ "min": 0,
33
+ "step": 1,
34
+ },
35
+ "scale": Object {
36
+ "x": [MockFunction],
37
+ "y": [MockFunction],
38
+ },
39
+ "size": Object {
40
+ "height": 400,
41
+ "width": 400,
42
+ },
43
+ "snap": Object {
44
+ "x": [MockFunction],
45
+ "y": [MockFunction],
46
+ },
47
+ }
48
+ }
49
+ onChange={[MockFunction]}
50
+ to={
51
+ Object {
52
+ "x": 1,
53
+ "y": 1,
54
+ }
55
+ }
56
+ />
57
+ `;
@@ -0,0 +1,63 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`rootEdgeComponent snapshot renders 1`] = `
4
+ <Component
5
+ graphProps={
6
+ Object {
7
+ "domain": Object {
8
+ "max": 1,
9
+ "min": 0,
10
+ "step": 1,
11
+ },
12
+ "range": Object {
13
+ "max": 1,
14
+ "min": 0,
15
+ "step": 1,
16
+ },
17
+ "scale": Object {
18
+ "x": [MockFunction],
19
+ "y": [MockFunction],
20
+ },
21
+ "size": Object {
22
+ "height": 400,
23
+ "width": 400,
24
+ },
25
+ "snap": Object {
26
+ "x": [MockFunction],
27
+ "y": [MockFunction],
28
+ },
29
+ }
30
+ }
31
+ mark={
32
+ Object {
33
+ "from": Object {
34
+ "x": 0,
35
+ "y": 0,
36
+ },
37
+ "to": Object {
38
+ "x": 1,
39
+ "y": 1,
40
+ },
41
+ }
42
+ }
43
+ onChange={[Function]}
44
+ />
45
+ `;
46
+
47
+ exports[`rootEdgeToToFromWRapper renders 1`] = `
48
+ <Component
49
+ mark={
50
+ Object {
51
+ "from": Object {
52
+ "x": 1,
53
+ "y": 1,
54
+ },
55
+ "to": Object {
56
+ "x": 2,
57
+ "y": 2,
58
+ },
59
+ }
60
+ }
61
+ onChange={[Function]}
62
+ />
63
+ `;
@@ -0,0 +1,247 @@
1
+ import { lineTool, lineToolComponent, lineBase } from '../index';
2
+ import { utils } from '@pie-lib/plot';
3
+ import { shallow } from 'enzyme';
4
+ import React from 'react';
5
+ import { graphProps as getGraphProps } from '../../../../__tests__/utils';
6
+
7
+ const { xy } = utils;
8
+ const xyLabel = (x, y, label) => ({ x, y, label });
9
+
10
+ describe('lineTool', () => {
11
+ describe('addPoint', () => {
12
+ let toolbar;
13
+ beforeEach(() => {
14
+ toolbar = lineTool('lineType', () => <div />)();
15
+ });
16
+ it('returns a building mark', () => {
17
+ const result = toolbar.addPoint(xy(1, 1));
18
+ expect(result).toEqual({
19
+ type: 'lineType',
20
+ building: true,
21
+ from: xy(1, 1),
22
+ });
23
+ });
24
+
25
+ it('returns a complete mark', () => {
26
+ const result = toolbar.addPoint(xy(1, 1), { from: xy(0, 0) });
27
+ expect(result).toEqual({
28
+ building: false,
29
+ from: xy(0, 0),
30
+ to: xy(1, 1),
31
+ });
32
+ });
33
+ });
34
+ });
35
+
36
+ describe('lineToolComponent', () => {
37
+ let Comp;
38
+ let mark;
39
+ let onChange;
40
+ let w;
41
+ const wrapper = (extras) => {
42
+ const defaults = {
43
+ mark,
44
+ onChange: jest.fn(),
45
+ graphProps: getGraphProps(),
46
+ };
47
+ const props = { ...defaults, ...extras };
48
+
49
+ return shallow(<Comp {...props} />);
50
+ };
51
+
52
+ beforeEach(() => {
53
+ Comp = lineToolComponent(() => <text />);
54
+ mark = { from: xy(0, 0), to: xy(1, 1) };
55
+ });
56
+
57
+ describe('snapshot', () => {
58
+ it('renders', () => {
59
+ w = wrapper();
60
+ expect(w).toMatchSnapshot();
61
+ });
62
+ });
63
+ describe('logic', () => {
64
+ describe('startDrag', () => {
65
+ it('sets state', () => {
66
+ w = wrapper();
67
+ w.instance().startDrag();
68
+ expect(w.state('mark')).toEqual(mark);
69
+ });
70
+ });
71
+
72
+ describe('stopDrag/changeMark', () => {
73
+ let update = { from: xy(2, 2), to: xy(4, 4) };
74
+ beforeEach(() => {
75
+ w = wrapper();
76
+ w.instance().changeMark(update);
77
+ w.instance().stopDrag();
78
+ });
79
+ it('calls onChange', () => {
80
+ expect(w.instance().props.onChange).toHaveBeenCalledWith(mark, update);
81
+ });
82
+ });
83
+ });
84
+ });
85
+
86
+ describe('lineBase', () => {
87
+ let Comp;
88
+ let w;
89
+ let onChange = jest.fn();
90
+ let changeMarkProps = jest.fn();
91
+
92
+ beforeEach(() => {
93
+ Comp = lineBase(() => <text />);
94
+ });
95
+
96
+ const wrapper = (extras) => {
97
+ const defaults = {
98
+ onChange,
99
+ changeMarkProps,
100
+ graphProps: getGraphProps(),
101
+ from: xy(0, 0),
102
+ to: xy(1, 1),
103
+ };
104
+ const props = { ...defaults, ...extras };
105
+
106
+ return shallow(<Comp {...props} />);
107
+ };
108
+
109
+ // used to test items that have labels attached to points
110
+ const labelNode = document.createElement('foreignObject');
111
+ const wrapperWithLabels = (extras = {}) =>
112
+ wrapper({
113
+ ...extras,
114
+ labelNode: labelNode,
115
+ from: xyLabel(0, 0, 'A'),
116
+ to: xyLabel(1, 1, 'B'),
117
+ });
118
+
119
+ describe('render', () => {
120
+ it('renders', () => {
121
+ w = wrapper();
122
+ expect(w).toMatchSnapshot();
123
+ });
124
+
125
+ it('renders with labels', () => {
126
+ w = wrapperWithLabels();
127
+ expect(w).toMatchSnapshot();
128
+ });
129
+ });
130
+
131
+ describe('logic', () => {
132
+ const assertCallsOnChange = (fn, args, expected) => {
133
+ it('calls onChange', () => {
134
+ const w = wrapper();
135
+ w.instance()[fn](...args);
136
+ expect(w.instance().props.onChange).toBeCalledWith(expected);
137
+ });
138
+ };
139
+
140
+ const assertCallsOnChangeWithLabels = (fn, args, expected) => {
141
+ it('calls onChange with labels', () => {
142
+ const w = wrapperWithLabels();
143
+ w.instance()[fn](...args);
144
+ expect(w.instance().props.onChange).toBeCalledWith(expected);
145
+ });
146
+ };
147
+
148
+ describe('dragComp', () => {
149
+ const update = { from: xy(2, 2), to: xy(4, 4) };
150
+ assertCallsOnChange('dragComp', [update], update);
151
+ });
152
+
153
+ describe('dragComp keeps labels on both "from" and "to"', () => {
154
+ const update = { from: xy(2, 2), to: xy(4, 4) };
155
+ assertCallsOnChangeWithLabels('dragComp', [update], {
156
+ from: xyLabel(2, 2, 'A'),
157
+ to: xyLabel(4, 4, 'B'),
158
+ });
159
+ });
160
+
161
+ describe('dragFrom', () => {
162
+ assertCallsOnChange('dragFrom', [xy(2, 2)], { from: xy(2, 2), to: xy(1, 1) });
163
+ });
164
+
165
+ describe('dragFrom keeps labels on "from"', () => {
166
+ assertCallsOnChangeWithLabels('dragFrom', [xy(2, 2)], {
167
+ from: xyLabel(2, 2, 'A'),
168
+ to: xyLabel(1, 1, 'B'),
169
+ });
170
+ });
171
+
172
+ describe('dragTo', () => {
173
+ assertCallsOnChange('dragTo', [xy(2, 2)], { from: xy(0, 0), to: xy(2, 2) });
174
+ });
175
+
176
+ describe('dragTo keeps labels on "to"', () => {
177
+ assertCallsOnChangeWithLabels('dragTo', [xy(3, 3)], {
178
+ from: xyLabel(0, 0, 'A'),
179
+ to: xyLabel(3, 3, 'B'),
180
+ });
181
+ });
182
+
183
+ describe('labelChange', () => {
184
+ it('updates "label" property for point', () => {
185
+ w = wrapperWithLabels({ labelModeEnabled: true });
186
+
187
+ w.instance().labelChange(xyLabel(0, 0, 'Label A'), 'from');
188
+ expect(changeMarkProps).toBeCalledWith({
189
+ from: xyLabel(0, 0, 'Label A'),
190
+ });
191
+
192
+ w.instance().labelChange(xyLabel(0, 0, 'Label B'), 'to');
193
+ expect(changeMarkProps).toBeCalledWith({
194
+ to: xyLabel(0, 0, 'Label B'),
195
+ });
196
+ });
197
+
198
+ it('removes "label" property if the field is empty', () => {
199
+ w = wrapperWithLabels();
200
+
201
+ w.instance().labelChange(xyLabel(0, 0, ''), 'from');
202
+ expect(changeMarkProps).toBeCalledWith({
203
+ from: xy(0, 0),
204
+ });
205
+
206
+ w.instance().labelChange(xyLabel(0, 0, ''), 'to');
207
+ expect(changeMarkProps).toBeCalledWith({
208
+ to: xy(0, 0),
209
+ });
210
+ });
211
+ });
212
+
213
+ describe('clickPoint', () => {
214
+ it('adds "label" property to a point', () => {
215
+ w = wrapperWithLabels({ labelModeEnabled: true });
216
+
217
+ w.instance().clickPoint(xy(0, 0), 'from');
218
+ expect(changeMarkProps).toBeCalledWith({
219
+ from: xyLabel(0, 0, ''),
220
+ to: xyLabel(1, 1, 'B'),
221
+ });
222
+
223
+ w.instance().clickPoint(xy(1, 1), 'to');
224
+ expect(changeMarkProps).toBeCalledWith({
225
+ from: xyLabel(0, 0, 'A'),
226
+ to: xyLabel(1, 1, ''),
227
+ });
228
+ });
229
+
230
+ it('if point already has label, keeps that value', () => {
231
+ w = wrapperWithLabels({ labelModeEnabled: true });
232
+
233
+ w.instance().clickPoint(xyLabel(0, 0, 'Label A'), 'from');
234
+ expect(changeMarkProps).toBeCalledWith({
235
+ from: xyLabel(0, 0, 'Label A'),
236
+ to: xyLabel(1, 1, 'B'),
237
+ });
238
+
239
+ w.instance().clickPoint(xyLabel(1, 1, 'Label B'), 'to');
240
+ expect(changeMarkProps).toBeCalledWith({
241
+ from: xyLabel(0, 0, 'A'),
242
+ to: xyLabel(1, 1, 'Label B'),
243
+ });
244
+ });
245
+ });
246
+ });
247
+ });
@@ -0,0 +1,53 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { graphProps as getGraphProps } from '../../../../__tests__/utils';
4
+ import { gridDraggable, utils } from '@pie-lib/plot';
5
+ const { xy } = utils;
6
+
7
+ import * as lineUtils from '../../../../utils';
8
+
9
+ const { bounds, pointsToArea } = lineUtils;
10
+ jest.mock('../../../../utils', () => {
11
+ const a = jest.requireActual('../../../../utils');
12
+ return {
13
+ pointsToArea: jest.fn().mockReturnValue({}),
14
+ bounds: jest.fn().mockReturnValue({}),
15
+ point: a.point,
16
+ };
17
+ });
18
+
19
+ jest.mock('@pie-lib/plot', () => {
20
+ const a = jest.requireActual('@pie-lib/plot');
21
+ return {
22
+ gridDraggable: jest.fn((opts) => jest.fn()),
23
+ types: a.types,
24
+ utils: a.utils,
25
+ };
26
+ });
27
+
28
+ describe('LinePath', () => {
29
+ let LinePath;
30
+ let w;
31
+ let onChange = jest.fn();
32
+ beforeEach(() => {
33
+ LinePath = require('../line-path').LinePath;
34
+ });
35
+ const wrapper = (extras) => {
36
+ const defaults = {
37
+ classes: {},
38
+ className: 'className',
39
+ onChange,
40
+ graphProps: getGraphProps(),
41
+ from: xy(0, 0, 0),
42
+ to: xy(1, 1, 0),
43
+ };
44
+ const props = { ...defaults, ...extras };
45
+ return shallow(<LinePath {...props} />);
46
+ };
47
+ describe('snapshot', () => {
48
+ it('renders', () => {
49
+ const w = wrapper();
50
+ expect(w).toMatchSnapshot();
51
+ });
52
+ });
53
+ });
@@ -0,0 +1,73 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { rootEdgeComponent, withRootEdge, rootEdgeToFromToWrapper } from '../with-root-edge';
4
+ import { graphProps as getGraphProps } from '../../../../__tests__/utils';
5
+ import { utils } from '@pie-lib/plot';
6
+ import { lineToolComponent, LineToolMockComponent } from '../index';
7
+ const { xy } = utils;
8
+ jest.mock('../index', () => {
9
+ const out = {
10
+ lineBase: jest.fn().mockReturnValue(() => <div />),
11
+ lineToolComponent: jest.fn().mockReturnValue(() => <div />),
12
+ };
13
+ return out;
14
+ });
15
+
16
+ describe('rootEdgeToToFromWRapper', () => {
17
+ let Comp;
18
+ let w;
19
+ let onChange = jest.fn();
20
+ beforeEach(() => {
21
+ Comp = rootEdgeToFromToWrapper(() => <div />);
22
+ });
23
+ const wrapper = (extras) => {
24
+ const defaults = {
25
+ mark: { root: xy(1, 1), edge: xy(2, 2) },
26
+ onChange,
27
+ };
28
+ const props = { ...defaults, ...extras };
29
+ return shallow(<Comp {...props} />);
30
+ };
31
+
32
+ it('renders', () => {
33
+ w = wrapper();
34
+ expect(w).toMatchSnapshot();
35
+ });
36
+
37
+ it('has from/to mark', () => {
38
+ w = wrapper();
39
+ expect(w.props().mark).toEqual({ from: xy(1, 1), to: xy(2, 2) });
40
+ });
41
+
42
+ it('calls onChange with root edge ', () => {
43
+ w = wrapper();
44
+ w.props().onChange({ from: xy(1, 1), to: xy(2, 2) }, { from: xy(3, 3), to: xy(4, 4) });
45
+ expect(onChange).toHaveBeenCalledWith({ root: xy(1, 1), edge: xy(2, 2) }, { root: xy(3, 3), edge: xy(4, 4) });
46
+ });
47
+ });
48
+ describe('rootEdgeComponent', () => {
49
+ let w;
50
+ let onChange = jest.fn();
51
+ let Comp;
52
+ let mark;
53
+ beforeEach(() => {
54
+ mark = { root: xy(0, 0), edge: xy(1, 1) };
55
+ Comp = rootEdgeComponent(() => <text />);
56
+ });
57
+ const wrapper = (extras, opts) => {
58
+ const defaults = {
59
+ mark,
60
+ graphProps: getGraphProps(),
61
+ onChange,
62
+ };
63
+
64
+ const props = { ...defaults, ...extras };
65
+ return shallow(<Comp {...props} />, opts);
66
+ };
67
+ describe('snapshot', () => {
68
+ it('renders', () => {
69
+ const w = wrapper();
70
+ expect(w).toMatchSnapshot();
71
+ });
72
+ });
73
+ });