@pie-lib/graphing-solution-set 4.1.0-beta.8 → 4.1.0-beta.9

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 (34) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/bg.test.jsx +0 -250
  3. package/src/__tests__/coordinates-label.test.jsx +0 -243
  4. package/src/__tests__/graph-with-controls.test.jsx +0 -184
  5. package/src/__tests__/graph.test.jsx +0 -93
  6. package/src/__tests__/grid-setup.test.jsx +0 -645
  7. package/src/__tests__/grid.test.jsx +0 -23
  8. package/src/__tests__/labels.test.jsx +0 -41
  9. package/src/__tests__/mark-label.test.jsx +0 -66
  10. package/src/__tests__/toggle-bar.test.jsx +0 -106
  11. package/src/__tests__/tool-menu.test.jsx +0 -453
  12. package/src/__tests__/undo-redo.test.jsx +0 -26
  13. package/src/__tests__/use-debounce.test.js +0 -21
  14. package/src/__tests__/utils.js +0 -41
  15. package/src/__tests__/utils.test.js +0 -105
  16. package/src/axis/__tests__/arrow.test.jsx +0 -43
  17. package/src/axis/__tests__/axes.test.jsx +0 -182
  18. package/src/container/__tests__/actions.test.js +0 -105
  19. package/src/container/__tests__/index.test.jsx +0 -227
  20. package/src/container/__tests__/marks.test.js +0 -172
  21. package/src/container/__tests__/middleware.test.js +0 -235
  22. package/src/container/__tests__/reducer.test.js +0 -324
  23. package/src/tools/line/__tests__/component.test.jsx +0 -37
  24. package/src/tools/polygon/__tests__/component.test.jsx +0 -487
  25. package/src/tools/polygon/__tests__/index.test.js +0 -65
  26. package/src/tools/polygon/__tests__/line.test.jsx +0 -23
  27. package/src/tools/polygon/__tests__/polygon.test.jsx +0 -44
  28. package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -33
  29. package/src/tools/shared/line/__tests__/index.test.jsx +0 -553
  30. package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -56
  31. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -488
  32. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
  33. package/src/tools/shared/point/__tests__/arrow.test.jsx +0 -469
  34. package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
@@ -1,66 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { coordinates, MarkLabel, position } from '../mark-label';
4
- import { graphProps as getGraphProps } from './utils';
5
-
6
- describe('MarkLabel', () => {
7
- let onChange = jest.fn();
8
- let inputRef = jest.fn();
9
-
10
- const renderComponent = (extras) => {
11
- const defaults = {
12
- classes: {},
13
- className: 'className',
14
- onChange,
15
- inputRef,
16
- mark: { x: 1, y: 1 },
17
- graphProps: getGraphProps(0, 10, 0, 10),
18
- };
19
- const props = { ...defaults, ...extras };
20
- return render(<MarkLabel {...props} />);
21
- };
22
-
23
- describe('rendering', () => {
24
- it('renders without crashing', () => {
25
- const { container } = renderComponent();
26
- expect(container.firstChild).toBeInTheDocument();
27
- });
28
-
29
- it('renders with different mark position', () => {
30
- const { container } = renderComponent({ mark: { x: 10, y: 10 } });
31
- expect(container.firstChild).toBeInTheDocument();
32
- });
33
- });
34
- });
35
-
36
- describe('position', () => {
37
- const assertPosition = (mark, rect, expected) => {
38
- it(`${mark.x},${mark.y} + ${rect.width},${rect.height} => ${expected}`, () => {
39
- // we set range.min to a value because in pixels - the greater the Y the lower down on the screen.
40
- const graphProps = getGraphProps(0, 12, 12, 0);
41
- const result = position(graphProps, mark, rect);
42
- expect(result).toEqual(expected);
43
- });
44
- };
45
-
46
- assertPosition({ x: 0, y: 0 }, { width: 10, height: 10 }, 'top-left');
47
- assertPosition({ x: 0, y: 0 }, { width: 1, height: 1 }, 'bottom-right');
48
- assertPosition({ x: 0, y: 0 }, { width: 10, height: 0 }, 'bottom-left');
49
- assertPosition({ x: 0, y: 0 }, { width: 0, height: 10 }, 'top-right');
50
- });
51
-
52
- describe('coordinates', () => {
53
- const assertCoordinates = (mark, rect, pos, expected) => {
54
- it(`${mark.x}, ${mark.y} -> ${pos} = ${expected.left}, ${expected.top}`, () => {
55
- const result = coordinates(getGraphProps(), mark, rect, pos);
56
- expect(result).toEqual(expected);
57
- });
58
- };
59
- assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'top-left', { left: -10, top: -10 });
60
- assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'bottom-left', { left: -10, top: 10 });
61
- assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'top-right', { left: 10, top: -10 });
62
- assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'bottom-right', {
63
- left: 10,
64
- top: 10,
65
- });
66
- });
@@ -1,106 +0,0 @@
1
- import { render, screen } from '@pie-lib/test-utils';
2
- import userEvent from '@testing-library/user-event';
3
- import React from 'react';
4
-
5
- import { ToggleBar } from '../toggle-bar';
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 @dnd-kit/core hooks to avoid DndContext requirement
13
- jest.mock('@dnd-kit/core', () => ({
14
- useDraggable: jest.fn(() => ({
15
- attributes: {
16
- role: 'button',
17
- tabIndex: 0,
18
- },
19
- listeners: {
20
- onPointerDown: jest.fn(),
21
- },
22
- setNodeRef: jest.fn(),
23
- transform: null,
24
- transition: null,
25
- isDragging: false,
26
- })),
27
- useDroppable: jest.fn(() => ({
28
- setNodeRef: jest.fn(),
29
- isOver: false,
30
- active: null,
31
- })),
32
- }));
33
-
34
- // Mock @dnd-kit/utilities for CSS transform
35
- jest.mock('@dnd-kit/utilities', () => ({
36
- CSS: {
37
- Transform: {
38
- toString: jest.fn((transform) => (transform ? 'translate3d(0, 0, 0)' : '')),
39
- },
40
- },
41
- }));
42
-
43
- // Mock @dnd-kit/sortable for arrayMove
44
- jest.mock('@dnd-kit/sortable', () => ({
45
- arrayMove: jest.fn((array, from, to) => {
46
- const newArray = [...array];
47
- const [removed] = newArray.splice(from, 1);
48
- newArray.splice(to, 0, removed);
49
- return newArray;
50
- }),
51
- }));
52
-
53
- // Mock Translator to return the key as-is for testing
54
- jest.mock('@pie-lib/translator', () => ({
55
- translator: {
56
- t: (key) => {
57
- // Extract tool name from key like "graphing.point" -> "point"
58
- const parts = key.split('.');
59
- return parts[parts.length - 1];
60
- },
61
- },
62
- }));
63
-
64
- describe('ToggleBar', () => {
65
- let onChange = jest.fn();
66
-
67
- beforeEach(() => {
68
- onChange.mockClear();
69
- });
70
-
71
- const renderComponent = (extras) => {
72
- const defaults = {
73
- className: 'className',
74
- onChange,
75
- options: ['line', 'polygon'],
76
- language: 'en',
77
- };
78
- const props = { ...defaults, ...extras };
79
- return render(<ToggleBar {...props} />);
80
- };
81
-
82
- describe('rendering', () => {
83
- it('renders without crashing', () => {
84
- const { container } = renderComponent();
85
- expect(container.firstChild).toBeInTheDocument();
86
- });
87
-
88
- it('renders tool buttons for valid tools', () => {
89
- renderComponent({ options: ['line', 'polygon'] });
90
- expect(screen.getByText(/line/i)).toBeInTheDocument();
91
- expect(screen.getByText(/polygon/i)).toBeInTheDocument();
92
- });
93
- });
94
-
95
- describe('interactions', () => {
96
- it('calls onChange when tool button is clicked', async () => {
97
- const user = userEvent.setup();
98
- renderComponent({ options: ['line', 'polygon'] });
99
-
100
- const lineButton = screen.getByText(/line/i).closest('button');
101
- await user.click(lineButton);
102
-
103
- expect(onChange).toHaveBeenCalledWith('line');
104
- });
105
- });
106
- });
@@ -1,453 +0,0 @@
1
- import { fireEvent, render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
-
4
- import ToolMenu from '../tool-menu';
5
-
6
- describe('ToolMenu', () => {
7
- let onChange;
8
- const tools = ['one', 'two'];
9
-
10
- beforeEach(() => {
11
- onChange = jest.fn();
12
- });
13
-
14
- const renderComponent = (extras) => {
15
- const defaults = {
16
- classes: {},
17
- className: 'className',
18
- onChange,
19
- currentTool: tools[0],
20
- tools,
21
- gssLineData: {
22
- selectedTool: 'lineA',
23
- numberOfLines: 2,
24
- lineA: { lineType: 'Solid' },
25
- lineB: { lineType: 'Solid' },
26
- },
27
- };
28
- const props = { ...defaults, ...extras };
29
- return render(<ToolMenu {...props} />);
30
- };
31
-
32
- describe('rendering', () => {
33
- it('renders without crashing', () => {
34
- const { container } = renderComponent();
35
- expect(container.firstChild).toBeInTheDocument();
36
- });
37
-
38
- it('renders Line A radio button', () => {
39
- const { getByText } = renderComponent();
40
- expect(getByText('Line A')).toBeInTheDocument();
41
- });
42
-
43
- it('renders Line B radio button when numberOfLines is 2', () => {
44
- const { getByText } = renderComponent();
45
- expect(getByText('Line B')).toBeInTheDocument();
46
- });
47
-
48
- it('does not render Line B radio button when numberOfLines is 1', () => {
49
- const { queryByText } = renderComponent({
50
- gssLineData: {
51
- selectedTool: 'lineA',
52
- numberOfLines: 1,
53
- lineA: { lineType: 'Solid' },
54
- lineB: { lineType: 'Solid' },
55
- },
56
- });
57
- expect(queryByText('Line B')).not.toBeInTheDocument();
58
- });
59
-
60
- it('renders Solution Set radio button', () => {
61
- const { getByText } = renderComponent();
62
- expect(getByText('Solution Set')).toBeInTheDocument();
63
- });
64
-
65
- it('renders Solid and Dashed buttons for Line A', () => {
66
- const { getAllByText } = renderComponent();
67
- const solidButtons = getAllByText(/Solid/);
68
- const dashedButtons = getAllByText(/Dashed/);
69
- expect(solidButtons.length).toBeGreaterThan(0);
70
- expect(dashedButtons.length).toBeGreaterThan(0);
71
- });
72
-
73
- it('shows checkmark on selected line type for Line A', () => {
74
- const { getAllByText } = renderComponent({
75
- gssLineData: {
76
- selectedTool: 'lineA',
77
- numberOfLines: 2,
78
- lineA: { lineType: 'Solid' },
79
- lineB: { lineType: 'Dashed' },
80
- },
81
- });
82
- const solidButtons = getAllByText(/✔ Solid/);
83
- expect(solidButtons.length).toBeGreaterThan(0);
84
- });
85
-
86
- it('disables all controls when disabled prop is true', () => {
87
- const { getAllByRole } = renderComponent({ disabled: true });
88
- const radios = getAllByRole('radio');
89
- const buttons = getAllByRole('button');
90
-
91
- radios.forEach((radio) => {
92
- expect(radio).toBeDisabled();
93
- });
94
-
95
- buttons.forEach((button) => {
96
- expect(button).toBeDisabled();
97
- });
98
- });
99
- });
100
-
101
- describe('onChangeRadioValue', () => {
102
- it('calls onChange with updated selectedTool when lineA radio is clicked', () => {
103
- const { getAllByRole } = renderComponent({
104
- gssLineData: {
105
- selectedTool: 'solutionSet',
106
- numberOfLines: 2,
107
- lineA: { lineType: 'Solid' },
108
- lineB: { lineType: 'Solid' },
109
- },
110
- });
111
-
112
- const radios = getAllByRole('radio');
113
- const lineARadio = radios.find((r) => r.value === 'lineA');
114
-
115
- fireEvent.click(lineARadio);
116
-
117
- expect(onChange).toHaveBeenCalledTimes(1);
118
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
119
- expect(updatedData.selectedTool).toBe('lineA');
120
- expect(oldSelectedTool).toBe('solutionSet');
121
- });
122
-
123
- it('calls onChange with updated selectedTool when lineB radio is clicked', () => {
124
- const { getAllByRole } = renderComponent({
125
- gssLineData: {
126
- selectedTool: 'lineA',
127
- numberOfLines: 2,
128
- lineA: { lineType: 'Solid' },
129
- lineB: { lineType: 'Solid' },
130
- },
131
- });
132
-
133
- const radios = getAllByRole('radio');
134
- const lineBRadio = radios.find((r) => r.value === 'lineB');
135
-
136
- fireEvent.click(lineBRadio);
137
-
138
- expect(onChange).toHaveBeenCalledTimes(1);
139
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
140
- expect(updatedData.selectedTool).toBe('lineB');
141
- expect(oldSelectedTool).toBe('lineA');
142
- });
143
-
144
- it('calls onChange with updated selectedTool when solutionSet radio is clicked', () => {
145
- const { getAllByRole } = renderComponent({
146
- gssLineData: {
147
- selectedTool: 'lineA',
148
- numberOfLines: 2,
149
- lineA: { lineType: 'Solid' },
150
- lineB: { lineType: 'Solid' },
151
- },
152
- });
153
-
154
- const radios = getAllByRole('radio');
155
- const solutionSetRadio = radios.find((r) => r.value === 'solutionSet');
156
-
157
- fireEvent.click(solutionSetRadio);
158
-
159
- expect(onChange).toHaveBeenCalledTimes(1);
160
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
161
- expect(updatedData.selectedTool).toBe('solutionSet');
162
- expect(oldSelectedTool).toBe('lineA');
163
- });
164
-
165
- it('preserves other gssLineData properties when changing selectedTool', () => {
166
- const { getAllByRole } = renderComponent({
167
- gssLineData: {
168
- selectedTool: 'lineA',
169
- numberOfLines: 2,
170
- lineA: { lineType: 'Dashed' },
171
- lineB: { lineType: 'Solid' },
172
- },
173
- });
174
-
175
- const radios = getAllByRole('radio');
176
- const lineBRadio = radios.find((r) => r.value === 'lineB');
177
-
178
- fireEvent.click(lineBRadio);
179
-
180
- const [updatedData] = onChange.mock.calls[0];
181
- expect(updatedData.lineA.lineType).toBe('Dashed');
182
- expect(updatedData.lineB.lineType).toBe('Solid');
183
- expect(updatedData.numberOfLines).toBe(2);
184
- });
185
-
186
- it('does not call onChange when disabled', () => {
187
- const { getAllByRole } = renderComponent({
188
- disabled: true,
189
- gssLineData: {
190
- selectedTool: 'lineA',
191
- numberOfLines: 2,
192
- lineA: { lineType: 'Solid' },
193
- lineB: { lineType: 'Solid' },
194
- },
195
- });
196
-
197
- const radios = getAllByRole('radio');
198
- const lineBRadio = radios.find((r) => r.value === 'lineB');
199
-
200
- // Disabled radios should not fire change events
201
- expect(lineBRadio).toBeDisabled();
202
- });
203
- });
204
-
205
- describe('lineTypeChange', () => {
206
- it('calls onChange with updated lineType for Line A when Solid button is clicked', () => {
207
- const { getAllByText } = renderComponent({
208
- gssLineData: {
209
- selectedTool: 'lineA',
210
- numberOfLines: 2,
211
- lineA: { lineType: 'Dashed' },
212
- lineB: { lineType: 'Solid' },
213
- },
214
- });
215
-
216
- const solidButtons = getAllByText(/Solid/);
217
- // First solid button should be for Line A
218
- fireEvent.click(solidButtons[0]);
219
-
220
- expect(onChange).toHaveBeenCalledTimes(1);
221
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
222
- expect(updatedData.lineA.lineType).toBe('Solid');
223
- expect(oldSelectedTool).toBe('lineA');
224
- });
225
-
226
- it('calls onChange with updated lineType for Line A when Dashed button is clicked', () => {
227
- const { getAllByText } = renderComponent({
228
- gssLineData: {
229
- selectedTool: 'lineA',
230
- numberOfLines: 2,
231
- lineA: { lineType: 'Solid' },
232
- lineB: { lineType: 'Solid' },
233
- },
234
- });
235
-
236
- const dashedButtons = getAllByText(/Dashed/);
237
- // First dashed button should be for Line A
238
- fireEvent.click(dashedButtons[0]);
239
-
240
- expect(onChange).toHaveBeenCalledTimes(1);
241
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
242
- expect(updatedData.lineA.lineType).toBe('Dashed');
243
- expect(oldSelectedTool).toBe('lineA');
244
- });
245
-
246
- it('calls onChange with updated lineType for Line B when Solid button is clicked', () => {
247
- const { getAllByText } = renderComponent({
248
- gssLineData: {
249
- selectedTool: 'lineB',
250
- numberOfLines: 2,
251
- lineA: { lineType: 'Solid' },
252
- lineB: { lineType: 'Dashed' },
253
- },
254
- });
255
-
256
- const solidButtons = getAllByText(/Solid/);
257
- // Second solid button should be for Line B
258
- fireEvent.click(solidButtons[1]);
259
-
260
- expect(onChange).toHaveBeenCalledTimes(1);
261
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
262
- expect(updatedData.lineB.lineType).toBe('Solid');
263
- expect(oldSelectedTool).toBe('lineB');
264
- });
265
-
266
- it('calls onChange with updated lineType for Line B when Dashed button is clicked', () => {
267
- const { getAllByText } = renderComponent({
268
- gssLineData: {
269
- selectedTool: 'lineB',
270
- numberOfLines: 2,
271
- lineA: { lineType: 'Solid' },
272
- lineB: { lineType: 'Solid' },
273
- },
274
- });
275
-
276
- const dashedButtons = getAllByText(/Dashed/);
277
- // Second dashed button should be for Line B
278
- fireEvent.click(dashedButtons[1]);
279
-
280
- expect(onChange).toHaveBeenCalledTimes(1);
281
- const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
282
- expect(updatedData.lineB.lineType).toBe('Dashed');
283
- expect(oldSelectedTool).toBe('lineB');
284
- });
285
-
286
- it('preserves other line properties when changing Line A lineType', () => {
287
- const { getAllByText } = renderComponent({
288
- gssLineData: {
289
- selectedTool: 'lineA',
290
- numberOfLines: 2,
291
- lineA: { lineType: 'Solid' },
292
- lineB: { lineType: 'Dashed' },
293
- },
294
- });
295
-
296
- const dashedButtons = getAllByText(/Dashed/);
297
- fireEvent.click(dashedButtons[0]);
298
-
299
- const [updatedData] = onChange.mock.calls[0];
300
- expect(updatedData.lineA.lineType).toBe('Dashed');
301
- expect(updatedData.lineB.lineType).toBe('Dashed');
302
- expect(updatedData.selectedTool).toBe('lineA');
303
- expect(updatedData.numberOfLines).toBe(2);
304
- });
305
-
306
- it('preserves other line properties when changing Line B lineType', () => {
307
- const { getAllByText } = renderComponent({
308
- gssLineData: {
309
- selectedTool: 'lineB',
310
- numberOfLines: 2,
311
- lineA: { lineType: 'Dashed' },
312
- lineB: { lineType: 'Solid' },
313
- },
314
- });
315
-
316
- const dashedButtons = getAllByText(/Dashed/);
317
- fireEvent.click(dashedButtons[1]);
318
-
319
- const [updatedData] = onChange.mock.calls[0];
320
- expect(updatedData.lineA.lineType).toBe('Dashed');
321
- expect(updatedData.lineB.lineType).toBe('Dashed');
322
- expect(updatedData.selectedTool).toBe('lineB');
323
- expect(updatedData.numberOfLines).toBe(2);
324
- });
325
-
326
- it('handles multiple line type changes correctly', () => {
327
- const { getAllByText } = renderComponent({
328
- gssLineData: {
329
- selectedTool: 'lineA',
330
- numberOfLines: 2,
331
- lineA: { lineType: 'Solid' },
332
- lineB: { lineType: 'Solid' },
333
- },
334
- });
335
-
336
- // Change Line A to Dashed
337
- let dashedButtons = getAllByText(/Dashed/);
338
- fireEvent.click(dashedButtons[0]);
339
-
340
- expect(onChange).toHaveBeenCalledTimes(1);
341
- let [updatedData] = onChange.mock.calls[0];
342
- expect(updatedData.lineA.lineType).toBe('Dashed');
343
-
344
- // Change Line B to Dashed
345
- dashedButtons = getAllByText(/Dashed/);
346
- fireEvent.click(dashedButtons[1]);
347
-
348
- expect(onChange).toHaveBeenCalledTimes(2);
349
- [updatedData] = onChange.mock.calls[1];
350
- expect(updatedData.lineB.lineType).toBe('Dashed');
351
- });
352
-
353
- it('does not call onChange when line type button is disabled', () => {
354
- const { getAllByRole } = renderComponent({
355
- disabled: true,
356
- gssLineData: {
357
- selectedTool: 'lineA',
358
- numberOfLines: 2,
359
- lineA: { lineType: 'Solid' },
360
- lineB: { lineType: 'Solid' },
361
- },
362
- });
363
-
364
- const buttons = getAllByRole('button');
365
-
366
- buttons.forEach((button) => {
367
- expect(button).toBeDisabled();
368
- });
369
- });
370
-
371
- it('maintains correct state when clicking same line type that is already selected', () => {
372
- const { getAllByText } = renderComponent({
373
- gssLineData: {
374
- selectedTool: 'lineA',
375
- numberOfLines: 2,
376
- lineA: { lineType: 'Solid' },
377
- lineB: { lineType: 'Solid' },
378
- },
379
- });
380
-
381
- const solidButtons = getAllByText(/Solid/);
382
- fireEvent.click(solidButtons[0]); // Click Solid when already Solid
383
-
384
- expect(onChange).toHaveBeenCalledTimes(1);
385
- const [updatedData] = onChange.mock.calls[0];
386
- expect(updatedData.lineA.lineType).toBe('Solid');
387
- });
388
- });
389
-
390
- describe('integration tests', () => {
391
- it('allows switching selected tool and changing line type in sequence', () => {
392
- const { getAllByRole, getAllByText } = renderComponent({
393
- gssLineData: {
394
- selectedTool: 'lineA',
395
- numberOfLines: 2,
396
- lineA: { lineType: 'Solid' },
397
- lineB: { lineType: 'Solid' },
398
- },
399
- });
400
-
401
- // Switch to Line B
402
- const radios = getAllByRole('radio');
403
- const lineBRadio = radios.find((r) => r.value === 'lineB');
404
- fireEvent.click(lineBRadio);
405
-
406
- expect(onChange).toHaveBeenCalledTimes(1);
407
- let [updatedData] = onChange.mock.calls[0];
408
- expect(updatedData.selectedTool).toBe('lineB');
409
-
410
- // Change Line B to Dashed
411
- const dashedButtons = getAllByText(/Dashed/);
412
- fireEvent.click(dashedButtons[1]);
413
-
414
- expect(onChange).toHaveBeenCalledTimes(2);
415
- [updatedData] = onChange.mock.calls[1];
416
- expect(updatedData.lineB.lineType).toBe('Dashed');
417
- });
418
-
419
- it('handles complete workflow of switching between all tools and changing line types', () => {
420
- const { getAllByRole, getAllByText } = renderComponent({
421
- gssLineData: {
422
- selectedTool: 'lineA',
423
- numberOfLines: 2,
424
- lineA: { lineType: 'Solid' },
425
- lineB: { lineType: 'Solid' },
426
- },
427
- });
428
-
429
- // Change Line A to Dashed
430
- let dashedButtons = getAllByText(/Dashed/);
431
- fireEvent.click(dashedButtons[0]);
432
- expect(onChange.mock.calls[0][0].lineA.lineType).toBe('Dashed');
433
-
434
- // Switch to Line B
435
- const radios = getAllByRole('radio');
436
- const lineBRadio = radios.find((r) => r.value === 'lineB');
437
- fireEvent.click(lineBRadio);
438
- expect(onChange.mock.calls[1][0].selectedTool).toBe('lineB');
439
-
440
- // Change Line B to Dashed
441
- dashedButtons = getAllByText(/Dashed/);
442
- fireEvent.click(dashedButtons[1]);
443
- expect(onChange.mock.calls[2][0].lineB.lineType).toBe('Dashed');
444
-
445
- // Switch to Solution Set
446
- const solutionSetRadio = radios.find((r) => r.value === 'solutionSet');
447
- fireEvent.click(solutionSetRadio);
448
- expect(onChange.mock.calls[3][0].selectedTool).toBe('solutionSet');
449
-
450
- expect(onChange).toHaveBeenCalledTimes(4);
451
- });
452
- });
453
- });
@@ -1,26 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import UndoRedo from '../undo-redo';
4
-
5
- describe('UndoRedo', () => {
6
- let onUndo = jest.fn();
7
- let onRedo = jest.fn();
8
- let onReset = jest.fn();
9
-
10
- const renderComponent = (extras) => {
11
- const defaults = {
12
- onUndo,
13
- onRedo,
14
- onReset,
15
- };
16
- const props = { ...defaults, ...extras };
17
- return render(<UndoRedo {...props} />);
18
- };
19
-
20
- describe('rendering', () => {
21
- it('renders without crashing', () => {
22
- const { container } = renderComponent();
23
- expect(container.firstChild).toBeInTheDocument();
24
- });
25
- });
26
- });
@@ -1,21 +0,0 @@
1
- import { useState } 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
- });