@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,645 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render, waitFor } from '@pie-lib/test-utils';
|
|
3
|
+
import GridSetup from '../grid-setup';
|
|
4
|
+
|
|
5
|
+
const mockOnChange = jest.fn();
|
|
6
|
+
const mockOnChangeView = jest.fn();
|
|
7
|
+
|
|
8
|
+
const defaultProps = {
|
|
9
|
+
domain: {
|
|
10
|
+
min: -5,
|
|
11
|
+
max: 5,
|
|
12
|
+
step: 1,
|
|
13
|
+
labelStep: 1,
|
|
14
|
+
axisLabel: 'x',
|
|
15
|
+
},
|
|
16
|
+
range: {
|
|
17
|
+
min: -5,
|
|
18
|
+
max: 5,
|
|
19
|
+
step: 1,
|
|
20
|
+
labelStep: 1,
|
|
21
|
+
axisLabel: 'y',
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
width: 480,
|
|
25
|
+
height: 480,
|
|
26
|
+
},
|
|
27
|
+
sizeConstraints: {
|
|
28
|
+
min: 300,
|
|
29
|
+
max: 900,
|
|
30
|
+
step: 10,
|
|
31
|
+
},
|
|
32
|
+
includeAxes: true,
|
|
33
|
+
standardGrid: false,
|
|
34
|
+
displayedFields: {
|
|
35
|
+
axisLabel: { enabled: true, label: 'Axis Label' },
|
|
36
|
+
min: { enabled: true, label: 'Min' },
|
|
37
|
+
max: { enabled: true, label: 'Max' },
|
|
38
|
+
step: { enabled: true, label: 'Interval' },
|
|
39
|
+
labelStep: { enabled: true, label: 'Label Interval' },
|
|
40
|
+
dimensionsEnabled: true,
|
|
41
|
+
includeAxesEnabled: true,
|
|
42
|
+
standardGridEnabled: true,
|
|
43
|
+
},
|
|
44
|
+
gridValues: {
|
|
45
|
+
domain: [1, 2, 5, 10],
|
|
46
|
+
range: [1, 2, 5, 10],
|
|
47
|
+
},
|
|
48
|
+
labelValues: {
|
|
49
|
+
domain: [0, 1, 2],
|
|
50
|
+
range: [0, 1, 2],
|
|
51
|
+
},
|
|
52
|
+
onChange: mockOnChange,
|
|
53
|
+
onChangeView: mockOnChangeView,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
describe('GridSetup', () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
jest.clearAllMocks();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('rendering', () => {
|
|
62
|
+
it('renders without crashing', () => {
|
|
63
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
64
|
+
expect(container).toBeTruthy();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('renders accordion with title', () => {
|
|
68
|
+
const { getByText } = render(<GridSetup {...defaultProps} />);
|
|
69
|
+
expect(getByText('Customize Grid Setup')).toBeTruthy();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('renders Include axes toggle when enabled', () => {
|
|
73
|
+
const { getByText } = render(<GridSetup {...defaultProps} />);
|
|
74
|
+
expect(getByText('Include axes and labels?')).toBeTruthy();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('does not render Include axes toggle when disabled', () => {
|
|
78
|
+
const props = {
|
|
79
|
+
...defaultProps,
|
|
80
|
+
displayedFields: {
|
|
81
|
+
...defaultProps.displayedFields,
|
|
82
|
+
includeAxesEnabled: false,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const { queryByText } = render(<GridSetup {...props} />);
|
|
86
|
+
expect(queryByText('Include axes and labels?')).toBeFalsy();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('renders standard grid toggle when enabled', () => {
|
|
90
|
+
const { getByText } = render(<GridSetup {...defaultProps} />);
|
|
91
|
+
expect(getByText('Constrain to standard coordinate grid?')).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('does not render standard grid toggle when disabled', () => {
|
|
95
|
+
const props = {
|
|
96
|
+
...defaultProps,
|
|
97
|
+
displayedFields: {
|
|
98
|
+
...defaultProps.displayedFields,
|
|
99
|
+
standardGridEnabled: false,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const { queryByText } = render(<GridSetup {...props} />);
|
|
103
|
+
expect(queryByText('Constrain to standard coordinate grid?')).toBeFalsy();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('renders dimensions section when enabled', () => {
|
|
107
|
+
const { getByText } = render(<GridSetup {...defaultProps} />);
|
|
108
|
+
expect(getByText('Dimensions(px)')).toBeTruthy();
|
|
109
|
+
expect(getByText(/Min 300, Max 900/)).toBeTruthy();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('does not render dimensions section when disabled', () => {
|
|
113
|
+
const props = {
|
|
114
|
+
...defaultProps,
|
|
115
|
+
displayedFields: {
|
|
116
|
+
...defaultProps.displayedFields,
|
|
117
|
+
dimensionsEnabled: false,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
const { queryByText } = render(<GridSetup {...props} />);
|
|
121
|
+
expect(queryByText('Dimensions(px)')).toBeFalsy();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('axes configuration', () => {
|
|
126
|
+
it('renders axis headers when includeAxes is true', () => {
|
|
127
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
128
|
+
const xAxisHeader = container.querySelector('i');
|
|
129
|
+
expect(xAxisHeader?.textContent).toBe('x');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('renders min/max fields when enabled', () => {
|
|
133
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
134
|
+
const minFields = getAllByLabelText('Min');
|
|
135
|
+
const maxFields = getAllByLabelText('Max');
|
|
136
|
+
expect(minFields.length).toBe(2); // domain and range
|
|
137
|
+
expect(maxFields.length).toBe(2); // domain and range
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('does not render min/max fields when disabled', () => {
|
|
141
|
+
const props = {
|
|
142
|
+
...defaultProps,
|
|
143
|
+
displayedFields: {
|
|
144
|
+
...defaultProps.displayedFields,
|
|
145
|
+
min: { enabled: false },
|
|
146
|
+
max: { enabled: false },
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
const { queryByLabelText } = render(<GridSetup {...props} />);
|
|
150
|
+
expect(queryByLabelText('Min')).toBeFalsy();
|
|
151
|
+
expect(queryByLabelText('Max')).toBeFalsy();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('renders axis label fields when enabled', () => {
|
|
155
|
+
const { getAllByText } = render(<GridSetup {...defaultProps} />);
|
|
156
|
+
const axisLabelFields = getAllByText('Axis Label');
|
|
157
|
+
expect(axisLabelFields.length).toBe(2); // domain and range
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('does not render axis label fields when disabled', () => {
|
|
161
|
+
const props = {
|
|
162
|
+
...defaultProps,
|
|
163
|
+
displayedFields: {
|
|
164
|
+
...defaultProps.displayedFields,
|
|
165
|
+
axisLabel: { enabled: false },
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
const { queryByText } = render(<GridSetup {...props} />);
|
|
169
|
+
expect(queryByText('Axis Label')).toBeFalsy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('renders step and labelStep fields when enabled', () => {
|
|
173
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
174
|
+
const intervalFields = getAllByLabelText('Interval');
|
|
175
|
+
const labelIntervalFields = getAllByLabelText('Label Interval');
|
|
176
|
+
expect(intervalFields.length).toBe(2); // domain and range
|
|
177
|
+
expect(labelIntervalFields.length).toBe(2); // domain and range
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('does not render step fields when disabled', () => {
|
|
181
|
+
const props = {
|
|
182
|
+
...defaultProps,
|
|
183
|
+
displayedFields: {
|
|
184
|
+
...defaultProps.displayedFields,
|
|
185
|
+
step: { enabled: false },
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
const { queryByLabelText } = render(<GridSetup {...props} />);
|
|
189
|
+
expect(queryByLabelText('Interval')).toBeFalsy();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('does not render labelStep fields when disabled', () => {
|
|
193
|
+
const props = {
|
|
194
|
+
...defaultProps,
|
|
195
|
+
displayedFields: {
|
|
196
|
+
...defaultProps.displayedFields,
|
|
197
|
+
labelStep: { enabled: false },
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
const { queryByLabelText } = render(<GridSetup {...props} />);
|
|
201
|
+
expect(queryByLabelText('Label Interval')).toBeFalsy();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('displays axis visibility hint when min/max enabled', () => {
|
|
205
|
+
const { getByText } = render(<GridSetup {...defaultProps} />);
|
|
206
|
+
expect(
|
|
207
|
+
getByText('If you want the axis to be visible, use a zero or negative Min Value, and a positive Max Value'),
|
|
208
|
+
).toBeTruthy();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('displays unnumbered gridlines hint when labelStep enabled', () => {
|
|
212
|
+
const { getByText } = render(<GridSetup {...defaultProps} />);
|
|
213
|
+
expect(getByText('For unnumbered gridlines, enter a label interval of 0')).toBeTruthy();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('gridlines configuration', () => {
|
|
218
|
+
it('renders gridlines config when includeAxes is false', () => {
|
|
219
|
+
const props = {
|
|
220
|
+
...defaultProps,
|
|
221
|
+
includeAxes: false,
|
|
222
|
+
};
|
|
223
|
+
const { getByLabelText } = render(<GridSetup {...props} />);
|
|
224
|
+
expect(getByLabelText('Number of Vertical Gridlines')).toBeTruthy();
|
|
225
|
+
expect(getByLabelText('Number of Horizontal Gridlines')).toBeTruthy();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('does not render axes config when includeAxes is false', () => {
|
|
229
|
+
const props = {
|
|
230
|
+
...defaultProps,
|
|
231
|
+
includeAxes: false,
|
|
232
|
+
};
|
|
233
|
+
const { queryByText } = render(<GridSetup {...props} />);
|
|
234
|
+
expect(queryByText('Axis Label')).toBeFalsy();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('does not render gridlines config when max is disabled', () => {
|
|
238
|
+
const props = {
|
|
239
|
+
...defaultProps,
|
|
240
|
+
includeAxes: false,
|
|
241
|
+
displayedFields: {
|
|
242
|
+
...defaultProps.displayedFields,
|
|
243
|
+
max: { enabled: false },
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
const { queryByLabelText } = render(<GridSetup {...props} />);
|
|
247
|
+
expect(queryByLabelText('Number of Vertical Gridlines')).toBeFalsy();
|
|
248
|
+
expect(queryByLabelText('Number of Horizontal Gridlines')).toBeFalsy();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('user interactions', () => {
|
|
253
|
+
it('calls onChange when includeAxes toggle is clicked', () => {
|
|
254
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
255
|
+
const toggleInput = container.querySelector('input[type="checkbox"]');
|
|
256
|
+
|
|
257
|
+
fireEvent.click(toggleInput);
|
|
258
|
+
|
|
259
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
260
|
+
expect.objectContaining({
|
|
261
|
+
includeAxes: false,
|
|
262
|
+
}),
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('calls onChange with proper config when includeAxes is disabled', () => {
|
|
267
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
268
|
+
const toggleInput = container.querySelector('input[type="checkbox"]');
|
|
269
|
+
|
|
270
|
+
fireEvent.click(toggleInput);
|
|
271
|
+
|
|
272
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
273
|
+
expect.objectContaining({
|
|
274
|
+
includeAxes: false,
|
|
275
|
+
domain: expect.objectContaining({
|
|
276
|
+
min: 1,
|
|
277
|
+
max: 5,
|
|
278
|
+
step: 1,
|
|
279
|
+
labelStep: 0,
|
|
280
|
+
}),
|
|
281
|
+
range: expect.objectContaining({
|
|
282
|
+
min: 1,
|
|
283
|
+
max: 5,
|
|
284
|
+
step: 1,
|
|
285
|
+
labelStep: 0,
|
|
286
|
+
}),
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('calls onChange with proper config when includeAxes is enabled', () => {
|
|
292
|
+
const props = {
|
|
293
|
+
...defaultProps,
|
|
294
|
+
includeAxes: false,
|
|
295
|
+
};
|
|
296
|
+
const { container } = render(<GridSetup {...props} />);
|
|
297
|
+
const toggleInputs = container.querySelectorAll('input[type="checkbox"]');
|
|
298
|
+
const includeAxesToggle = toggleInputs[0]; // First toggle is includeAxes
|
|
299
|
+
|
|
300
|
+
fireEvent.click(includeAxesToggle);
|
|
301
|
+
|
|
302
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
303
|
+
expect.objectContaining({
|
|
304
|
+
includeAxes: true,
|
|
305
|
+
domain: expect.objectContaining({
|
|
306
|
+
labelStep: 1,
|
|
307
|
+
}),
|
|
308
|
+
range: expect.objectContaining({
|
|
309
|
+
labelStep: 1,
|
|
310
|
+
}),
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('calls onChange when standardGrid toggle is clicked', () => {
|
|
316
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
317
|
+
const toggleInputs = container.querySelectorAll('input[type="checkbox"]');
|
|
318
|
+
const standardGridToggle = toggleInputs[1]; // Second toggle is standardGrid
|
|
319
|
+
|
|
320
|
+
fireEvent.click(standardGridToggle);
|
|
321
|
+
|
|
322
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
323
|
+
expect.objectContaining({
|
|
324
|
+
standardGrid: true,
|
|
325
|
+
graph: expect.objectContaining({
|
|
326
|
+
width: 480,
|
|
327
|
+
height: 480,
|
|
328
|
+
}),
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('calls onChange when width is changed', async () => {
|
|
334
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
335
|
+
const widthInput = getAllByLabelText('Width')[0];
|
|
336
|
+
|
|
337
|
+
fireEvent.change(widthInput, { target: { value: '500' } });
|
|
338
|
+
fireEvent.blur(widthInput);
|
|
339
|
+
|
|
340
|
+
await waitFor(() => {
|
|
341
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
342
|
+
expect.objectContaining({
|
|
343
|
+
graph: expect.objectContaining({
|
|
344
|
+
width: 500,
|
|
345
|
+
}),
|
|
346
|
+
}),
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('calls onChange when height is changed', async () => {
|
|
352
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
353
|
+
const heightInput = getAllByLabelText('Height')[0];
|
|
354
|
+
|
|
355
|
+
fireEvent.change(heightInput, { target: { value: '520' } });
|
|
356
|
+
fireEvent.blur(heightInput);
|
|
357
|
+
|
|
358
|
+
await waitFor(() => {
|
|
359
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
360
|
+
expect.objectContaining({
|
|
361
|
+
graph: expect.objectContaining({
|
|
362
|
+
height: 520,
|
|
363
|
+
}),
|
|
364
|
+
}),
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('updates both width and height when standardGrid is true', async () => {
|
|
370
|
+
const props = {
|
|
371
|
+
...defaultProps,
|
|
372
|
+
standardGrid: true,
|
|
373
|
+
};
|
|
374
|
+
const { getAllByLabelText } = render(<GridSetup {...props} />);
|
|
375
|
+
const widthInput = getAllByLabelText('Width')[0];
|
|
376
|
+
|
|
377
|
+
fireEvent.change(widthInput, { target: { value: '600' } });
|
|
378
|
+
fireEvent.blur(widthInput);
|
|
379
|
+
|
|
380
|
+
await waitFor(() => {
|
|
381
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
382
|
+
expect.objectContaining({
|
|
383
|
+
graph: expect.objectContaining({
|
|
384
|
+
width: 600,
|
|
385
|
+
height: 600,
|
|
386
|
+
}),
|
|
387
|
+
}),
|
|
388
|
+
);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('calls onChange when domain min is changed', async () => {
|
|
393
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
394
|
+
const minInputs = getAllByLabelText('Min');
|
|
395
|
+
const domainMinInput = minInputs[0];
|
|
396
|
+
|
|
397
|
+
fireEvent.change(domainMinInput, { target: { value: '-10' } });
|
|
398
|
+
fireEvent.blur(domainMinInput);
|
|
399
|
+
|
|
400
|
+
await waitFor(() => {
|
|
401
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
402
|
+
expect.objectContaining({
|
|
403
|
+
domain: expect.objectContaining({
|
|
404
|
+
min: -10,
|
|
405
|
+
}),
|
|
406
|
+
}),
|
|
407
|
+
);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('calls onChange when domain max is changed', async () => {
|
|
412
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
413
|
+
const maxInputs = getAllByLabelText('Max');
|
|
414
|
+
const domainMaxInput = maxInputs[0];
|
|
415
|
+
|
|
416
|
+
fireEvent.change(domainMaxInput, { target: { value: '10' } });
|
|
417
|
+
fireEvent.blur(domainMaxInput);
|
|
418
|
+
|
|
419
|
+
await waitFor(() => {
|
|
420
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
421
|
+
expect.objectContaining({
|
|
422
|
+
domain: expect.objectContaining({
|
|
423
|
+
max: 10,
|
|
424
|
+
}),
|
|
425
|
+
}),
|
|
426
|
+
);
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it('calls onChange when range min is changed', async () => {
|
|
431
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
432
|
+
const minInputs = getAllByLabelText('Min');
|
|
433
|
+
const rangeMinInput = minInputs[1];
|
|
434
|
+
|
|
435
|
+
fireEvent.change(rangeMinInput, { target: { value: '-8' } });
|
|
436
|
+
fireEvent.blur(rangeMinInput);
|
|
437
|
+
|
|
438
|
+
await waitFor(() => {
|
|
439
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
440
|
+
expect.objectContaining({
|
|
441
|
+
range: expect.objectContaining({
|
|
442
|
+
min: -8,
|
|
443
|
+
}),
|
|
444
|
+
}),
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('calls onChange when range max is changed', async () => {
|
|
450
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
451
|
+
const maxInputs = getAllByLabelText('Max');
|
|
452
|
+
const rangeMaxInput = maxInputs[1];
|
|
453
|
+
|
|
454
|
+
fireEvent.change(rangeMaxInput, { target: { value: '12' } });
|
|
455
|
+
fireEvent.blur(rangeMaxInput);
|
|
456
|
+
|
|
457
|
+
await waitFor(() => {
|
|
458
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
459
|
+
expect.objectContaining({
|
|
460
|
+
range: expect.objectContaining({
|
|
461
|
+
max: 12,
|
|
462
|
+
}),
|
|
463
|
+
}),
|
|
464
|
+
);
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('updates both domain and range when standardGrid is true and domain changes', async () => {
|
|
469
|
+
const props = {
|
|
470
|
+
...defaultProps,
|
|
471
|
+
standardGrid: true,
|
|
472
|
+
};
|
|
473
|
+
const { getAllByLabelText } = render(<GridSetup {...props} />);
|
|
474
|
+
const minInputs = getAllByLabelText('Min');
|
|
475
|
+
const domainMinInput = minInputs[0];
|
|
476
|
+
|
|
477
|
+
fireEvent.change(domainMinInput, { target: { value: '-15' } });
|
|
478
|
+
fireEvent.blur(domainMinInput);
|
|
479
|
+
|
|
480
|
+
await waitFor(() => {
|
|
481
|
+
expect(mockOnChange).toHaveBeenCalledWith(
|
|
482
|
+
expect.objectContaining({
|
|
483
|
+
domain: expect.objectContaining({
|
|
484
|
+
min: -15,
|
|
485
|
+
}),
|
|
486
|
+
range: expect.objectContaining({
|
|
487
|
+
min: -15,
|
|
488
|
+
}),
|
|
489
|
+
}),
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('does not update range when domain axisLabel changes with standardGrid', async () => {
|
|
495
|
+
const props = {
|
|
496
|
+
...defaultProps,
|
|
497
|
+
standardGrid: true,
|
|
498
|
+
};
|
|
499
|
+
const { container } = render(<GridSetup {...props} />);
|
|
500
|
+
|
|
501
|
+
// EditableHTML change is harder to trigger, but we can test the handler directly
|
|
502
|
+
// by verifying the range doesn't get the axisLabel value from domain
|
|
503
|
+
const axisLabelInputs = container.querySelectorAll('[contenteditable="true"]');
|
|
504
|
+
|
|
505
|
+
if (axisLabelInputs.length > 0) {
|
|
506
|
+
fireEvent.input(axisLabelInputs[0], { target: { innerHTML: 'X-Axis' } });
|
|
507
|
+
|
|
508
|
+
await waitFor(() => {
|
|
509
|
+
if (mockOnChange.mock.calls.length > 0) {
|
|
510
|
+
const lastCall = mockOnChange.mock.calls[mockOnChange.mock.calls.length - 1][0];
|
|
511
|
+
// range.axisLabel should not be 'X-Axis', it should keep its original value
|
|
512
|
+
expect(lastCall.range?.axisLabel).not.toBe('X-Axis');
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it('calls onChangeView when accordion is toggled', () => {
|
|
519
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
520
|
+
const accordionSummary = container.querySelector('[aria-expanded]');
|
|
521
|
+
|
|
522
|
+
fireEvent.click(accordionSummary);
|
|
523
|
+
|
|
524
|
+
expect(mockOnChangeView).toHaveBeenCalled();
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
describe('disabled states', () => {
|
|
529
|
+
it('disables range fields when standardGrid is true', () => {
|
|
530
|
+
const props = {
|
|
531
|
+
...defaultProps,
|
|
532
|
+
standardGrid: true,
|
|
533
|
+
};
|
|
534
|
+
const { getAllByLabelText } = render(<GridSetup {...props} />);
|
|
535
|
+
const minInputs = getAllByLabelText('Min');
|
|
536
|
+
const rangeMinInput = minInputs[1];
|
|
537
|
+
|
|
538
|
+
expect(rangeMinInput).toBeDisabled();
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it('disables height field when standardGrid is true', () => {
|
|
542
|
+
const props = {
|
|
543
|
+
...defaultProps,
|
|
544
|
+
standardGrid: true,
|
|
545
|
+
};
|
|
546
|
+
const { getAllByLabelText } = render(<GridSetup {...props} />);
|
|
547
|
+
const heightInput = getAllByLabelText('Height')[0];
|
|
548
|
+
|
|
549
|
+
expect(heightInput).toBeDisabled();
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('disables horizontal gridlines field when standardGrid is true and includeAxes is false', () => {
|
|
553
|
+
const props = {
|
|
554
|
+
...defaultProps,
|
|
555
|
+
includeAxes: false,
|
|
556
|
+
standardGrid: true,
|
|
557
|
+
};
|
|
558
|
+
const { getByLabelText } = render(<GridSetup {...props} />);
|
|
559
|
+
const horizontalGridlinesInput = getByLabelText('Number of Horizontal Gridlines');
|
|
560
|
+
|
|
561
|
+
expect(horizontalGridlinesInput).toBeDisabled();
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
describe('GridConfig component', () => {
|
|
566
|
+
it('renders step field when enabled', () => {
|
|
567
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
568
|
+
const intervalFields = getAllByLabelText('Interval');
|
|
569
|
+
expect(intervalFields.length).toBeGreaterThan(0);
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it('renders labelStep field when enabled', () => {
|
|
573
|
+
const { getAllByLabelText } = render(<GridSetup {...defaultProps} />);
|
|
574
|
+
const labelIntervalFields = getAllByLabelText('Label Interval');
|
|
575
|
+
expect(labelIntervalFields.length).toBeGreaterThan(0);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it('does not render when both step and labelStep are disabled', () => {
|
|
579
|
+
const props = {
|
|
580
|
+
...defaultProps,
|
|
581
|
+
displayedFields: {
|
|
582
|
+
...defaultProps.displayedFields,
|
|
583
|
+
step: { enabled: false },
|
|
584
|
+
labelStep: { enabled: false },
|
|
585
|
+
},
|
|
586
|
+
};
|
|
587
|
+
const { queryByLabelText } = render(<GridSetup {...props} />);
|
|
588
|
+
expect(queryByLabelText('Interval')).toBeFalsy();
|
|
589
|
+
expect(queryByLabelText('Label Interval')).toBeFalsy();
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
describe('AxisConfig component', () => {
|
|
594
|
+
it('renders x-axis header', () => {
|
|
595
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
596
|
+
const headers = container.querySelectorAll('i');
|
|
597
|
+
const xAxisHeader = Array.from(headers).find((h) => h.textContent === 'x');
|
|
598
|
+
expect(xAxisHeader).toBeTruthy();
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it('renders y-axis header', () => {
|
|
602
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
603
|
+
const headers = container.querySelectorAll('i');
|
|
604
|
+
const yAxisHeader = Array.from(headers).find((h) => h.textContent === 'y');
|
|
605
|
+
expect(yAxisHeader).toBeTruthy();
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it('does not render headers when all fields are disabled', () => {
|
|
609
|
+
const props = {
|
|
610
|
+
...defaultProps,
|
|
611
|
+
displayedFields: {
|
|
612
|
+
...defaultProps.displayedFields,
|
|
613
|
+
min: { enabled: false },
|
|
614
|
+
max: { enabled: false },
|
|
615
|
+
axisLabel: { enabled: false },
|
|
616
|
+
step: { enabled: false },
|
|
617
|
+
labelStep: { enabled: false },
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
const { container } = render(<GridSetup {...props} />);
|
|
621
|
+
const headers = container.querySelectorAll('i');
|
|
622
|
+
const axisHeaders = Array.from(headers).filter((h) => h.textContent === 'x' || h.textContent === 'y');
|
|
623
|
+
expect(axisHeaders.length).toBe(0);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
describe('Accordion behavior', () => {
|
|
628
|
+
it('renders with correct transition props', () => {
|
|
629
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
630
|
+
const accordion = container.querySelector('.MuiAccordion-root');
|
|
631
|
+
expect(accordion).toBeTruthy();
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
it('expands and collapses accordion', () => {
|
|
635
|
+
const { container } = render(<GridSetup {...defaultProps} />);
|
|
636
|
+
const accordionSummary = container.querySelector('[aria-expanded]');
|
|
637
|
+
|
|
638
|
+
expect(accordionSummary.getAttribute('aria-expanded')).toBe('false');
|
|
639
|
+
|
|
640
|
+
fireEvent.click(accordionSummary);
|
|
641
|
+
|
|
642
|
+
expect(mockOnChangeView).toHaveBeenCalled();
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { MarkLabel, position
|
|
3
|
+
import { coordinates, MarkLabel, position } from '../mark-label';
|
|
4
4
|
import { graphProps as getGraphProps } from './utils';
|
|
5
5
|
|
|
6
6
|
describe('MarkLabel', () => {
|