@pie-lib/graphing-solution-set 2.34.3-next.2 → 2.34.3-next.203

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 (145) hide show
  1. package/CHANGELOG.md +15 -67
  2. package/lib/axis/arrow.js +19 -55
  3. package/lib/axis/arrow.js.map +1 -1
  4. package/lib/axis/axes.js +103 -193
  5. package/lib/axis/axes.js.map +1 -1
  6. package/lib/axis/index.js +1 -6
  7. package/lib/axis/index.js.map +1 -1
  8. package/lib/bg.js +21 -49
  9. package/lib/bg.js.map +1 -1
  10. package/lib/container/actions.js +2 -8
  11. package/lib/container/actions.js.map +1 -1
  12. package/lib/container/index.js +14 -60
  13. package/lib/container/index.js.map +1 -1
  14. package/lib/container/marks.js +1 -6
  15. package/lib/container/marks.js.map +1 -1
  16. package/lib/container/middleware.js +2 -8
  17. package/lib/container/middleware.js.map +1 -1
  18. package/lib/container/reducer.js +1 -8
  19. package/lib/container/reducer.js.map +1 -1
  20. package/lib/coordinates-label.js +23 -55
  21. package/lib/coordinates-label.js.map +1 -1
  22. package/lib/graph-with-controls.js +129 -203
  23. package/lib/graph-with-controls.js.map +1 -1
  24. package/lib/graph.js +61 -126
  25. package/lib/graph.js.map +1 -1
  26. package/lib/grid-setup.js +169 -225
  27. package/lib/grid-setup.js.map +1 -1
  28. package/lib/grid.js +29 -74
  29. package/lib/grid.js.map +1 -1
  30. package/lib/index.js +1 -12
  31. package/lib/index.js.map +1 -1
  32. package/lib/labels.js +85 -185
  33. package/lib/labels.js.map +1 -1
  34. package/lib/mark-label.js +39 -88
  35. package/lib/mark-label.js.map +1 -1
  36. package/lib/toggle-bar.js +155 -243
  37. package/lib/toggle-bar.js.map +1 -1
  38. package/lib/tool-menu.js +93 -200
  39. package/lib/tool-menu.js.map +1 -1
  40. package/lib/tools/index.js +2 -7
  41. package/lib/tools/index.js.map +1 -1
  42. package/lib/tools/line/component.js +48 -62
  43. package/lib/tools/line/component.js.map +1 -1
  44. package/lib/tools/line/index.js +1 -6
  45. package/lib/tools/line/index.js.map +1 -1
  46. package/lib/tools/polygon/component.js +76 -173
  47. package/lib/tools/polygon/component.js.map +1 -1
  48. package/lib/tools/polygon/index.js +6 -23
  49. package/lib/tools/polygon/index.js.map +1 -1
  50. package/lib/tools/polygon/line.js +48 -85
  51. package/lib/tools/polygon/line.js.map +1 -1
  52. package/lib/tools/polygon/polygon.js +62 -102
  53. package/lib/tools/polygon/polygon.js.map +1 -1
  54. package/lib/tools/shared/arrow-head.js +7 -20
  55. package/lib/tools/shared/arrow-head.js.map +1 -1
  56. package/lib/tools/shared/line/index.js +89 -185
  57. package/lib/tools/shared/line/index.js.map +1 -1
  58. package/lib/tools/shared/line/line-path.js +71 -95
  59. package/lib/tools/shared/line/line-path.js.map +1 -1
  60. package/lib/tools/shared/line/with-root-edge.js +22 -56
  61. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  62. package/lib/tools/shared/point/arrow-point.js +18 -45
  63. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  64. package/lib/tools/shared/point/arrow.js +16 -42
  65. package/lib/tools/shared/point/arrow.js.map +1 -1
  66. package/lib/tools/shared/point/base-point.js +44 -58
  67. package/lib/tools/shared/point/base-point.js.map +1 -1
  68. package/lib/tools/shared/point/index.js +38 -52
  69. package/lib/tools/shared/point/index.js.map +1 -1
  70. package/lib/tools/shared/styles.js +8 -31
  71. package/lib/tools/shared/styles.js.map +1 -1
  72. package/lib/tools/shared/types.js +1 -5
  73. package/lib/tools/shared/types.js.map +1 -1
  74. package/lib/undo-redo.js +27 -67
  75. package/lib/undo-redo.js.map +1 -1
  76. package/lib/use-debounce.js +4 -11
  77. package/lib/use-debounce.js.map +1 -1
  78. package/lib/utils.js +56 -131
  79. package/lib/utils.js.map +1 -1
  80. package/package.json +26 -31
  81. package/src/__tests__/graph-with-controls.test.jsx +23 -10
  82. package/src/__tests__/graph.test.jsx +36 -171
  83. package/src/__tests__/grid.test.jsx +9 -6
  84. package/src/__tests__/labels.test.jsx +11 -8
  85. package/src/__tests__/mark-label.test.jsx +15 -17
  86. package/src/__tests__/toggle-bar.test.jsx +46 -17
  87. package/src/__tests__/tool-menu.test.jsx +12 -8
  88. package/src/__tests__/undo-redo.test.jsx +9 -8
  89. package/src/__tests__/utils.js +3 -0
  90. package/src/axis/__tests__/arrow.test.jsx +21 -17
  91. package/src/axis/__tests__/axes.test.jsx +117 -155
  92. package/src/axis/arrow.jsx +7 -12
  93. package/src/axis/axes.jsx +41 -51
  94. package/src/coordinates-label.jsx +13 -18
  95. package/src/graph-with-controls.jsx +90 -93
  96. package/src/grid-setup.jsx +203 -205
  97. package/src/grid.jsx +2 -4
  98. package/src/labels.jsx +84 -125
  99. package/src/mark-label.jsx +14 -25
  100. package/src/toggle-bar.jsx +135 -163
  101. package/src/tool-menu.jsx +136 -195
  102. package/src/tools/line/__tests__/component.test.jsx +7 -7
  103. package/src/tools/line/component.jsx +29 -29
  104. package/src/tools/polygon/__tests__/component.test.jsx +13 -152
  105. package/src/tools/polygon/__tests__/line.test.jsx +7 -9
  106. package/src/tools/polygon/__tests__/polygon.test.jsx +8 -8
  107. package/src/tools/polygon/component.jsx +2 -4
  108. package/src/tools/polygon/line.jsx +26 -24
  109. package/src/tools/polygon/polygon.jsx +35 -40
  110. package/src/tools/shared/__tests__/arrow-head.test.jsx +16 -17
  111. package/src/tools/shared/line/__tests__/index.test.jsx +26 -163
  112. package/src/tools/shared/line/__tests__/line-path.test.jsx +9 -9
  113. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +14 -24
  114. package/src/tools/shared/line/index.jsx +3 -3
  115. package/src/tools/shared/line/line-path.jsx +51 -48
  116. package/src/tools/shared/line/with-root-edge.jsx +1 -1
  117. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
  118. package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
  119. package/src/tools/shared/point/base-point.jsx +33 -6
  120. package/src/tools/shared/point/index.jsx +30 -32
  121. package/src/undo-redo.jsx +16 -24
  122. package/esm/index.css +0 -847
  123. package/esm/index.js +0 -233259
  124. package/esm/index.js.map +0 -1
  125. package/esm/package.json +0 -3
  126. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -114
  127. package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -213
  128. package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
  129. package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
  130. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -37
  131. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
  132. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -35
  133. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -15
  134. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
  135. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
  136. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
  137. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -94
  138. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -44
  139. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -53
  140. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -32
  141. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
  142. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -57
  143. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
  144. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -55
  145. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -43
@@ -1,4 +1,4 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
 
4
4
  import { xy } from './utils';
@@ -6,6 +6,7 @@ import { xy } from './utils';
6
6
  import Graph, { removeBuildingToolIfCurrentToolDiffers } from '../graph';
7
7
  import { toolsArr } from '../tools';
8
8
 
9
+ // Pure function tests - keep as-is
9
10
  describe('removeBuildingToolIfCurrentToolDiffers', () => {
10
11
  let marks = [
11
12
  {
@@ -32,9 +33,14 @@ describe('removeBuildingToolIfCurrentToolDiffers', () => {
32
33
  });
33
34
  });
34
35
 
36
+ // Note: Instance method tests have been removed. Component behavior should be tested
37
+ // through user interactions and integration tests.
35
38
  describe('Graph', () => {
36
39
  let onChangeMarks = jest.fn();
37
- let wrapper;
40
+
41
+ beforeEach(() => {
42
+ onChangeMarks.mockClear();
43
+ });
38
44
 
39
45
  const complete = jest.fn();
40
46
  const addPoint = jest.fn();
@@ -43,7 +49,6 @@ describe('Graph', () => {
43
49
  currentTool.addPoint = addPoint;
44
50
 
45
51
  const props = {
46
- classes: {},
47
52
  className: 'className',
48
53
  onChangeMarks,
49
54
  tools: toolsArr,
@@ -53,178 +58,38 @@ describe('Graph', () => {
53
58
  currentTool,
54
59
  };
55
60
 
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);
61
+ const renderComponent = (extras) => {
62
+ const properties = {
63
+ ...props,
64
+ marks: [
65
+ {
66
+ type: 'point',
67
+ x: 2,
68
+ y: 2,
69
+ label: 'Point',
70
+ showLabel: true,
71
+ },
72
+ {
73
+ type: 'line',
74
+ from: { x: 0, y: 0 },
75
+ label: 'Line',
76
+ building: true,
77
+ },
78
+ ],
79
+ ...extras,
79
80
  };
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;
81
+ return render(<Graph {...properties} />);
82
+ };
204
83
 
205
- expect(w.instance().getComponent({ type: toolsArr[0].type })).toEqual(null);
206
- });
84
+ describe('rendering', () => {
85
+ it('renders without crashing', () => {
86
+ const { container } = renderComponent();
87
+ expect(container.firstChild).toBeInTheDocument();
207
88
  });
208
89
 
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
- });
90
+ it('renders SVG graph', () => {
91
+ const { container } = renderComponent();
92
+ expect(container.querySelector('svg')).toBeInTheDocument();
228
93
  });
229
94
  });
230
95
  });
@@ -1,20 +1,23 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { Grid } from '../grid';
4
4
  import { graphProps } from './utils';
5
5
 
6
6
  describe('Grid', () => {
7
- let w;
8
- const wrapper = (extras) => {
7
+ const renderComponent = (extras) => {
9
8
  const defaults = {
10
9
  classes: {},
11
10
  className: 'className',
12
11
  graphProps: graphProps(),
13
12
  };
14
13
  const props = { ...defaults, ...extras };
15
- return shallow(<Grid {...props} />);
14
+ return render(<Grid {...props} />);
16
15
  };
17
- describe('snapshot', () => {
18
- it('renders', () => expect(wrapper()).toMatchSnapshot());
16
+
17
+ describe('rendering', () => {
18
+ it('renders without crashing', () => {
19
+ const { container } = renderComponent();
20
+ expect(container.firstChild).toBeInTheDocument();
21
+ });
19
22
  });
20
23
  });
@@ -1,24 +1,27 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
 
4
4
  import Labels, { getTransform } from '../labels';
5
+ import { graphProps } from './utils';
5
6
 
6
7
  describe('Labels', () => {
7
- let w;
8
8
  let onChange = jest.fn();
9
- const wrapper = (extras) => {
9
+
10
+ const renderComponent = (extras) => {
10
11
  const defaults = {
11
12
  classes: {},
12
13
  className: 'className',
13
14
  onChange,
15
+ graphProps: graphProps(),
14
16
  };
15
17
  const props = { ...defaults, ...extras };
16
- return shallow(<Labels {...props} />);
18
+ return render(<Labels {...props} />);
17
19
  };
18
- describe('snapshot', () => {
19
- it('renders', () => {
20
- w = wrapper();
21
- expect(w).toMatchSnapshot();
20
+
21
+ describe('rendering', () => {
22
+ it('renders without crashing', () => {
23
+ const { container } = renderComponent();
24
+ expect(container.firstChild).toBeInTheDocument();
22
25
  });
23
26
  });
24
27
  });
@@ -1,36 +1,34 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { MarkLabel, position, coordinates } from '../mark-label';
4
4
  import { graphProps as getGraphProps } from './utils';
5
5
 
6
- const xyFn = () => {
7
- const out = jest.fn((n) => n);
8
- out.invert = jest.fn((n) => n);
9
- return out;
10
- };
11
-
12
6
  describe('MarkLabel', () => {
13
- let w;
14
7
  let onChange = jest.fn();
15
- const wrapper = (extras) => {
8
+ let inputRef = jest.fn();
9
+
10
+ const renderComponent = (extras) => {
16
11
  const defaults = {
17
12
  classes: {},
18
13
  className: 'className',
19
14
  onChange,
15
+ inputRef,
20
16
  mark: { x: 1, y: 1 },
21
17
  graphProps: getGraphProps(0, 10, 0, 10),
22
18
  };
23
19
  const props = { ...defaults, ...extras };
24
- return shallow(<MarkLabel {...props} />);
20
+ return render(<MarkLabel {...props} />);
25
21
  };
26
- describe('snapshot', () => {
27
- it('renders', () => {
28
- w = wrapper();
29
- expect(w).toMatchSnapshot();
22
+
23
+ describe('rendering', () => {
24
+ it('renders without crashing', () => {
25
+ const { container } = renderComponent();
26
+ expect(container.firstChild).toBeInTheDocument();
30
27
  });
31
- it('renders', () => {
32
- w = wrapper({ mark: { x: 10, y: 10 } });
33
- expect(w).toMatchSnapshot();
28
+
29
+ it('renders with different mark position', () => {
30
+ const { container } = renderComponent({ mark: { x: 10, y: 10 } });
31
+ expect(container.firstChild).toBeInTheDocument();
34
32
  });
35
33
  });
36
34
  });
@@ -1,36 +1,65 @@
1
- import { shallow } from 'enzyme';
1
+ import { render, screen } from '@pie-lib/test-utils';
2
+ import userEvent from '@testing-library/user-event';
2
3
  import React from 'react';
3
4
 
4
5
  import { ToggleBar } from '../toggle-bar';
5
6
 
7
+ // Mock DragProvider to avoid @dnd-kit React version conflicts
8
+ jest.mock('@pie-lib/drag', () => ({
9
+ DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
10
+ }));
11
+
12
+ // Mock Translator to return the key as-is for testing
13
+ jest.mock('@pie-lib/translator', () => ({
14
+ translator: {
15
+ t: (key) => {
16
+ // Extract tool name from key like "graphing.point" -> "point"
17
+ const parts = key.split('.');
18
+ return parts[parts.length - 1];
19
+ },
20
+ },
21
+ }));
22
+
6
23
  describe('ToggleBar', () => {
7
- let w;
8
24
  let onChange = jest.fn();
9
- const wrapper = (extras) => {
25
+
26
+ beforeEach(() => {
27
+ onChange.mockClear();
28
+ });
29
+
30
+ const renderComponent = (extras) => {
10
31
  const defaults = {
11
- classes: {},
12
32
  className: 'className',
13
33
  onChange,
14
- options: ['one', 'two'],
34
+ options: ['line', 'polygon'],
35
+ language: 'en',
15
36
  };
16
37
  const props = { ...defaults, ...extras };
17
- return shallow(<ToggleBar {...props} />);
38
+ return render(<ToggleBar {...props} />);
18
39
  };
19
40
 
20
- describe('snapshot', () => {
21
- it('renders', () => {
22
- w = wrapper();
23
- expect(w).toMatchSnapshot();
41
+ describe('rendering', () => {
42
+ it('renders without crashing', () => {
43
+ const { container } = renderComponent();
44
+ expect(container.firstChild).toBeInTheDocument();
45
+ });
46
+
47
+ it('renders tool buttons for valid tools', () => {
48
+ renderComponent({ options: ['line', 'polygon'] });
49
+ expect(screen.getByText(/line/i)).toBeInTheDocument();
50
+ expect(screen.getByText(/polygon/i)).toBeInTheDocument();
24
51
  });
25
52
  });
26
53
 
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
- });
54
+ describe('interactions', () => {
55
+ it('calls onChange when tool button is clicked', async () => {
56
+ const user = userEvent.setup();
57
+ renderComponent({ options: ['line', 'polygon'] });
58
+
59
+ const lineButton = screen.getByText(/line/i).closest('button');
60
+ await user.click(lineButton);
61
+
62
+ expect(onChange).toHaveBeenCalledWith('line');
34
63
  });
35
64
  });
36
65
  });
@@ -1,29 +1,33 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
 
4
4
  import ToolMenu from '../tool-menu';
5
5
 
6
6
  describe('ToolMenu', () => {
7
- let w;
8
7
  let onChange = jest.fn();
9
8
  const tools = ['one', 'two'];
10
9
 
11
- const wrapper = (extras) => {
10
+ const renderComponent = (extras) => {
12
11
  const defaults = {
13
12
  classes: {},
14
13
  className: 'className',
15
14
  onChange,
16
15
  currentTool: tools[0],
17
16
  tools,
17
+ gssLineData: {
18
+ selectedTool: 'lineA',
19
+ lineA: { lineType: 'Solid' },
20
+ lineB: { lineType: 'Solid' },
21
+ },
18
22
  };
19
23
  const props = { ...defaults, ...extras };
20
- return shallow(<ToolMenu {...props} />);
24
+ return render(<ToolMenu {...props} />);
21
25
  };
22
26
 
23
- describe('snapshot', () => {
24
- it('renders', () => {
25
- w = wrapper();
26
- expect(w).toMatchSnapshot();
27
+ describe('rendering', () => {
28
+ it('renders without crashing', () => {
29
+ const { container } = renderComponent();
30
+ expect(container.firstChild).toBeInTheDocument();
27
31
  });
28
32
  });
29
33
  });
@@ -1,25 +1,26 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import UndoRedo from '../undo-redo';
4
4
 
5
5
  describe('UndoRedo', () => {
6
- let w;
7
6
  let onUndo = jest.fn();
8
7
  let onRedo = jest.fn();
9
8
  let onReset = jest.fn();
10
- const wrapper = (extras) => {
9
+
10
+ const renderComponent = (extras) => {
11
11
  const defaults = {
12
12
  onUndo,
13
13
  onRedo,
14
14
  onReset,
15
15
  };
16
16
  const props = { ...defaults, ...extras };
17
- return shallow(<UndoRedo {...props} />);
17
+ return render(<UndoRedo {...props} />);
18
18
  };
19
- describe('snapshot', () => {
20
- it('renders', () => {
21
- w = wrapper();
22
- expect(w).toMatchSnapshot();
19
+
20
+ describe('rendering', () => {
21
+ it('renders without crashing', () => {
22
+ const { container } = renderComponent();
23
+ expect(container.firstChild).toBeInTheDocument();
23
24
  });
24
25
  });
25
26
  });
@@ -1,6 +1,9 @@
1
1
  export const scaleMock = () => {
2
2
  const fn = jest.fn((n) => n);
3
3
  fn.invert = jest.fn((n) => n);
4
+ fn.domain = jest.fn(() => fn);
5
+ fn.range = jest.fn(() => fn);
6
+ fn.copy = jest.fn(() => scaleMock());
4
7
  return fn;
5
8
  };
6
9
 
@@ -1,11 +1,11 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { Arrow } from '../arrow';
4
4
 
5
5
  describe('Arrow', () => {
6
- let w;
7
6
  let onChange = jest.fn();
8
- const wrapper = (extras) => {
7
+
8
+ const renderComponent = (extras) => {
9
9
  const defaults = {
10
10
  classes: {},
11
11
  className: 'className',
@@ -16,24 +16,28 @@ describe('Arrow', () => {
16
16
  },
17
17
  };
18
18
  const props = { ...defaults, ...extras };
19
- return shallow(<Arrow {...props} />);
19
+ return render(<Arrow {...props} />);
20
20
  };
21
- describe('snapshot', () => {
22
- it('up', () => {
23
- w = wrapper({ direction: 'up' });
24
- expect(w).toMatchSnapshot();
21
+
22
+ describe('rendering', () => {
23
+ it('renders with direction up', () => {
24
+ const { container } = renderComponent({ direction: 'up' });
25
+ expect(container.firstChild).toBeInTheDocument();
25
26
  });
26
- it('down', () => {
27
- w = wrapper({ direction: 'down' });
28
- expect(w).toMatchSnapshot();
27
+
28
+ it('renders with direction down', () => {
29
+ const { container } = renderComponent({ direction: 'down' });
30
+ expect(container.firstChild).toBeInTheDocument();
29
31
  });
30
- it('left', () => {
31
- w = wrapper({ direction: 'left' });
32
- expect(w).toMatchSnapshot();
32
+
33
+ it('renders with direction left', () => {
34
+ const { container } = renderComponent({ direction: 'left' });
35
+ expect(container.firstChild).toBeInTheDocument();
33
36
  });
34
- it('right', () => {
35
- w = wrapper({ direction: 'right' });
36
- expect(w).toMatchSnapshot();
37
+
38
+ it('renders with direction right', () => {
39
+ const { container } = renderComponent({ direction: 'right' });
40
+ expect(container.firstChild).toBeInTheDocument();
37
41
  });
38
42
  });
39
43
  });