@pie-lib/charting 7.1.0-beta.8 → 7.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 (31) hide show
  1. package/package.json +2 -2
  2. package/src/__tests__/actions-button.test.jsx +0 -280
  3. package/src/__tests__/axes.test.jsx +0 -667
  4. package/src/__tests__/chart-setup.test.jsx +0 -532
  5. package/src/__tests__/chart-type.test.jsx +0 -23
  6. package/src/__tests__/chart.test.jsx +0 -86
  7. package/src/__tests__/grid.test.jsx +0 -37
  8. package/src/__tests__/key-legend.test.jsx +0 -223
  9. package/src/__tests__/mark-label.test.jsx +0 -33
  10. package/src/__tests__/tool-menu.test.jsx +0 -522
  11. package/src/__tests__/utils.js +0 -36
  12. package/src/__tests__/utils.test.js +0 -100
  13. package/src/bars/__tests__/bar.test.jsx +0 -45
  14. package/src/bars/__tests__/histogram.test.jsx +0 -45
  15. package/src/bars/__tests__/utils.js +0 -30
  16. package/src/bars/common/__tests__/bars.test.jsx +0 -68
  17. package/src/bars/common/__tests__/utils.js +0 -30
  18. package/src/common/__tests__/correctness-indicators.test.jsx +0 -720
  19. package/src/common/__tests__/drag-handle.test.jsx +0 -58
  20. package/src/common/__tests__/utils.js +0 -30
  21. package/src/line/__tests__/line-cross.test.jsx +0 -463
  22. package/src/line/__tests__/line-dot.test.jsx +0 -41
  23. package/src/line/__tests__/utils.js +0 -36
  24. package/src/line/common/__tests__/drag-handle.test.jsx +0 -62
  25. package/src/line/common/__tests__/line.test.jsx +0 -79
  26. package/src/line/common/__tests__/utils.js +0 -30
  27. package/src/plot/__tests__/dot.test.jsx +0 -344
  28. package/src/plot/__tests__/line.test.jsx +0 -375
  29. package/src/plot/__tests__/utils.js +0 -30
  30. package/src/plot/common/__tests__/plot.test.jsx +0 -69
  31. package/src/plot/common/__tests__/utils.js +0 -30
@@ -1,79 +0,0 @@
1
- import { render } from '@testing-library/react';
2
- import React from 'react';
3
- import Line, { RawLine } from '../line';
4
- import { graphProps } from './utils';
5
-
6
- describe('Line', () => {
7
- const xBand = () => {};
8
- xBand.bandwidth = () => {};
9
- const onChange = jest.fn();
10
-
11
- const renderComponent = (extras) => {
12
- const defaults = {
13
- classes: {},
14
- className: 'className',
15
- graphProps: graphProps(),
16
- xBand,
17
- onChange,
18
- data: [{ value: 0, label: '0' }],
19
- };
20
- const props = { ...defaults, ...extras };
21
- return render(<Line {...props} />);
22
- };
23
-
24
- describe('rendering', () => {
25
- it('renders without crashing', () => {
26
- const { container } = renderComponent();
27
- expect(container.firstChild).toBeInTheDocument();
28
- });
29
- });
30
-
31
- describe('functionality', () => {
32
- it('calls onChange when line changes', () => {
33
- const { container } = renderComponent();
34
- // Testing changeLine functionality would require user interaction
35
- // with drag handles on the line chart
36
- expect(container.firstChild).toBeInTheDocument();
37
- });
38
- });
39
- });
40
-
41
- describe('RawLine', () => {
42
- const xBand = () => {};
43
- xBand.bandwidth = () => {};
44
- const onChange = jest.fn();
45
-
46
- const renderComponent = (extras) => {
47
- const defaults = {
48
- classes: {},
49
- className: 'className',
50
- graphProps: graphProps(),
51
- xBand,
52
- onChange,
53
- data: [
54
- { label: 'A', value: 0 },
55
- { label: 'B', value: 1 },
56
- ],
57
- label: 'label',
58
- CustomBarElement: () => <div />,
59
- };
60
- const props = { ...defaults, ...extras };
61
- return render(<RawLine {...props} />);
62
- };
63
-
64
- describe('rendering', () => {
65
- it('renders without crashing', () => {
66
- const { container } = renderComponent();
67
- expect(container.firstChild).toBeInTheDocument();
68
- });
69
- });
70
-
71
- describe('functionality', () => {
72
- it('handles drag operations', () => {
73
- const { container } = renderComponent();
74
- // Testing dragStop functionality would require user interaction
75
- // with drag handles on the line
76
- expect(container.firstChild).toBeInTheDocument();
77
- });
78
- });
79
- });
@@ -1,30 +0,0 @@
1
- export const scaleMock = () => {
2
- const fn = jest.fn((n) => n);
3
- fn.invert = jest.fn((n) => n);
4
- return fn;
5
- };
6
-
7
- export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
8
- scale: {
9
- x: scaleMock(),
10
- y: scaleMock(),
11
- },
12
- snap: {
13
- x: jest.fn((n) => n),
14
- y: jest.fn((n) => n),
15
- },
16
- domain: {
17
- min: dmin,
18
- max: dmax,
19
- step: 1,
20
- },
21
- range: {
22
- min: rmin,
23
- max: rmax,
24
- step: 1,
25
- },
26
- size: {
27
- width: 400,
28
- height: 400,
29
- },
30
- });
@@ -1,344 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@pie-lib/test-utils';
3
- import { createTheme, ThemeProvider } from '@mui/material/styles';
4
- import Dot, { DotPlot } from '../dot';
5
- import { graphProps } from './utils';
6
-
7
- jest.mock('@mui/icons-material/Check', () => {
8
- return function Check(props) {
9
- return <div data-testid="check-icon" {...props} />;
10
- };
11
- });
12
-
13
- jest.mock('@visx/shape', () => ({
14
- Circle: ({ cx, cy, r, ...rest }) => <circle cx={cx} cy={cy} r={r} {...rest} />,
15
- }));
16
-
17
- let theme;
18
-
19
- beforeAll(() => {
20
- theme = createTheme();
21
- });
22
-
23
- describe('DotPlot', () => {
24
- const renderComponent = (extras) => {
25
- const defaults = {
26
- classes: {},
27
- className: 'className',
28
- graphProps: graphProps(),
29
- xBand: () => {
30
- return {
31
- bandwidth: () => {},
32
- };
33
- },
34
- };
35
- const props = { ...defaults, ...extras };
36
- return render(
37
- <ThemeProvider theme={theme}>
38
- <svg>
39
- <DotPlot {...props} />
40
- </svg>
41
- </ThemeProvider>,
42
- );
43
- };
44
-
45
- describe('rendering', () => {
46
- it('renders dot plot', () => {
47
- const { container } = renderComponent();
48
- expect(container.firstChild).toBeInTheDocument();
49
- });
50
-
51
- it('renders without graphProps', () => {
52
- const { container } = renderComponent({ graphProps: undefined });
53
- expect(container.firstChild).toBeInTheDocument();
54
- });
55
-
56
- it('renders with data array', () => {
57
- const data = [
58
- { value: 1, label: 'A' },
59
- { value: 2, label: 'B' },
60
- { value: 3, label: 'C' },
61
- ];
62
- const { container } = renderComponent({ data });
63
- expect(container.firstChild).toBeInTheDocument();
64
- });
65
-
66
- it('renders with empty data array', () => {
67
- const { container } = renderComponent({ data: [] });
68
- expect(container.firstChild).toBeInTheDocument();
69
- });
70
-
71
- it('renders with null data', () => {
72
- const { container } = renderComponent({ data: null });
73
- expect(container.firstChild).toBeInTheDocument();
74
- });
75
-
76
- it('renders with undefined data', () => {
77
- const { container } = renderComponent({ data: undefined });
78
- expect(container.firstChild).toBeInTheDocument();
79
- });
80
-
81
- it('renders with custom className', () => {
82
- const { container } = renderComponent({ className: 'custom-dot-plot' });
83
- expect(container.firstChild).toBeInTheDocument();
84
- });
85
-
86
- it('renders with onChange handler', () => {
87
- const onChange = jest.fn();
88
- const { container } = renderComponent({ onChange });
89
- expect(container.firstChild).toBeInTheDocument();
90
- });
91
-
92
- it('renders in defineChart mode', () => {
93
- const { container } = renderComponent({ defineChart: true });
94
- expect(container.firstChild).toBeInTheDocument();
95
- });
96
-
97
- it('renders with correctData', () => {
98
- const data = [{ value: 2, label: 'A' }];
99
- const correctData = [{ value: 3, label: 'A' }];
100
- const { container } = renderComponent({ data, correctData });
101
- expect(container.firstChild).toBeInTheDocument();
102
- });
103
- });
104
-
105
- describe('graphProps handling', () => {
106
- it('handles graphProps with missing scale', () => {
107
- const props = graphProps();
108
- delete props.scale;
109
- const { container } = renderComponent({ graphProps: props });
110
- expect(container.firstChild).toBeInTheDocument();
111
- });
112
-
113
- it('handles graphProps with missing size', () => {
114
- const props = graphProps();
115
- delete props.size;
116
- const { container } = renderComponent({ graphProps: props });
117
- expect(container.firstChild).toBeInTheDocument();
118
- });
119
-
120
- it('handles graphProps with empty scale object', () => {
121
- const props = graphProps();
122
- props.scale = {};
123
- const { container } = renderComponent({ graphProps: props });
124
- expect(container.firstChild).toBeInTheDocument();
125
- });
126
-
127
- it('handles graphProps with empty size object', () => {
128
- const props = graphProps();
129
- props.size = {};
130
- const { container } = renderComponent({ graphProps: props });
131
- expect(container.firstChild).toBeInTheDocument();
132
- });
133
- });
134
-
135
- describe('data variations', () => {
136
- it('renders with single data point', () => {
137
- const data = [{ value: 1, label: 'A' }];
138
- const { container } = renderComponent({ data });
139
- expect(container.firstChild).toBeInTheDocument();
140
- });
141
-
142
- it('renders with multiple data points', () => {
143
- const data = [
144
- { value: 1, label: 'A' },
145
- { value: 2, label: 'B' },
146
- { value: 3, label: 'C' },
147
- { value: 4, label: 'D' },
148
- ];
149
- const { container } = renderComponent({ data });
150
- expect(container.firstChild).toBeInTheDocument();
151
- });
152
-
153
- it('renders with zero values', () => {
154
- const data = [
155
- { value: 0, label: 'A' },
156
- { value: 0, label: 'B' },
157
- ];
158
- const { container } = renderComponent({ data });
159
- expect(container.firstChild).toBeInTheDocument();
160
- });
161
-
162
- it('renders with mixed values', () => {
163
- const data = [
164
- { value: 0, label: 'A' },
165
- { value: 5, label: 'B' },
166
- { value: 1, label: 'C' },
167
- ];
168
- const { container } = renderComponent({ data });
169
- expect(container.firstChild).toBeInTheDocument();
170
- });
171
-
172
- it('renders with large values', () => {
173
- const data = [
174
- { value: 100, label: 'A' },
175
- { value: 200, label: 'B' },
176
- ];
177
- const { container } = renderComponent({ data });
178
- expect(container.firstChild).toBeInTheDocument();
179
- });
180
-
181
- it('renders with correctness data', () => {
182
- const data = [
183
- { value: 2, label: 'A', correctness: { value: 'correct', label: 'Correct' } },
184
- { value: 3, label: 'B', correctness: { value: 'correct', label: 'Correct' } },
185
- ];
186
- const { container } = renderComponent({ data });
187
- expect(container.firstChild).toBeInTheDocument();
188
- });
189
-
190
- it('renders with incorrect correctness and correctData', () => {
191
- const data = [
192
- { value: 2, label: 'A', correctness: { value: 'incorrect', label: 'Incorrect' } },
193
- { value: 3, label: 'B', correctness: { value: 'incorrect', label: 'Incorrect' } },
194
- ];
195
- const correctData = [
196
- { value: 3, label: 'A' },
197
- { value: 4, label: 'B' },
198
- ];
199
- const { container } = renderComponent({ data, correctData });
200
- expect(container.firstChild).toBeInTheDocument();
201
- });
202
-
203
- it('renders with interactive data points', () => {
204
- const data = [
205
- { value: 2, label: 'A', interactive: true },
206
- { value: 3, label: 'B', interactive: false },
207
- ];
208
- const { container } = renderComponent({ data });
209
- expect(container.firstChild).toBeInTheDocument();
210
- });
211
- });
212
-
213
- describe('callbacks', () => {
214
- it('passes onChange handler to Plot component', () => {
215
- const onChange = jest.fn();
216
- const data = [{ value: 1, label: 'A' }];
217
- const { container } = renderComponent({ data, onChange });
218
- expect(container.firstChild).toBeInTheDocument();
219
- });
220
-
221
- it('handles onChangeCategory callback', () => {
222
- const onChangeCategory = jest.fn();
223
- const data = [{ value: 1, label: 'A' }];
224
- const { container } = renderComponent({ data, onChangeCategory });
225
- expect(container.firstChild).toBeInTheDocument();
226
- });
227
- });
228
-
229
- describe('component', () => {
230
- it('returns correct chart object', () => {
231
- const chart = Dot();
232
-
233
- expect(chart).toEqual({
234
- type: 'dotPlot',
235
- Component: DotPlot,
236
- name: 'Dot Plot',
237
- });
238
- });
239
-
240
- it('returns object with Component that can be rendered', () => {
241
- const chart = Dot();
242
- const { Component } = chart;
243
-
244
- const { container } = render(<Component graphProps={graphProps()} />);
245
- expect(container.firstChild).toBeInTheDocument();
246
- });
247
- });
248
- });
249
-
250
- describe('CustomBarElement (Dot)', () => {
251
- const mockScale = {
252
- y: jest.fn((n) => n * 10),
253
- };
254
-
255
- it('renders a circle element', () => {
256
- const data = [{ value: 1, label: 'A' }];
257
- const { container } = render(
258
- <ThemeProvider theme={theme}>
259
- <svg>
260
- <DotPlot data={data} graphProps={graphProps()} />
261
- </svg>
262
- </ThemeProvider>,
263
- );
264
- expect(container).toBeInTheDocument();
265
- });
266
-
267
- it('renders with dottedOverline prop', () => {
268
- const data = [{ value: 2, label: 'A', correctness: { value: 'incorrect' } }];
269
- const correctData = [{ value: 3, label: 'A' }];
270
- const { container } = render(
271
- <ThemeProvider theme={theme}>
272
- <svg>
273
- <DotPlot data={data} graphProps={graphProps()} correctData={correctData} />
274
- </svg>
275
- </ThemeProvider>,
276
- );
277
- expect(container).toBeInTheDocument();
278
- });
279
-
280
- it('renders without dottedOverline prop', () => {
281
- const data = [{ value: 2, label: 'A' }];
282
- const { container } = render(
283
- <ThemeProvider theme={theme}>
284
- <svg>
285
- <DotPlot data={data} graphProps={graphProps()} />
286
- </svg>
287
- </ThemeProvider>,
288
- );
289
- expect(container).toBeInTheDocument();
290
- });
291
-
292
- it('calculates correct circle position', () => {
293
- const data = [{ value: 3, label: 'A' }];
294
- const { container } = render(
295
- <ThemeProvider theme={theme}>
296
- <svg>
297
- <DotPlot data={data} graphProps={graphProps()} />
298
- </svg>
299
- </ThemeProvider>,
300
- );
301
- expect(container).toBeInTheDocument();
302
- });
303
-
304
- it('handles zero pointDiameter', () => {
305
- const props = graphProps();
306
- props.size = { width: 0, height: 0 };
307
- const data = [{ value: 1, label: 'A' }];
308
- const { container } = render(
309
- <ThemeProvider theme={theme}>
310
- <svg>
311
- <DotPlot data={data} graphProps={props} />
312
- </svg>
313
- </ThemeProvider>,
314
- );
315
- expect(container).toBeInTheDocument();
316
- });
317
-
318
- it('handles large pointDiameter values', () => {
319
- const props = graphProps();
320
- props.size = { width: 1000, height: 1000 };
321
- const data = [{ value: 1, label: 'A' }];
322
- const { container } = render(
323
- <ThemeProvider theme={theme}>
324
- <svg>
325
- <DotPlot data={data} graphProps={props} />
326
- </svg>
327
- </ThemeProvider>,
328
- );
329
- expect(container).toBeInTheDocument();
330
- });
331
-
332
- it('renders dotted circle with correct styling when dottedOverline is true', () => {
333
- const data = [{ value: 2, label: 'A', correctness: { value: 'incorrect' } }];
334
- const correctData = [{ value: 3, label: 'A' }];
335
- const { container } = render(
336
- <ThemeProvider theme={theme}>
337
- <svg>
338
- <DotPlot data={data} graphProps={graphProps()} correctData={correctData} />
339
- </svg>
340
- </ThemeProvider>,
341
- );
342
- expect(container).toBeInTheDocument();
343
- });
344
- });