@pie-lib/charting 5.36.3-next.2 → 5.36.4-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/CHANGELOG.md +17 -96
- package/lib/__tests__/axes.test.js +129 -0
- package/lib/__tests__/chart-setup.test.js +57 -0
- package/lib/__tests__/chart-type.test.js +25 -0
- package/lib/__tests__/chart.test.js +103 -0
- package/lib/__tests__/grid.test.js +39 -0
- package/lib/__tests__/mark-label.test.js +46 -0
- package/lib/__tests__/utils.js +56 -0
- package/lib/__tests__/utils.test.js +186 -0
- package/lib/actions-button.js +61 -91
- package/lib/actions-button.js.map +1 -1
- package/lib/axes.js +163 -239
- package/lib/axes.js.map +1 -1
- package/lib/bars/__tests__/bar.test.js +53 -0
- package/lib/bars/__tests__/histogram.test.js +53 -0
- package/lib/bars/__tests__/utils.js +50 -0
- package/lib/bars/bar.js +14 -42
- package/lib/bars/bar.js.map +1 -1
- package/lib/bars/common/__tests__/bars.test.js +76 -0
- package/lib/bars/common/__tests__/utils.js +50 -0
- package/lib/bars/common/bars.js +62 -138
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/bars/common/correct-check-icon.js +6 -7
- package/lib/bars/common/correct-check-icon.js.map +1 -1
- package/lib/bars/histogram.js +14 -42
- package/lib/bars/histogram.js.map +1 -1
- package/lib/chart-setup.js +120 -196
- package/lib/chart-setup.js.map +1 -1
- package/lib/chart-type.js +53 -44
- package/lib/chart-type.js.map +1 -1
- package/lib/chart-types.js +2 -11
- package/lib/chart-types.js.map +1 -1
- package/lib/chart.js +74 -152
- package/lib/chart.js.map +1 -1
- package/lib/common/__tests__/drag-handle.test.js +74 -0
- package/lib/common/__tests__/utils.js +50 -0
- package/lib/common/correctness-indicators.js +110 -53
- package/lib/common/correctness-indicators.js.map +1 -1
- package/lib/common/drag-handle.js +66 -109
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/drag-icon.js +13 -13
- package/lib/common/drag-icon.js.map +1 -1
- package/lib/common/styles.js +7 -25
- package/lib/common/styles.js.map +1 -1
- package/lib/grid.js +44 -84
- package/lib/grid.js.map +1 -1
- package/lib/index.js +1 -7
- package/lib/index.js.map +1 -1
- package/lib/key-legend.js +64 -88
- package/lib/key-legend.js.map +1 -1
- package/lib/line/__tests__/line-cross.test.js +47 -0
- package/lib/line/__tests__/line-dot.test.js +47 -0
- package/lib/line/__tests__/utils.js +56 -0
- package/lib/line/common/__tests__/drag-handle.test.js +74 -0
- package/lib/line/common/__tests__/line.test.js +92 -0
- package/lib/line/common/__tests__/utils.js +50 -0
- package/lib/line/common/drag-handle.js +73 -101
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/common/line.js +51 -97
- package/lib/line/common/line.js.map +1 -1
- package/lib/line/line-cross.js +80 -90
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js +59 -77
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js +85 -120
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/__tests__/dot.test.js +53 -0
- package/lib/plot/__tests__/line.test.js +53 -0
- package/lib/plot/__tests__/utils.js +50 -0
- package/lib/plot/common/__tests__/plot.test.js +79 -0
- package/lib/plot/common/__tests__/utils.js +50 -0
- package/lib/plot/common/plot.js +91 -149
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js +33 -59
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js +40 -65
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js +48 -84
- package/lib/tool-menu.js.map +1 -1
- package/lib/utils.js +32 -87
- package/lib/utils.js.map +1 -1
- package/package.json +22 -24
- package/src/__tests__/axes.test.jsx +85 -100
- package/src/__tests__/chart-type.test.jsx +5 -11
- package/src/__tests__/chart.test.jsx +41 -50
- package/src/__tests__/grid.test.jsx +23 -11
- package/src/__tests__/mark-label.test.jsx +13 -11
- package/src/__tests__/utils.js +8 -2
- package/src/actions-button.jsx +44 -39
- package/src/axes.jsx +67 -81
- package/src/bars/__tests__/bar.test.jsx +19 -11
- package/src/bars/__tests__/histogram.test.jsx +19 -12
- package/src/bars/common/__tests__/bars.test.jsx +23 -24
- package/src/bars/common/bars.jsx +42 -69
- package/src/bars/common/correct-check-icon.jsx +5 -0
- package/src/chart-setup.jsx +75 -88
- package/src/chart-type.js +45 -22
- package/src/chart.jsx +19 -34
- package/src/common/__tests__/drag-handle.test.jsx +16 -45
- package/src/common/correctness-indicators.jsx +91 -13
- package/src/common/drag-handle.jsx +44 -64
- package/src/common/drag-icon.jsx +9 -2
- package/src/common/styles.js +1 -1
- package/src/grid.jsx +10 -14
- package/src/key-legend.jsx +62 -60
- package/src/line/__tests__/line-cross.test.jsx +16 -13
- package/src/line/__tests__/line-dot.test.jsx +16 -13
- package/src/line/__tests__/utils.js +8 -2
- package/src/line/common/__tests__/drag-handle.test.jsx +20 -45
- package/src/line/common/__tests__/line.test.jsx +27 -30
- package/src/line/common/drag-handle.jsx +61 -55
- package/src/line/common/line.jsx +21 -11
- package/src/line/line-cross.js +39 -14
- package/src/line/line-dot.js +27 -32
- package/src/mark-label.jsx +51 -47
- package/src/plot/__tests__/dot.test.jsx +19 -12
- package/src/plot/__tests__/line.test.jsx +19 -12
- package/src/plot/common/__tests__/plot.test.jsx +23 -24
- package/src/plot/common/plot.jsx +29 -24
- package/src/plot/dot.js +11 -4
- package/src/plot/line.js +16 -8
- package/src/tool-menu.jsx +26 -30
- package/src/utils.js +13 -9
- package/esm/index.css +0 -847
- package/esm/index.js +0 -231130
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/axes.test.jsx.snap +0 -569
- package/src/__tests__/__snapshots__/chart-type.test.jsx.snap +0 -14
- package/src/__tests__/__snapshots__/chart.test.jsx.snap +0 -595
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -72
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -73
- package/src/bars/__tests__/__snapshots__/bar.test.jsx.snap +0 -43
- package/src/bars/__tests__/__snapshots__/histogram.test.jsx.snap +0 -45
- package/src/bars/common/__tests__/__snapshots__/bars.test.jsx.snap +0 -110
- package/src/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +0 -48
- package/src/line/__tests__/__snapshots__/line-cross.test.jsx.snap +0 -45
- package/src/line/__tests__/__snapshots__/line-dot.test.jsx.snap +0 -45
- package/src/line/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +0 -49
- package/src/line/common/__tests__/__snapshots__/line.test.jsx.snap +0 -143
- package/src/plot/__tests__/__snapshots__/dot.test.jsx.snap +0 -45
- package/src/plot/__tests__/__snapshots__/line.test.jsx.snap +0 -45
- package/src/plot/common/__tests__/__snapshots__/plot.test.jsx.snap +0 -97
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "5.36.
|
|
6
|
+
"version": "5.36.4-next.0",
|
|
7
7
|
"description": "charting",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -17,39 +17,37 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@emotion/react": "^11.14.0",
|
|
21
|
+
"@emotion/style": "^0.8.0",
|
|
20
22
|
"@mapbox/point-geometry": "^0.1.0",
|
|
21
|
-
"@material
|
|
22
|
-
"@
|
|
23
|
-
"@pie-lib/
|
|
24
|
-
"@pie-lib/
|
|
25
|
-
"@pie-lib/
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
23
|
+
"@mui/icons-material": "^7.3.4",
|
|
24
|
+
"@mui/material": "^7.3.4",
|
|
25
|
+
"@pie-lib/math-rendering": "3.22.3-next.0",
|
|
26
|
+
"@pie-lib/plot": "2.27.4-next.0",
|
|
27
|
+
"@pie-lib/render-ui": "4.35.4-next.0",
|
|
28
|
+
"@pie-lib/translator": "2.23.3-next.0",
|
|
29
|
+
"@visx/axis": "^3.0.0",
|
|
30
|
+
"@visx/event": "^3.0.0",
|
|
31
|
+
"@visx/grid": "^3.0.0",
|
|
32
|
+
"@visx/group": "^3.0.0",
|
|
33
|
+
"@visx/point": "^3.0.0",
|
|
34
|
+
"@visx/scale": "^3.0.0",
|
|
35
|
+
"@visx/shape": "^3.0.0",
|
|
33
36
|
"classnames": "^2.2.6",
|
|
34
37
|
"d3-scale": "^2.1.2",
|
|
35
38
|
"d3-selection": "^1.3.2",
|
|
36
39
|
"debug": "^4.1.1",
|
|
37
40
|
"invariant": "^2.2.4",
|
|
38
41
|
"lodash": "^4.17.11",
|
|
39
|
-
"react": "^
|
|
42
|
+
"react": "^18.2.0",
|
|
40
43
|
"react-draggable": "^3.1.1",
|
|
41
44
|
"react-input-autosize": "^2.2.1"
|
|
42
45
|
},
|
|
43
46
|
"peerDependencies": {
|
|
44
|
-
"react": "^
|
|
47
|
+
"react": "^18.2.0"
|
|
45
48
|
},
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"import": "./src/index.js",
|
|
51
|
-
"default": "./lib/index.js"
|
|
52
|
-
},
|
|
53
|
-
"./esm": "./esm/index.js"
|
|
54
|
-
}
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@pie-lib/test-utils": "0.22.3-next.0"
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "ad47e833acbaecca94eab8df2aee2a1ee9d90516"
|
|
55
53
|
}
|
|
@@ -1,141 +1,126 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
4
|
import ChartAxes, { TickComponent, RawChartAxes } from '../axes';
|
|
4
|
-
import { graphProps } from './utils';
|
|
5
|
+
import { graphProps, createBandScale } from './utils';
|
|
6
|
+
|
|
7
|
+
const theme = createTheme();
|
|
5
8
|
|
|
6
9
|
describe('ChartAxes', () => {
|
|
7
|
-
const
|
|
10
|
+
const renderComponent = (extras) => {
|
|
8
11
|
const defaults = {
|
|
9
12
|
classes: {},
|
|
10
13
|
className: 'className',
|
|
11
14
|
graphProps: graphProps(),
|
|
12
|
-
xBand:
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
+
xBand: createBandScale(['a', 'b', 'c'], [0, 400]),
|
|
16
|
+
categories: [],
|
|
15
17
|
};
|
|
16
18
|
const props = { ...defaults, ...extras };
|
|
17
|
-
return
|
|
19
|
+
return render(
|
|
20
|
+
<ThemeProvider theme={theme}>
|
|
21
|
+
<svg>
|
|
22
|
+
<ChartAxes {...props} />
|
|
23
|
+
</svg>
|
|
24
|
+
</ThemeProvider>
|
|
25
|
+
);
|
|
18
26
|
};
|
|
19
27
|
|
|
20
|
-
describe('
|
|
21
|
-
it('renders', () =>
|
|
28
|
+
describe('rendering', () => {
|
|
29
|
+
it('renders axes container', () => {
|
|
30
|
+
const { container } = renderComponent();
|
|
31
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renders SVG with axes group', () => {
|
|
35
|
+
const { container} = renderComponent();
|
|
36
|
+
const svg = container.querySelector('svg');
|
|
37
|
+
expect(svg).toBeInTheDocument();
|
|
38
|
+
// Component renders StyledAxesGroup which is a <g> element
|
|
39
|
+
const axesGroup = container.querySelector('g');
|
|
40
|
+
expect(axesGroup).toBeInTheDocument();
|
|
41
|
+
});
|
|
22
42
|
});
|
|
23
43
|
});
|
|
24
44
|
|
|
25
45
|
describe('RawChartAxes', () => {
|
|
26
|
-
const
|
|
46
|
+
const renderComponent = (extras) => {
|
|
27
47
|
const defaults = {
|
|
28
48
|
classes: {},
|
|
29
49
|
className: 'className',
|
|
30
50
|
graphProps: graphProps(),
|
|
31
|
-
xBand:
|
|
32
|
-
bandwidth: () => {},
|
|
33
|
-
rangeRound: () => {},
|
|
34
|
-
},
|
|
51
|
+
xBand: createBandScale(['a', 'b', 'c'], [0, 400]),
|
|
35
52
|
categories: [],
|
|
36
53
|
};
|
|
37
54
|
const props = { ...defaults, ...extras };
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
it('renders if categories are not defined', () => expect(wrapper({ categories: undefined })).toMatchSnapshot());
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('splitText method', () => {
|
|
51
|
-
const wrapper = (extras) => {
|
|
52
|
-
const xBand = jest.fn();
|
|
53
|
-
xBand.bandwidth = jest.fn();
|
|
54
|
-
|
|
55
|
-
const defaults = {
|
|
56
|
-
graphProps: graphProps(),
|
|
57
|
-
xBand,
|
|
58
|
-
};
|
|
59
|
-
const props = { ...defaults, ...extras };
|
|
60
|
-
return shallow(<TickComponent {...props} />);
|
|
55
|
+
return render(
|
|
56
|
+
<ThemeProvider theme={theme}>
|
|
57
|
+
<svg>
|
|
58
|
+
<RawChartAxes {...props} />
|
|
59
|
+
</svg>
|
|
60
|
+
</ThemeProvider>
|
|
61
|
+
);
|
|
61
62
|
};
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('returns an array with a single string when the input is less than the specified length', () => {
|
|
71
|
-
const w = wrapper();
|
|
72
|
-
const input = 'Short text';
|
|
73
|
-
const output = w.instance().splitText(input, 20);
|
|
74
|
-
expect(output).toEqual(['Short text']);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('splits a string into chunks of exact length when no spaces are present', () => {
|
|
78
|
-
const w = wrapper();
|
|
79
|
-
const input = 'ThisisateststringforsplitTextfunction';
|
|
80
|
-
const output = w.instance().splitText(input, 10);
|
|
81
|
-
expect(output).toEqual(['Thisisates', 'tstringfor', 'splitTextf', 'unction']);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('returns an empty array when the input is an empty string', () => {
|
|
85
|
-
const w = wrapper();
|
|
86
|
-
const input = '';
|
|
87
|
-
const output = w.instance().splitText(input, 20);
|
|
88
|
-
expect(output).toEqual([]);
|
|
89
|
-
});
|
|
64
|
+
describe('rendering', () => {
|
|
65
|
+
it('renders raw axes container', () => {
|
|
66
|
+
const { container } = renderComponent();
|
|
67
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
68
|
+
});
|
|
90
69
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
it('renders SVG with axes group', () => {
|
|
71
|
+
const { container } = renderComponent();
|
|
72
|
+
const svg = container.querySelector('svg');
|
|
73
|
+
expect(svg).toBeInTheDocument();
|
|
74
|
+
// Component renders StyledAxesGroup which is a <g> element
|
|
75
|
+
const axesGroup = container.querySelector('g');
|
|
76
|
+
expect(axesGroup).toBeInTheDocument();
|
|
77
|
+
});
|
|
96
78
|
});
|
|
97
79
|
});
|
|
98
80
|
|
|
99
81
|
describe('TickComponent', () => {
|
|
100
|
-
const
|
|
101
|
-
const xBand = jest.fn();
|
|
102
|
-
xBand.bandwidth = jest.fn();
|
|
103
|
-
|
|
82
|
+
const renderComponent = (extras) => {
|
|
104
83
|
const defaults = {
|
|
105
84
|
graphProps: graphProps(),
|
|
106
|
-
xBand,
|
|
85
|
+
xBand: createBandScale(['a', 'b', 'c'], [0, 400]),
|
|
86
|
+
categories: [{ value: 1, label: 'test', editable: false, interactive: false }],
|
|
87
|
+
formattedValue: '0-test',
|
|
88
|
+
bandWidth: 100,
|
|
89
|
+
barWidth: 100,
|
|
90
|
+
x: 50,
|
|
91
|
+
y: 50,
|
|
107
92
|
};
|
|
108
93
|
const props = { ...defaults, ...extras };
|
|
109
|
-
return
|
|
94
|
+
return render(
|
|
95
|
+
<ThemeProvider theme={theme}>
|
|
96
|
+
<svg>
|
|
97
|
+
<TickComponent {...props} />
|
|
98
|
+
</svg>
|
|
99
|
+
</ThemeProvider>
|
|
100
|
+
);
|
|
110
101
|
};
|
|
111
102
|
|
|
112
|
-
describe('
|
|
113
|
-
it('renders', () =>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
expect(
|
|
119
|
-
wrapper({
|
|
120
|
-
formattedValue: '0-test',
|
|
121
|
-
categories: [{ value: 1, label: 'test' }],
|
|
122
|
-
}),
|
|
123
|
-
).toMatchSnapshot());
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe('logic', () => {
|
|
127
|
-
const onChange = jest.fn();
|
|
128
|
-
const onChangeCategory = jest.fn();
|
|
129
|
-
const w = wrapper({
|
|
130
|
-
formattedValue: '0-test',
|
|
131
|
-
categories: [{ value: 1, label: 'test' }],
|
|
132
|
-
onChange,
|
|
133
|
-
onChangeCategory,
|
|
103
|
+
describe('rendering', () => {
|
|
104
|
+
it('renders tick component', () => {
|
|
105
|
+
const { container } = renderComponent();
|
|
106
|
+
const svg = container.querySelector('svg');
|
|
107
|
+
expect(svg).toBeInTheDocument();
|
|
108
|
+
// TickComponent renders a <g> element
|
|
109
|
+
expect(container.querySelector('g')).toBeInTheDocument();
|
|
134
110
|
});
|
|
135
111
|
|
|
136
|
-
it('
|
|
137
|
-
|
|
138
|
-
|
|
112
|
+
it('renders with categories', () => {
|
|
113
|
+
const { container } = renderComponent({
|
|
114
|
+
formattedValue: '0-test',
|
|
115
|
+
categories: [{ value: 1, label: 'test', editable: false, interactive: false }],
|
|
116
|
+
});
|
|
117
|
+
const svg = container.querySelector('svg');
|
|
118
|
+
expect(svg).toBeInTheDocument();
|
|
119
|
+
expect(container.querySelector('g')).toBeInTheDocument();
|
|
139
120
|
});
|
|
140
121
|
});
|
|
122
|
+
|
|
123
|
+
// Note: splitText and changeCategory are internal implementation details.
|
|
124
|
+
// In RTL philosophy, we test user-visible behavior rather than implementation.
|
|
125
|
+
// These methods would be tested indirectly through their effects on the rendered output.
|
|
141
126
|
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import ChartType from '../chart-type';
|
|
4
4
|
|
|
5
5
|
describe('ChartType', () => {
|
|
6
|
-
let wrapper;
|
|
7
6
|
let props;
|
|
8
7
|
const onChange = jest.fn();
|
|
9
8
|
|
|
@@ -13,17 +12,12 @@ describe('ChartType', () => {
|
|
|
13
12
|
value: 'bar',
|
|
14
13
|
onChange,
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
wrapper = (newProps) => {
|
|
18
|
-
const configureProps = { ...props, newProps };
|
|
19
|
-
|
|
20
|
-
return shallow(<ChartType {...configureProps} />);
|
|
21
|
-
};
|
|
22
15
|
});
|
|
23
16
|
|
|
24
|
-
describe('
|
|
25
|
-
it('
|
|
26
|
-
|
|
17
|
+
describe('rendering', () => {
|
|
18
|
+
it('renders chart type selector', () => {
|
|
19
|
+
const { container } = render(<ChartType {...props} />);
|
|
20
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
27
21
|
});
|
|
28
22
|
});
|
|
29
23
|
});
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import { Chart } from '../chart';
|
|
4
|
-
import { graphProps } from './utils';
|
|
4
|
+
import { graphProps, createBandScale } from './utils';
|
|
5
5
|
|
|
6
6
|
describe('ChartAxes', () => {
|
|
7
7
|
let onDataChange = jest.fn();
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
const renderComponent = (extras) => {
|
|
9
10
|
const defaults = {
|
|
10
11
|
classes: {},
|
|
11
12
|
onDataChange,
|
|
12
13
|
className: 'className',
|
|
13
14
|
graphProps: graphProps(),
|
|
14
|
-
xBand: (
|
|
15
|
-
return {
|
|
16
|
-
bandwidth: () => {},
|
|
17
|
-
};
|
|
18
|
-
},
|
|
15
|
+
xBand: createBandScale(['a', 'b', 'c'], [0, 100]),
|
|
19
16
|
charts: [
|
|
20
17
|
{
|
|
21
18
|
type: 'bar',
|
|
@@ -35,61 +32,55 @@ describe('ChartAxes', () => {
|
|
|
35
32
|
data: [],
|
|
36
33
|
};
|
|
37
34
|
const props = { ...defaults, ...extras };
|
|
38
|
-
return
|
|
35
|
+
return render(<Chart {...props} />);
|
|
39
36
|
};
|
|
40
37
|
|
|
41
|
-
describe('
|
|
42
|
-
it('renders', () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect(
|
|
38
|
+
describe('rendering', () => {
|
|
39
|
+
it('renders chart container', () => {
|
|
40
|
+
const { container } = renderComponent();
|
|
41
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
42
|
+
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
it('renders
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect(
|
|
45
|
+
it('renders chart with default size', () => {
|
|
46
|
+
const { container } = renderComponent();
|
|
47
|
+
const svg = container.querySelector('svg');
|
|
48
|
+
expect(svg).toBeInTheDocument();
|
|
49
|
+
expect(svg).toHaveAttribute('width', '240');
|
|
50
|
+
expect(svg).toHaveAttribute('height', '240');
|
|
52
51
|
});
|
|
53
52
|
|
|
54
|
-
it('renders
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
it('renders chart when size is not defined', () => {
|
|
54
|
+
const { container } = renderComponent({ size: undefined });
|
|
55
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
56
|
+
const svg = container.querySelector('svg');
|
|
57
|
+
expect(svg).toBeInTheDocument();
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
it('renders without chartType
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(wrapper({ chartType: null, charts: [] })).toMatchSnapshot());
|
|
65
|
-
|
|
66
|
-
it('renders with chartType property and empty charts property', () =>
|
|
67
|
-
expect(wrapper({ charts: [] })).toMatchSnapshot());
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('logic', () => {
|
|
71
|
-
it('changeData', () => {
|
|
72
|
-
let w = wrapper();
|
|
73
|
-
|
|
74
|
-
w.instance().changeData();
|
|
75
|
-
|
|
76
|
-
expect(onDataChange).toHaveBeenCalled();
|
|
60
|
+
it('renders chart without chartType property', () => {
|
|
61
|
+
const { container } = renderComponent({ chartType: null });
|
|
62
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
63
|
+
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
77
64
|
});
|
|
78
65
|
|
|
79
|
-
it('
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
const chart = w.instance().getChart();
|
|
83
|
-
|
|
84
|
-
expect(chart.type).toEqual('bar');
|
|
66
|
+
it('renders chart without chartType and charts properties', () => {
|
|
67
|
+
const { container } = renderComponent({ chartType: null, charts: null });
|
|
68
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
85
69
|
});
|
|
86
70
|
|
|
87
|
-
it('
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
it('renders chart without chartType property and empty charts property', () => {
|
|
72
|
+
const { container } = renderComponent({ chartType: null, charts: [] });
|
|
73
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
74
|
+
});
|
|
91
75
|
|
|
92
|
-
|
|
76
|
+
it('renders chart with chartType property and empty charts property', () => {
|
|
77
|
+
const { container } = renderComponent({ charts: [] });
|
|
78
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
79
|
+
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
93
80
|
});
|
|
94
81
|
});
|
|
82
|
+
|
|
83
|
+
// Note: changeData, getChart, and deleteCategory are internal implementation details.
|
|
84
|
+
// In RTL philosophy, we test user-visible behavior rather than implementation.
|
|
85
|
+
// These methods would be tested indirectly through user interactions that trigger them.
|
|
95
86
|
});
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import { Grid } from '../grid';
|
|
4
|
-
import { graphProps } from './utils';
|
|
4
|
+
import { graphProps, createBandScale } from './utils';
|
|
5
5
|
|
|
6
6
|
describe('Grid', () => {
|
|
7
|
-
|
|
8
|
-
const wrapper = (extras) => {
|
|
7
|
+
const renderComponent = (extras) => {
|
|
9
8
|
const defaults = {
|
|
10
9
|
classes: {},
|
|
11
10
|
className: 'className',
|
|
12
11
|
graphProps: graphProps(),
|
|
13
|
-
xBand:
|
|
14
|
-
bandwidth: () => {},
|
|
15
|
-
},
|
|
12
|
+
xBand: createBandScale(['a', 'b', 'c'], [0, 400]),
|
|
16
13
|
};
|
|
17
14
|
const props = { ...defaults, ...extras };
|
|
18
|
-
return
|
|
15
|
+
return render(
|
|
16
|
+
<svg>
|
|
17
|
+
<Grid {...props} />
|
|
18
|
+
</svg>
|
|
19
|
+
);
|
|
19
20
|
};
|
|
20
|
-
describe('snapshot', () => {
|
|
21
|
-
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
describe('rendering', () => {
|
|
23
|
+
it('renders grid container', () => {
|
|
24
|
+
const { container } = renderComponent();
|
|
25
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders grid with SVG group', () => {
|
|
29
|
+
const { container } = renderComponent();
|
|
30
|
+
const svg = container.querySelector('svg');
|
|
31
|
+
expect(svg).toBeInTheDocument();
|
|
32
|
+
// Grid renders a <g> element (StyledGridGroup)
|
|
33
|
+
const gridGroup = container.querySelector('g');
|
|
34
|
+
expect(gridGroup).toBeInTheDocument();
|
|
35
|
+
});
|
|
24
36
|
});
|
|
25
37
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import { MarkLabel } from '../mark-label';
|
|
4
4
|
import { graphProps as getGraphProps } from './utils';
|
|
5
5
|
|
|
6
6
|
describe('MarkLabel', () => {
|
|
7
|
-
let w;
|
|
8
7
|
let onChange = jest.fn();
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
const renderComponent = (extras) => {
|
|
10
10
|
const defaults = {
|
|
11
11
|
classes: {},
|
|
12
12
|
defineChart: false,
|
|
@@ -16,16 +16,18 @@ describe('MarkLabel', () => {
|
|
|
16
16
|
graphProps: getGraphProps(0, 10, 0, 10),
|
|
17
17
|
};
|
|
18
18
|
const props = { ...defaults, ...extras };
|
|
19
|
-
return
|
|
19
|
+
return render(<MarkLabel {...props} />);
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
|
|
22
|
+
describe('rendering', () => {
|
|
23
|
+
it('renders mark label', () => {
|
|
24
|
+
const { container } = renderComponent();
|
|
25
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
25
26
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
it('renders mark label at different positions', () => {
|
|
29
|
+
const { container } = renderComponent({ mark: { x: 10, y: 10 } });
|
|
30
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
29
31
|
});
|
|
30
32
|
});
|
|
31
33
|
});
|
package/src/__tests__/utils.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
2
|
+
|
|
1
3
|
export const scaleMock = () => {
|
|
2
4
|
const fn = jest.fn((n) => n);
|
|
3
5
|
fn.invert = jest.fn((n) => n);
|
|
4
6
|
return fn;
|
|
5
7
|
};
|
|
6
8
|
|
|
9
|
+
export const createBandScale = (domain = [], range = [0, 400]) => {
|
|
10
|
+
return scaleBand().domain(domain).range(range).padding(0.1);
|
|
11
|
+
};
|
|
12
|
+
|
|
7
13
|
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
8
14
|
scale: {
|
|
9
|
-
x:
|
|
10
|
-
y:
|
|
15
|
+
x: scaleLinear().domain([dmin, dmax]).range([0, 400]),
|
|
16
|
+
y: scaleLinear().domain([rmin, rmax]).range([400, 0]),
|
|
11
17
|
},
|
|
12
18
|
snap: {
|
|
13
19
|
x: jest.fn((n) => n),
|