@pie-lib/graphing-solution-set 3.1.1-next.0 → 3.2.0-next.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/lib/axis/arrow.js +0 -3
- package/lib/axis/arrow.js.map +1 -1
- package/lib/axis/axes.js +0 -16
- package/lib/axis/axes.js.map +1 -1
- package/lib/axis/index.js +0 -7
- package/lib/axis/index.js.map +1 -1
- package/lib/bg.js +0 -6
- package/lib/bg.js.map +1 -1
- package/lib/container/actions.js +0 -1
- package/lib/container/actions.js.map +1 -1
- package/lib/container/index.js +4 -10
- package/lib/container/index.js.map +1 -1
- package/lib/container/marks.js +0 -2
- package/lib/container/marks.js.map +1 -1
- package/lib/container/middleware.js +0 -1
- package/lib/container/middleware.js.map +1 -1
- package/lib/container/reducer.js +0 -1
- package/lib/container/reducer.js.map +1 -1
- package/lib/coordinates-label.js +0 -11
- package/lib/coordinates-label.js.map +1 -1
- package/lib/graph-with-controls.js +3 -22
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/graph.js +7 -26
- package/lib/graph.js.map +1 -1
- package/lib/grid-setup.js +0 -11
- package/lib/grid-setup.js.map +1 -1
- package/lib/grid.js +0 -22
- package/lib/grid.js.map +1 -1
- package/lib/index.js +0 -7
- package/lib/index.js.map +1 -1
- package/lib/labels.js +0 -13
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +0 -16
- package/lib/mark-label.js.map +1 -1
- package/lib/toggle-bar.js +0 -17
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +0 -3
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/index.js +0 -1
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/line/component.js +0 -13
- package/lib/tools/line/component.js.map +1 -1
- package/lib/tools/line/index.js +0 -1
- package/lib/tools/line/index.js.map +1 -1
- package/lib/tools/polygon/component.js +5 -25
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/polygon/index.js +0 -12
- package/lib/tools/polygon/index.js.map +1 -1
- package/lib/tools/polygon/line.js +0 -16
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/polygon/polygon.js +0 -19
- package/lib/tools/polygon/polygon.js.map +1 -1
- package/lib/tools/shared/arrow-head.js +0 -3
- package/lib/tools/shared/arrow-head.js.map +1 -1
- package/lib/tools/shared/line/index.js +7 -22
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +0 -16
- package/lib/tools/shared/line/line-path.js.map +1 -1
- package/lib/tools/shared/line/with-root-edge.js +0 -11
- package/lib/tools/shared/line/with-root-edge.js.map +1 -1
- package/lib/tools/shared/point/arrow-point.js +2 -5
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +0 -3
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +0 -11
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/tools/shared/point/index.js +0 -16
- package/lib/tools/shared/point/index.js.map +1 -1
- package/lib/tools/shared/styles.js +0 -1
- package/lib/tools/shared/styles.js.map +1 -1
- package/lib/tools/shared/types.js +0 -1
- package/lib/tools/shared/types.js.map +1 -1
- package/lib/undo-redo.js +0 -2
- package/lib/undo-redo.js.map +1 -1
- package/lib/use-debounce.js +0 -2
- package/lib/use-debounce.js.map +1 -1
- package/lib/utils.js +8 -26
- package/lib/utils.js.map +1 -1
- package/package.json +14 -11
- package/src/__tests__/bg.test.jsx +250 -0
- package/src/__tests__/coordinates-label.test.jsx +243 -0
- package/src/__tests__/graph-with-controls.test.jsx +9 -10
- package/src/__tests__/graph.test.jsx +0 -2
- package/src/__tests__/grid-setup.test.jsx +645 -0
- package/src/__tests__/mark-label.test.jsx +1 -1
- package/src/__tests__/tool-menu.test.jsx +422 -2
- package/src/__tests__/use-debounce.test.js +1 -1
- package/src/__tests__/utils.test.js +15 -61
- package/src/axis/__tests__/axes.test.jsx +1 -1
- package/src/axis/axes.jsx +7 -21
- package/src/axis/index.js +1 -0
- package/src/bg.jsx +1 -1
- package/src/container/__tests__/actions.test.js +105 -0
- package/src/container/__tests__/index.test.jsx +227 -0
- package/src/container/__tests__/marks.test.js +172 -0
- package/src/container/__tests__/middleware.test.js +235 -0
- package/src/container/__tests__/reducer.test.js +324 -0
- package/src/container/index.jsx +3 -4
- package/src/coordinates-label.jsx +1 -7
- package/src/graph-with-controls.jsx +7 -25
- package/src/graph.jsx +3 -4
- package/src/grid-setup.jsx +1 -1
- package/src/mark-label.jsx +2 -2
- package/src/toggle-bar.jsx +8 -1
- package/src/tool-menu.jsx +1 -1
- package/src/tools/line/__tests__/component.test.jsx +1 -0
- package/src/tools/line/component.jsx +2 -2
- package/src/tools/polygon/__tests__/component.test.jsx +417 -5
- package/src/tools/polygon/__tests__/polygon.test.jsx +1 -1
- package/src/tools/polygon/component.jsx +4 -14
- package/src/tools/polygon/line.jsx +1 -1
- package/src/tools/shared/line/__tests__/index.test.jsx +460 -17
- package/src/tools/shared/line/__tests__/line-path.test.jsx +7 -4
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +439 -14
- package/src/tools/shared/line/index.jsx +4 -6
- package/src/tools/shared/line/line-path.jsx +2 -8
- package/src/tools/shared/point/__tests__/arrow.test.jsx +469 -0
- package/src/tools/shared/point/arrow-point.jsx +2 -2
- package/src/tools/shared/point/base-point.jsx +1 -1
- package/src/tools/shared/point/index.jsx +1 -1
- package/src/undo-redo.jsx +1 -3
- package/src/use-debounce.js +1 -1
- package/src/utils.js +1 -5
- package/NEXT.CHANGELOG.json +0 -16
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
|
+
import { select } from 'd3-selection';
|
|
4
|
+
import Bg from '../bg';
|
|
5
|
+
|
|
6
|
+
jest.mock('d3-selection', () => ({
|
|
7
|
+
select: jest.fn(),
|
|
8
|
+
pointer: jest.fn(() => [50, 50]),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe('Bg', () => {
|
|
12
|
+
let defaultProps;
|
|
13
|
+
let mockRect;
|
|
14
|
+
let clickHandler;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
clickHandler = null;
|
|
18
|
+
mockRect = {
|
|
19
|
+
on: jest.fn((event, handler) => {
|
|
20
|
+
if (event === 'click') {
|
|
21
|
+
clickHandler = handler;
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
node: jest.fn(() => ({})),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
select.mockReturnValue(mockRect);
|
|
28
|
+
|
|
29
|
+
defaultProps = {
|
|
30
|
+
width: 500,
|
|
31
|
+
height: 400,
|
|
32
|
+
onClick: jest.fn(),
|
|
33
|
+
graphProps: {
|
|
34
|
+
domain: { min: -10, max: 10, step: 1, label: 'x', axisLabel: 'X' },
|
|
35
|
+
range: { min: -10, max: 10, step: 1, label: 'y', axisLabel: 'Y' },
|
|
36
|
+
size: { width: 500, height: 400 },
|
|
37
|
+
scale: {
|
|
38
|
+
x: {
|
|
39
|
+
invert: jest.fn((val) => val / 10),
|
|
40
|
+
},
|
|
41
|
+
y: {
|
|
42
|
+
invert: jest.fn((val) => val / 10),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('rendering', () => {
|
|
50
|
+
it('renders without crashing', () => {
|
|
51
|
+
const { container } = render(<Bg {...defaultProps} />);
|
|
52
|
+
expect(container).toBeTruthy();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('renders a rect element', () => {
|
|
56
|
+
const { container } = render(<Bg {...defaultProps} />);
|
|
57
|
+
const rect = container.querySelector('rect');
|
|
58
|
+
expect(rect).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('applies correct dimensions', () => {
|
|
62
|
+
const { container } = render(<Bg {...defaultProps} />);
|
|
63
|
+
const rect = container.querySelector('rect');
|
|
64
|
+
|
|
65
|
+
// Width and height should be expanded by padding * 2
|
|
66
|
+
const padding = 10; // default padding
|
|
67
|
+
expect(rect.getAttribute('width')).toBe(String(defaultProps.width + padding * 2));
|
|
68
|
+
expect(rect.getAttribute('height')).toBe(String(defaultProps.height + padding * 2));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('applies correct transform', () => {
|
|
72
|
+
const { container } = render(<Bg {...defaultProps} />);
|
|
73
|
+
const rect = container.querySelector('rect');
|
|
74
|
+
const padding = 10;
|
|
75
|
+
|
|
76
|
+
expect(rect.getAttribute('transform')).toBe(`translate(-${padding}, -${padding})`);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('sets fill opacity to make it invisible', () => {
|
|
80
|
+
const { container } = render(<Bg {...defaultProps} />);
|
|
81
|
+
const rect = container.querySelector('rect');
|
|
82
|
+
|
|
83
|
+
expect(rect.getAttribute('fill-opacity')).toBe('0.0');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('componentDidMount', () => {
|
|
88
|
+
it('attaches click handler to rect', () => {
|
|
89
|
+
render(<Bg {...defaultProps} />);
|
|
90
|
+
|
|
91
|
+
expect(select).toHaveBeenCalled();
|
|
92
|
+
expect(mockRect.on).toHaveBeenCalledWith('click', expect.any(Function));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('getRectPadding', () => {
|
|
97
|
+
it('returns 10 for normal graphs', () => {
|
|
98
|
+
const { container } = render(<Bg {...defaultProps} />);
|
|
99
|
+
const rect = container.querySelector('rect');
|
|
100
|
+
const padding = 10;
|
|
101
|
+
|
|
102
|
+
expect(rect.getAttribute('width')).toBe(String(defaultProps.width + padding * 2));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('returns 6 for graphs with thinner shapes', () => {
|
|
106
|
+
const props = {
|
|
107
|
+
...defaultProps,
|
|
108
|
+
graphProps: {
|
|
109
|
+
...defaultProps.graphProps,
|
|
110
|
+
domain: { min: -100, max: 100, step: 1, label: 'x', axisLabel: 'X' },
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const { container } = render(<Bg {...props} />);
|
|
115
|
+
const rect = container.querySelector('rect');
|
|
116
|
+
const padding = 6;
|
|
117
|
+
|
|
118
|
+
expect(rect.getAttribute('width')).toBe(String(props.width + padding * 2));
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('onRectClick', () => {
|
|
123
|
+
it('calls onClick with snapped coordinates', () => {
|
|
124
|
+
const { pointer } = require('d3-selection');
|
|
125
|
+
pointer.mockReturnValue([100, 100]);
|
|
126
|
+
|
|
127
|
+
render(<Bg {...defaultProps} />);
|
|
128
|
+
|
|
129
|
+
const event = new MouseEvent('click');
|
|
130
|
+
clickHandler(event);
|
|
131
|
+
|
|
132
|
+
expect(defaultProps.onClick).toHaveBeenCalled();
|
|
133
|
+
const calledWith = defaultProps.onClick.mock.calls[0][0];
|
|
134
|
+
expect(calledWith).toHaveProperty('x');
|
|
135
|
+
expect(calledWith).toHaveProperty('y');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('snaps coordinates to nearest tick', () => {
|
|
139
|
+
const { pointer } = require('d3-selection');
|
|
140
|
+
|
|
141
|
+
render(<Bg {...defaultProps} />);
|
|
142
|
+
|
|
143
|
+
const event = new MouseEvent('click');
|
|
144
|
+
clickHandler(event);
|
|
145
|
+
|
|
146
|
+
expect(defaultProps.onClick).toHaveBeenCalled();
|
|
147
|
+
const { x, y } = defaultProps.onClick.mock.calls[0][0];
|
|
148
|
+
|
|
149
|
+
expect(Number.isInteger(x) || x.toString().length <= 4).toBe(true);
|
|
150
|
+
expect(Number.isInteger(y) || y.toString().length <= 4).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('accounts for padding when converting coordinates', () => {
|
|
154
|
+
const { pointer } = require('d3-selection');
|
|
155
|
+
const coords = [50, 50];
|
|
156
|
+
pointer.mockReturnValue(coords);
|
|
157
|
+
|
|
158
|
+
render(<Bg {...defaultProps} />);
|
|
159
|
+
|
|
160
|
+
const event = new MouseEvent('click');
|
|
161
|
+
clickHandler(event);
|
|
162
|
+
|
|
163
|
+
expect(defaultProps.graphProps.scale.x.invert).toHaveBeenCalled();
|
|
164
|
+
expect(defaultProps.graphProps.scale.y.invert).toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('shouldComponentUpdate', () => {
|
|
169
|
+
it('returns true when width changes', () => {
|
|
170
|
+
const { rerender } = render(<Bg {...defaultProps} />);
|
|
171
|
+
const newProps = {
|
|
172
|
+
...defaultProps,
|
|
173
|
+
width: 600,
|
|
174
|
+
graphProps: {
|
|
175
|
+
...defaultProps.graphProps,
|
|
176
|
+
size: { width: 600, height: defaultProps.height },
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
expect(() => {
|
|
181
|
+
rerender(<Bg {...newProps} />);
|
|
182
|
+
}).not.toThrow();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('returns true when height changes', () => {
|
|
186
|
+
const { rerender } = render(<Bg {...defaultProps} />);
|
|
187
|
+
const newProps = {
|
|
188
|
+
...defaultProps,
|
|
189
|
+
height: 500,
|
|
190
|
+
graphProps: {
|
|
191
|
+
...defaultProps.graphProps,
|
|
192
|
+
size: { width: defaultProps.width, height: 500 },
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
expect(() => {
|
|
197
|
+
rerender(<Bg {...newProps} />);
|
|
198
|
+
}).not.toThrow();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('returns true when graphProps domain/range changes', () => {
|
|
202
|
+
const { rerender } = render(<Bg {...defaultProps} />);
|
|
203
|
+
const newProps = {
|
|
204
|
+
...defaultProps,
|
|
205
|
+
graphProps: {
|
|
206
|
+
...defaultProps.graphProps,
|
|
207
|
+
domain: { min: -5, max: 5, step: 1, label: 'x', axisLabel: 'X' },
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
expect(() => {
|
|
212
|
+
rerender(<Bg {...newProps} />);
|
|
213
|
+
}).not.toThrow();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('edge cases', () => {
|
|
218
|
+
it('handles zero dimensions', () => {
|
|
219
|
+
const props = { ...defaultProps, width: 0, height: 0 };
|
|
220
|
+
const { container } = render(<Bg {...props} />);
|
|
221
|
+
const rect = container.querySelector('rect');
|
|
222
|
+
|
|
223
|
+
expect(rect).toBeTruthy();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('handles large dimensions', () => {
|
|
227
|
+
const props = { ...defaultProps, width: 10000, height: 10000 };
|
|
228
|
+
const { container } = render(<Bg {...props} />);
|
|
229
|
+
const rect = container.querySelector('rect');
|
|
230
|
+
|
|
231
|
+
expect(rect).toBeTruthy();
|
|
232
|
+
expect(rect.getAttribute('width')).toBe('10020');
|
|
233
|
+
expect(rect.getAttribute('height')).toBe('10020');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('handles negative coordinates in domain/range', () => {
|
|
237
|
+
const props = {
|
|
238
|
+
...defaultProps,
|
|
239
|
+
graphProps: {
|
|
240
|
+
...defaultProps.graphProps,
|
|
241
|
+
domain: { min: -100, max: -10, step: 1, label: 'x', axisLabel: 'X' },
|
|
242
|
+
range: { min: -100, max: -10, step: 1, label: 'y', axisLabel: 'Y' },
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const { container } = render(<Bg {...props} />);
|
|
247
|
+
expect(container.querySelector('rect')).toBeTruthy();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
|
+
import { CoordinatesLabel, getLabelPosition } from '../coordinates-label';
|
|
4
|
+
|
|
5
|
+
describe('CoordinatesLabel', () => {
|
|
6
|
+
let defaultProps;
|
|
7
|
+
let graphProps;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
graphProps = {
|
|
11
|
+
domain: { min: -10, max: 10, step: 1, label: 'x', axisLabel: 'X' },
|
|
12
|
+
range: { min: -10, max: 10, step: 1, label: 'y', axisLabel: 'Y' },
|
|
13
|
+
scale: {
|
|
14
|
+
x: jest.fn((val) => (val + 10) * 20),
|
|
15
|
+
y: jest.fn((val) => (10 - val) * 20),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
defaultProps = {
|
|
20
|
+
x: 5,
|
|
21
|
+
y: 5,
|
|
22
|
+
graphProps,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('rendering', () => {
|
|
27
|
+
it('renders without crashing', () => {
|
|
28
|
+
const { container } = render(<CoordinatesLabel {...defaultProps} />);
|
|
29
|
+
expect(container).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('displays formatted coordinates', () => {
|
|
33
|
+
const { container } = render(<CoordinatesLabel {...defaultProps} />);
|
|
34
|
+
const input = container.querySelector('input');
|
|
35
|
+
|
|
36
|
+
expect(input.value).toBe('(5, 5)');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('rounds coordinates to 4 decimal places', () => {
|
|
40
|
+
const props = { ...defaultProps, x: 1.123456, y: 2.987654 };
|
|
41
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
42
|
+
const input = container.querySelector('input');
|
|
43
|
+
|
|
44
|
+
expect(input.value).toBe('(1.1235, 2.9877)');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('handles integer coordinates', () => {
|
|
48
|
+
const props = { ...defaultProps, x: 0, y: 0 };
|
|
49
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
50
|
+
const input = container.querySelector('input');
|
|
51
|
+
|
|
52
|
+
expect(input.value).toBe('(0, 0)');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('handles negative coordinates', () => {
|
|
56
|
+
const props = { ...defaultProps, x: -3, y: -7 };
|
|
57
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
58
|
+
const input = container.querySelector('input');
|
|
59
|
+
|
|
60
|
+
expect(input.value).toBe('(-3, -7)');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('renders as an input element', () => {
|
|
64
|
+
const { container } = render(<CoordinatesLabel {...defaultProps} />);
|
|
65
|
+
const input = container.querySelector('input');
|
|
66
|
+
|
|
67
|
+
expect(input).toBeTruthy();
|
|
68
|
+
expect(input.tagName).toBe('INPUT');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('applies correct styles', () => {
|
|
72
|
+
const { container } = render(<CoordinatesLabel {...defaultProps} />);
|
|
73
|
+
const wrapper = container.firstChild;
|
|
74
|
+
|
|
75
|
+
expect(wrapper).toHaveStyle({ position: 'absolute' });
|
|
76
|
+
expect(wrapper).toHaveStyle({ pointerEvents: 'auto' });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('getLabelPosition', () => {
|
|
81
|
+
it('positions label to the right by default', () => {
|
|
82
|
+
const position = getLabelPosition(graphProps, 0, 0, 60);
|
|
83
|
+
|
|
84
|
+
expect(position.left).toBeGreaterThan(graphProps.scale.x(0));
|
|
85
|
+
expect(position.top).toBeDefined();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('positions label to the left when near right edge', () => {
|
|
89
|
+
const x = 9; // Near max
|
|
90
|
+
const labelLength = 100;
|
|
91
|
+
const position = getLabelPosition(graphProps, x, 0, labelLength);
|
|
92
|
+
|
|
93
|
+
expect(position.left).toBeLessThan(graphProps.scale.x(x));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('adjusts top position for minimum y value', () => {
|
|
97
|
+
const position = getLabelPosition(graphProps, 0, -10, 60);
|
|
98
|
+
|
|
99
|
+
expect(position.top).toBe(graphProps.scale.y(-10) - 16);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('adjusts top position for maximum y value', () => {
|
|
103
|
+
const position = getLabelPosition(graphProps, 0, 10, 60);
|
|
104
|
+
|
|
105
|
+
expect(position.top).toBe(graphProps.scale.y(10) - 0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('centers label vertically for middle values', () => {
|
|
109
|
+
const position = getLabelPosition(graphProps, 0, 0, 60);
|
|
110
|
+
|
|
111
|
+
expect(position.top).toBe(graphProps.scale.y(0) - 8);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('applies left shift consistently', () => {
|
|
115
|
+
const leftShift = 10;
|
|
116
|
+
const labelLength = 60;
|
|
117
|
+
|
|
118
|
+
const rightPos = getLabelPosition(graphProps, 0, 0, labelLength);
|
|
119
|
+
expect(rightPos.left).toBe(graphProps.scale.x(0) + leftShift);
|
|
120
|
+
|
|
121
|
+
const leftPos = getLabelPosition(graphProps, 9, 0, labelLength);
|
|
122
|
+
expect(leftPos.left).toBe(graphProps.scale.x(9) - leftShift - labelLength);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('label width calculation', () => {
|
|
127
|
+
it('calculates width based on label length', () => {
|
|
128
|
+
const props = { ...defaultProps, x: 1, y: 2 };
|
|
129
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
130
|
+
const wrapper = container.firstChild;
|
|
131
|
+
|
|
132
|
+
const expectedWidth = 6 * 6;
|
|
133
|
+
expect(wrapper).toHaveStyle({ width: `${expectedWidth}px` });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('adjusts width for longer coordinates', () => {
|
|
137
|
+
const props = { ...defaultProps, x: -10.123, y: 10.456 };
|
|
138
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
139
|
+
const wrapper = container.firstChild;
|
|
140
|
+
|
|
141
|
+
const style = window.getComputedStyle(wrapper);
|
|
142
|
+
expect(parseInt(style.width)).toBeGreaterThan(42);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('edge cases', () => {
|
|
147
|
+
it('handles very small coordinates', () => {
|
|
148
|
+
const props = { ...defaultProps, x: 0.0001, y: 0.0002 };
|
|
149
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
150
|
+
const input = container.querySelector('input');
|
|
151
|
+
|
|
152
|
+
expect(input.value).toContain('(');
|
|
153
|
+
expect(input.value).toContain(')');
|
|
154
|
+
expect(input.value).toContain(',');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('handles very large coordinates', () => {
|
|
158
|
+
const props = { ...defaultProps, x: 999999, y: 888888 };
|
|
159
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
160
|
+
const input = container.querySelector('input');
|
|
161
|
+
|
|
162
|
+
expect(input.value).toBe('(999999, 888888)');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('handles zero coordinates', () => {
|
|
166
|
+
const props = { ...defaultProps, x: 0, y: 0 };
|
|
167
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
168
|
+
const input = container.querySelector('input');
|
|
169
|
+
|
|
170
|
+
expect(input.value).toBe('(0, 0)');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('handles coordinates at domain/range boundaries', () => {
|
|
174
|
+
const props = { ...defaultProps, x: 10, y: 10 };
|
|
175
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
176
|
+
const input = container.querySelector('input');
|
|
177
|
+
|
|
178
|
+
expect(input.value).toBe('(10, 10)');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('handles negative boundaries', () => {
|
|
182
|
+
const props = { ...defaultProps, x: -10, y: -10 };
|
|
183
|
+
const { container } = render(<CoordinatesLabel {...props} />);
|
|
184
|
+
const input = container.querySelector('input');
|
|
185
|
+
|
|
186
|
+
expect(input.value).toBe('(-10, -10)');
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('prop types and validation', () => {
|
|
191
|
+
it('accepts required props', () => {
|
|
192
|
+
expect(() => {
|
|
193
|
+
render(<CoordinatesLabel {...defaultProps} />);
|
|
194
|
+
}).not.toThrow();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('renders with missing optional props', () => {
|
|
198
|
+
const props = {
|
|
199
|
+
x: 1,
|
|
200
|
+
y: 2,
|
|
201
|
+
graphProps,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
expect(() => {
|
|
205
|
+
render(<CoordinatesLabel {...props} />);
|
|
206
|
+
}).not.toThrow();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('updates', () => {
|
|
211
|
+
it('updates when x coordinate changes', () => {
|
|
212
|
+
const { container, rerender } = render(<CoordinatesLabel {...defaultProps} />);
|
|
213
|
+
let input = container.querySelector('input');
|
|
214
|
+
expect(input.value).toBe('(5, 5)');
|
|
215
|
+
|
|
216
|
+
rerender(<CoordinatesLabel {...defaultProps} x={7} />);
|
|
217
|
+
input = container.querySelector('input');
|
|
218
|
+
expect(input.value).toBe('(7, 5)');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('updates when y coordinate changes', () => {
|
|
222
|
+
const { container, rerender } = render(<CoordinatesLabel {...defaultProps} />);
|
|
223
|
+
let input = container.querySelector('input');
|
|
224
|
+
expect(input.value).toBe('(5, 5)');
|
|
225
|
+
|
|
226
|
+
rerender(<CoordinatesLabel {...defaultProps} y={3} />);
|
|
227
|
+
input = container.querySelector('input');
|
|
228
|
+
expect(input.value).toBe('(5, 3)');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('updates position when coordinates change', () => {
|
|
232
|
+
const { container, rerender } = render(<CoordinatesLabel {...defaultProps} />);
|
|
233
|
+
const initialStyle = window.getComputedStyle(container.firstChild);
|
|
234
|
+
const initialLeft = initialStyle.left;
|
|
235
|
+
|
|
236
|
+
rerender(<CoordinatesLabel {...defaultProps} x={8} />);
|
|
237
|
+
const newStyle = window.getComputedStyle(container.firstChild);
|
|
238
|
+
const newLeft = newStyle.left;
|
|
239
|
+
|
|
240
|
+
expect(newLeft).not.toBe(initialLeft);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
filterByValidToolTypes,
|
|
5
|
+
filterByVisibleToolTypes,
|
|
6
|
+
getAvailableTool,
|
|
7
|
+
GraphWithControls,
|
|
8
|
+
setToolbarAvailability,
|
|
9
|
+
toolIsAvailable,
|
|
10
|
+
} from '../graph-with-controls';
|
|
11
|
+
import { allTools, line as lineTool, toolsArr } from '../tools';
|
|
3
12
|
|
|
4
13
|
// Mock DragProvider to avoid @dnd-kit React version conflicts
|
|
5
14
|
jest.mock('@pie-lib/drag', () => ({
|
|
@@ -47,16 +56,6 @@ jest.mock('@dnd-kit/sortable', () => ({
|
|
|
47
56
|
}),
|
|
48
57
|
}));
|
|
49
58
|
|
|
50
|
-
import {
|
|
51
|
-
GraphWithControls,
|
|
52
|
-
setToolbarAvailability,
|
|
53
|
-
toolIsAvailable,
|
|
54
|
-
getAvailableTool,
|
|
55
|
-
filterByValidToolTypes,
|
|
56
|
-
filterByVisibleToolTypes,
|
|
57
|
-
} from '../graph-with-controls';
|
|
58
|
-
import { toolsArr, allTools, line as lineTool } from '../tools';
|
|
59
|
-
|
|
60
59
|
const line = {
|
|
61
60
|
type: 'line',
|
|
62
61
|
from: { x: 0, y: 0 },
|