@pie-lib/charting 7.0.13 → 7.1.0-beta
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 +0 -44
- package/lib/__tests__/actions-button.test.js +332 -0
- package/lib/__tests__/actions-button.test.js.map +1 -0
- package/lib/__tests__/axes.test.js +746 -0
- package/lib/__tests__/axes.test.js.map +1 -0
- package/lib/__tests__/chart-setup.test.js +796 -0
- package/lib/__tests__/chart-setup.test.js.map +1 -0
- package/lib/__tests__/chart-type.test.js +25 -0
- package/lib/__tests__/chart-type.test.js.map +1 -0
- package/lib/__tests__/chart.test.js +103 -0
- package/lib/__tests__/chart.test.js.map +1 -0
- package/lib/__tests__/grid.test.js +39 -0
- package/lib/__tests__/grid.test.js.map +1 -0
- package/lib/__tests__/key-legend.test.js +235 -0
- package/lib/__tests__/key-legend.test.js.map +1 -0
- package/lib/__tests__/mark-label.test.js +46 -0
- package/lib/__tests__/mark-label.test.js.map +1 -0
- package/lib/__tests__/tool-menu.test.js +627 -0
- package/lib/__tests__/tool-menu.test.js.map +1 -0
- package/lib/__tests__/utils.js +56 -0
- package/lib/__tests__/utils.js.map +1 -0
- package/lib/__tests__/utils.test.js +186 -0
- package/lib/__tests__/utils.test.js.map +1 -0
- package/lib/bars/__tests__/bar.test.js +53 -0
- package/lib/bars/__tests__/bar.test.js.map +1 -0
- package/lib/bars/__tests__/histogram.test.js +53 -0
- package/lib/bars/__tests__/histogram.test.js.map +1 -0
- package/lib/bars/__tests__/utils.js +50 -0
- package/lib/bars/__tests__/utils.js.map +1 -0
- package/lib/bars/common/__tests__/bars.test.js +76 -0
- package/lib/bars/common/__tests__/bars.test.js.map +1 -0
- package/lib/bars/common/__tests__/utils.js +50 -0
- package/lib/bars/common/__tests__/utils.js.map +1 -0
- package/lib/common/__tests__/correctness-indicators.test.js +887 -0
- package/lib/common/__tests__/correctness-indicators.test.js.map +1 -0
- package/lib/common/__tests__/drag-handle.test.js +73 -0
- package/lib/common/__tests__/drag-handle.test.js.map +1 -0
- package/lib/common/__tests__/utils.js +50 -0
- package/lib/common/__tests__/utils.js.map +1 -0
- package/lib/line/__tests__/line-cross.test.js +617 -0
- package/lib/line/__tests__/line-cross.test.js.map +1 -0
- package/lib/line/__tests__/line-dot.test.js +47 -0
- package/lib/line/__tests__/line-dot.test.js.map +1 -0
- package/lib/line/__tests__/utils.js +56 -0
- package/lib/line/__tests__/utils.js.map +1 -0
- package/lib/line/common/__tests__/drag-handle.test.js +73 -0
- package/lib/line/common/__tests__/drag-handle.test.js.map +1 -0
- package/lib/line/common/__tests__/line.test.js +92 -0
- package/lib/line/common/__tests__/line.test.js.map +1 -0
- package/lib/line/common/__tests__/utils.js +50 -0
- package/lib/line/common/__tests__/utils.js.map +1 -0
- package/lib/plot/__tests__/dot.test.js +513 -0
- package/lib/plot/__tests__/dot.test.js.map +1 -0
- package/lib/plot/__tests__/line.test.js +566 -0
- package/lib/plot/__tests__/line.test.js.map +1 -0
- package/lib/plot/__tests__/utils.js +50 -0
- package/lib/plot/__tests__/utils.js.map +1 -0
- package/lib/plot/common/__tests__/plot.test.js +79 -0
- package/lib/plot/common/__tests__/plot.test.js.map +1 -0
- package/lib/plot/common/__tests__/utils.js +50 -0
- package/lib/plot/common/__tests__/utils.js.map +1 -0
- package/package.json +5 -5
- package/LICENSE.md +0 -5
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
6
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _testUtils = require("@pie-lib/test-utils");
|
|
10
|
+
var _styles = require("@mui/material/styles");
|
|
11
|
+
var _lineCross = _interopRequireWildcard(require("../line-cross"));
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
var _excluded = ["data", "x", "y", "strokeWidth", "style"],
|
|
14
|
+
_excluded2 = ["children"],
|
|
15
|
+
_excluded3 = ["CustomDraggableComponent", "data", "graphProps"];
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
// Mock dependencies
|
|
20
|
+
jest.mock('@visx/shape', function () {
|
|
21
|
+
return {
|
|
22
|
+
LinePath: function LinePath(_ref) {
|
|
23
|
+
var data = _ref.data,
|
|
24
|
+
x = _ref.x,
|
|
25
|
+
y = _ref.y,
|
|
26
|
+
strokeWidth = _ref.strokeWidth,
|
|
27
|
+
style = _ref.style,
|
|
28
|
+
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
29
|
+
return /*#__PURE__*/_react["default"].createElement("path", (0, _extends2["default"])({
|
|
30
|
+
"data-testid": "line-path",
|
|
31
|
+
d: data.map(function (d, i) {
|
|
32
|
+
return "".concat(i === 0 ? 'M' : 'L').concat(x(d), ",").concat(y(d));
|
|
33
|
+
}).join(' '),
|
|
34
|
+
strokeWidth: strokeWidth
|
|
35
|
+
}, props));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
jest.mock('@visx/group', function () {
|
|
40
|
+
return {
|
|
41
|
+
Group: function Group(_ref2) {
|
|
42
|
+
var children = _ref2.children,
|
|
43
|
+
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2);
|
|
44
|
+
return /*#__PURE__*/_react["default"].createElement("g", (0, _extends2["default"])({
|
|
45
|
+
"data-testid": "visx-group"
|
|
46
|
+
}, props), children);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
jest.mock('@pie-lib/render-ui', function () {
|
|
51
|
+
return {
|
|
52
|
+
color: {
|
|
53
|
+
text: function text() {
|
|
54
|
+
return '#000000';
|
|
55
|
+
},
|
|
56
|
+
defaults: {
|
|
57
|
+
TEXT: '#000000',
|
|
58
|
+
BLACK: '#000000',
|
|
59
|
+
BORDER_GRAY: '#cccccc'
|
|
60
|
+
},
|
|
61
|
+
disabled: function disabled() {
|
|
62
|
+
return '#cccccc';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
jest.mock('../../utils', function () {
|
|
68
|
+
return {
|
|
69
|
+
dataToXBand: jest.fn(function (scale, data, width, type) {
|
|
70
|
+
return {
|
|
71
|
+
bandwidth: function bandwidth() {
|
|
72
|
+
return 20;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
jest.mock('../common/line', function () {
|
|
79
|
+
return function RawLine(_ref3) {
|
|
80
|
+
var CustomDraggableComponent = _ref3.CustomDraggableComponent,
|
|
81
|
+
data = _ref3.data,
|
|
82
|
+
graphProps = _ref3.graphProps,
|
|
83
|
+
props = (0, _objectWithoutProperties2["default"])(_ref3, _excluded3);
|
|
84
|
+
return /*#__PURE__*/_react["default"].createElement("svg", {
|
|
85
|
+
"data-testid": "raw-line"
|
|
86
|
+
}, data && data.length > 0 ? data.map(function (d, i) {
|
|
87
|
+
return /*#__PURE__*/_react["default"].createElement(CustomDraggableComponent, (0, _extends2["default"])({
|
|
88
|
+
key: i,
|
|
89
|
+
scale: graphProps.scale,
|
|
90
|
+
x: d.x || i,
|
|
91
|
+
y: d.y || i,
|
|
92
|
+
r: 8,
|
|
93
|
+
correctness: d.correctness,
|
|
94
|
+
interactive: d.interactive,
|
|
95
|
+
correctData: props.correctData,
|
|
96
|
+
label: d.label
|
|
97
|
+
}, props));
|
|
98
|
+
}) : /*#__PURE__*/_react["default"].createElement("text", null, "No data"));
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
jest.mock('../../common/correctness-indicators', function () {
|
|
102
|
+
return {
|
|
103
|
+
CorrectnessIndicator: function CorrectnessIndicator(_ref4) {
|
|
104
|
+
var scale = _ref4.scale,
|
|
105
|
+
x = _ref4.x,
|
|
106
|
+
y = _ref4.y,
|
|
107
|
+
correctness = _ref4.correctness,
|
|
108
|
+
interactive = _ref4.interactive;
|
|
109
|
+
return correctness && interactive ? /*#__PURE__*/_react["default"].createElement("g", {
|
|
110
|
+
"data-testid": "correctness-indicator"
|
|
111
|
+
}, /*#__PURE__*/_react["default"].createElement("circle", {
|
|
112
|
+
cx: scale.x(x),
|
|
113
|
+
cy: scale.y(y),
|
|
114
|
+
r: 5
|
|
115
|
+
})) : null;
|
|
116
|
+
},
|
|
117
|
+
SmallCorrectPointIndicator: function SmallCorrectPointIndicator(_ref5) {
|
|
118
|
+
var scale = _ref5.scale,
|
|
119
|
+
x = _ref5.x,
|
|
120
|
+
correctness = _ref5.correctness,
|
|
121
|
+
correctData = _ref5.correctData,
|
|
122
|
+
label = _ref5.label;
|
|
123
|
+
return correctness && correctness.value === 'incorrect' && correctData ? /*#__PURE__*/_react["default"].createElement("g", {
|
|
124
|
+
"data-testid": "small-correct-indicator"
|
|
125
|
+
}, /*#__PURE__*/_react["default"].createElement("circle", {
|
|
126
|
+
cx: scale.x(x),
|
|
127
|
+
cy: scale.y(0),
|
|
128
|
+
r: 3
|
|
129
|
+
})) : null;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
var theme;
|
|
134
|
+
beforeAll(function () {
|
|
135
|
+
theme = (0, _styles.createTheme)();
|
|
136
|
+
});
|
|
137
|
+
describe('LineChart', function () {
|
|
138
|
+
var renderComponent = function renderComponent(extras) {
|
|
139
|
+
var defaults = {
|
|
140
|
+
classes: {},
|
|
141
|
+
className: 'className',
|
|
142
|
+
graphProps: (0, _utils.graphProps)(),
|
|
143
|
+
data: [],
|
|
144
|
+
xBand: function xBand() {
|
|
145
|
+
return {
|
|
146
|
+
bandwidth: function bandwidth() {}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var props = _objectSpread(_objectSpread({}, defaults), extras);
|
|
151
|
+
return (0, _testUtils.render)(/*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
|
|
152
|
+
theme: theme
|
|
153
|
+
}, /*#__PURE__*/_react["default"].createElement(_lineCross.LineCross, props)));
|
|
154
|
+
};
|
|
155
|
+
describe('rendering', function () {
|
|
156
|
+
it('renders line cross chart', function () {
|
|
157
|
+
var _renderComponent = renderComponent(),
|
|
158
|
+
container = _renderComponent.container;
|
|
159
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
160
|
+
});
|
|
161
|
+
it('renders with data points', function () {
|
|
162
|
+
var data = [{
|
|
163
|
+
x: 1,
|
|
164
|
+
y: 2,
|
|
165
|
+
label: 'A'
|
|
166
|
+
}, {
|
|
167
|
+
x: 2,
|
|
168
|
+
y: 3,
|
|
169
|
+
label: 'B'
|
|
170
|
+
}];
|
|
171
|
+
var _renderComponent2 = renderComponent({
|
|
172
|
+
data: data
|
|
173
|
+
}),
|
|
174
|
+
getByTestId = _renderComponent2.getByTestId;
|
|
175
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
176
|
+
});
|
|
177
|
+
it('renders without data', function () {
|
|
178
|
+
var _renderComponent3 = renderComponent({
|
|
179
|
+
data: []
|
|
180
|
+
}),
|
|
181
|
+
getByTestId = _renderComponent3.getByTestId;
|
|
182
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
183
|
+
});
|
|
184
|
+
it('passes graphProps to RawLine', function () {
|
|
185
|
+
var customGraphProps = (0, _utils.graphProps)(0, 10, 0, 10);
|
|
186
|
+
var _renderComponent4 = renderComponent({
|
|
187
|
+
graphProps: customGraphProps
|
|
188
|
+
}),
|
|
189
|
+
getByTestId = _renderComponent4.getByTestId;
|
|
190
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
191
|
+
});
|
|
192
|
+
it('passes onChange to RawLine', function () {
|
|
193
|
+
var onChange = jest.fn();
|
|
194
|
+
var _renderComponent5 = renderComponent({
|
|
195
|
+
onChange: onChange
|
|
196
|
+
}),
|
|
197
|
+
getByTestId = _renderComponent5.getByTestId;
|
|
198
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
describe('xBand calculation', function () {
|
|
202
|
+
it('calculates xBand from data', function () {
|
|
203
|
+
var data = [{
|
|
204
|
+
x: 1,
|
|
205
|
+
y: 2
|
|
206
|
+
}];
|
|
207
|
+
var _renderComponent6 = renderComponent({
|
|
208
|
+
data: data
|
|
209
|
+
}),
|
|
210
|
+
getByTestId = _renderComponent6.getByTestId;
|
|
211
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
212
|
+
});
|
|
213
|
+
it('handles empty data for xBand', function () {
|
|
214
|
+
var _renderComponent7 = renderComponent({
|
|
215
|
+
data: []
|
|
216
|
+
}),
|
|
217
|
+
getByTestId = _renderComponent7.getByTestId;
|
|
218
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe('component', function () {
|
|
222
|
+
it('returns correct chart object', function () {
|
|
223
|
+
var chart = (0, _lineCross["default"])();
|
|
224
|
+
expect(chart).toEqual({
|
|
225
|
+
type: 'lineCross',
|
|
226
|
+
Component: _lineCross.LineCross,
|
|
227
|
+
name: 'Line Cross'
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
it('returns object with correct type', function () {
|
|
231
|
+
var chart = (0, _lineCross["default"])();
|
|
232
|
+
expect(chart.type).toBe('lineCross');
|
|
233
|
+
});
|
|
234
|
+
it('returns object with correct name', function () {
|
|
235
|
+
var chart = (0, _lineCross["default"])();
|
|
236
|
+
expect(chart.name).toBe('Line Cross');
|
|
237
|
+
});
|
|
238
|
+
it('returns object with LineCross component', function () {
|
|
239
|
+
var chart = (0, _lineCross["default"])();
|
|
240
|
+
expect(chart.Component).toBe(_lineCross.LineCross);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe('edge cases', function () {
|
|
244
|
+
it('handles null data', function () {
|
|
245
|
+
var _renderComponent8 = renderComponent({
|
|
246
|
+
data: null
|
|
247
|
+
}),
|
|
248
|
+
getByTestId = _renderComponent8.getByTestId;
|
|
249
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
250
|
+
});
|
|
251
|
+
it('handles undefined graphProps', function () {
|
|
252
|
+
var _renderComponent9 = renderComponent({
|
|
253
|
+
graphProps: undefined
|
|
254
|
+
}),
|
|
255
|
+
container = _renderComponent9.container;
|
|
256
|
+
expect(container).toBeInTheDocument();
|
|
257
|
+
});
|
|
258
|
+
it('handles missing scale in graphProps', function () {
|
|
259
|
+
var _renderComponent0 = renderComponent({
|
|
260
|
+
graphProps: {
|
|
261
|
+
size: {
|
|
262
|
+
width: 400,
|
|
263
|
+
height: 400
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}),
|
|
267
|
+
container = _renderComponent0.container;
|
|
268
|
+
expect(container).toBeInTheDocument();
|
|
269
|
+
});
|
|
270
|
+
it('handles missing size in graphProps', function () {
|
|
271
|
+
var _renderComponent1 = renderComponent({
|
|
272
|
+
graphProps: {
|
|
273
|
+
scale: (0, _utils.graphProps)().scale
|
|
274
|
+
}
|
|
275
|
+
}),
|
|
276
|
+
container = _renderComponent1.container;
|
|
277
|
+
expect(container).toBeInTheDocument();
|
|
278
|
+
});
|
|
279
|
+
it('renders with className', function () {
|
|
280
|
+
var _renderComponent10 = renderComponent({
|
|
281
|
+
className: 'custom-class'
|
|
282
|
+
}),
|
|
283
|
+
container = _renderComponent10.container;
|
|
284
|
+
expect(container).toBeInTheDocument();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
describe('data with correctness', function () {
|
|
288
|
+
it('renders data with correct answers', function () {
|
|
289
|
+
var data = [{
|
|
290
|
+
x: 1,
|
|
291
|
+
y: 2,
|
|
292
|
+
label: 'A',
|
|
293
|
+
correctness: {
|
|
294
|
+
value: 'correct',
|
|
295
|
+
label: 'Correct!'
|
|
296
|
+
},
|
|
297
|
+
interactive: true
|
|
298
|
+
}];
|
|
299
|
+
var _renderComponent11 = renderComponent({
|
|
300
|
+
data: data
|
|
301
|
+
}),
|
|
302
|
+
getByTestId = _renderComponent11.getByTestId;
|
|
303
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
304
|
+
});
|
|
305
|
+
it('renders data with incorrect answers', function () {
|
|
306
|
+
var data = [{
|
|
307
|
+
x: 1,
|
|
308
|
+
y: 2,
|
|
309
|
+
label: 'A',
|
|
310
|
+
correctness: {
|
|
311
|
+
value: 'incorrect',
|
|
312
|
+
label: 'Wrong'
|
|
313
|
+
},
|
|
314
|
+
interactive: true
|
|
315
|
+
}];
|
|
316
|
+
var correctData = [{
|
|
317
|
+
label: 'A',
|
|
318
|
+
value: 3
|
|
319
|
+
}];
|
|
320
|
+
var _renderComponent12 = renderComponent({
|
|
321
|
+
data: data,
|
|
322
|
+
correctData: correctData
|
|
323
|
+
}),
|
|
324
|
+
getByTestId = _renderComponent12.getByTestId;
|
|
325
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
326
|
+
});
|
|
327
|
+
it('renders non-interactive data', function () {
|
|
328
|
+
var data = [{
|
|
329
|
+
x: 1,
|
|
330
|
+
y: 2,
|
|
331
|
+
label: 'A',
|
|
332
|
+
interactive: false
|
|
333
|
+
}];
|
|
334
|
+
var _renderComponent13 = renderComponent({
|
|
335
|
+
data: data
|
|
336
|
+
}),
|
|
337
|
+
getByTestId = _renderComponent13.getByTestId;
|
|
338
|
+
expect(getByTestId('raw-line')).toBeInTheDocument();
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
describe('DraggableComponent', function () {
|
|
343
|
+
// We need to test the DraggableComponent through LineCross since it's not exported
|
|
344
|
+
var renderLineCrossWithData = function renderLineCrossWithData() {
|
|
345
|
+
var dataExtras = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
346
|
+
var data = [_objectSpread({
|
|
347
|
+
x: 5,
|
|
348
|
+
y: 10,
|
|
349
|
+
label: 'A',
|
|
350
|
+
r: 8,
|
|
351
|
+
interactive: true
|
|
352
|
+
}, dataExtras)];
|
|
353
|
+
var props = {
|
|
354
|
+
graphProps: (0, _utils.graphProps)(),
|
|
355
|
+
data: data
|
|
356
|
+
};
|
|
357
|
+
return (0, _testUtils.render)(/*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
|
|
358
|
+
theme: theme
|
|
359
|
+
}, /*#__PURE__*/_react["default"].createElement(_lineCross.LineCross, props)));
|
|
360
|
+
};
|
|
361
|
+
describe('rendering', function () {
|
|
362
|
+
it('renders cross lines', function () {
|
|
363
|
+
var _renderLineCrossWithD = renderLineCrossWithData(),
|
|
364
|
+
getAllByTestId = _renderLineCrossWithD.getAllByTestId;
|
|
365
|
+
var linePaths = getAllByTestId('line-path');
|
|
366
|
+
expect(linePaths.length).toBeGreaterThan(0);
|
|
367
|
+
});
|
|
368
|
+
it('renders visx group', function () {
|
|
369
|
+
var _renderLineCrossWithD2 = renderLineCrossWithData(),
|
|
370
|
+
getByTestId = _renderLineCrossWithD2.getByTestId;
|
|
371
|
+
expect(getByTestId('visx-group')).toBeInTheDocument();
|
|
372
|
+
});
|
|
373
|
+
it('renders transparent handle circle', function () {
|
|
374
|
+
var _renderLineCrossWithD3 = renderLineCrossWithData(),
|
|
375
|
+
container = _renderLineCrossWithD3.container;
|
|
376
|
+
var circles = container.querySelectorAll('circle');
|
|
377
|
+
expect(circles.length).toBeGreaterThan(0);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
describe('hover interactions', function () {
|
|
381
|
+
it('renders interactive elements for hover', function () {
|
|
382
|
+
var _renderLineCrossWithD4 = renderLineCrossWithData(),
|
|
383
|
+
container = _renderLineCrossWithD4.container;
|
|
384
|
+
// The component should render, even if we can't test hover through the mock
|
|
385
|
+
expect(container).toBeInTheDocument();
|
|
386
|
+
});
|
|
387
|
+
it('component supports hover state changes', function () {
|
|
388
|
+
var _renderLineCrossWithD5 = renderLineCrossWithData(),
|
|
389
|
+
container = _renderLineCrossWithD5.container;
|
|
390
|
+
// Verify the component renders with interactive data
|
|
391
|
+
var svg = container.querySelector('svg');
|
|
392
|
+
expect(svg).toBeInTheDocument();
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
describe('correctness indicators', function () {
|
|
396
|
+
it('renders correctness indicator for correct answer', function () {
|
|
397
|
+
var _renderLineCrossWithD6 = renderLineCrossWithData({
|
|
398
|
+
correctness: {
|
|
399
|
+
value: 'correct',
|
|
400
|
+
label: 'Correct!'
|
|
401
|
+
}
|
|
402
|
+
}),
|
|
403
|
+
getByTestId = _renderLineCrossWithD6.getByTestId;
|
|
404
|
+
expect(getByTestId('correctness-indicator')).toBeInTheDocument();
|
|
405
|
+
});
|
|
406
|
+
it('does not render correctness indicator when not interactive', function () {
|
|
407
|
+
var _renderLineCrossWithD7 = renderLineCrossWithData({
|
|
408
|
+
correctness: {
|
|
409
|
+
value: 'correct',
|
|
410
|
+
label: 'Correct!'
|
|
411
|
+
},
|
|
412
|
+
interactive: false
|
|
413
|
+
}),
|
|
414
|
+
queryByTestId = _renderLineCrossWithD7.queryByTestId;
|
|
415
|
+
expect(queryByTestId('correctness-indicator')).not.toBeInTheDocument();
|
|
416
|
+
});
|
|
417
|
+
it('renders small correct indicator for incorrect answer', function () {
|
|
418
|
+
var data = [{
|
|
419
|
+
x: 5,
|
|
420
|
+
y: 10,
|
|
421
|
+
label: 'A',
|
|
422
|
+
correctness: {
|
|
423
|
+
value: 'incorrect',
|
|
424
|
+
label: 'Wrong'
|
|
425
|
+
},
|
|
426
|
+
interactive: true
|
|
427
|
+
}];
|
|
428
|
+
var correctData = [{
|
|
429
|
+
label: 'A',
|
|
430
|
+
value: 15
|
|
431
|
+
}];
|
|
432
|
+
var props = {
|
|
433
|
+
graphProps: (0, _utils.graphProps)(),
|
|
434
|
+
data: data,
|
|
435
|
+
correctData: correctData
|
|
436
|
+
};
|
|
437
|
+
var _render = (0, _testUtils.render)(/*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
|
|
438
|
+
theme: theme
|
|
439
|
+
}, /*#__PURE__*/_react["default"].createElement(_lineCross.LineCross, props))),
|
|
440
|
+
getByTestId = _render.getByTestId;
|
|
441
|
+
expect(getByTestId('small-correct-indicator')).toBeInTheDocument();
|
|
442
|
+
});
|
|
443
|
+
it('does not render small correct indicator for correct answer', function () {
|
|
444
|
+
var data = [{
|
|
445
|
+
x: 5,
|
|
446
|
+
y: 10,
|
|
447
|
+
label: 'A',
|
|
448
|
+
correctness: {
|
|
449
|
+
value: 'correct',
|
|
450
|
+
label: 'Correct!'
|
|
451
|
+
},
|
|
452
|
+
interactive: true
|
|
453
|
+
}];
|
|
454
|
+
var correctData = [{
|
|
455
|
+
label: 'A',
|
|
456
|
+
value: 15
|
|
457
|
+
}];
|
|
458
|
+
var props = {
|
|
459
|
+
graphProps: (0, _utils.graphProps)(),
|
|
460
|
+
data: data,
|
|
461
|
+
correctData: correctData
|
|
462
|
+
};
|
|
463
|
+
var _render2 = (0, _testUtils.render)(/*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
|
|
464
|
+
theme: theme
|
|
465
|
+
}, /*#__PURE__*/_react["default"].createElement(_lineCross.LineCross, props))),
|
|
466
|
+
queryByTestId = _render2.queryByTestId;
|
|
467
|
+
expect(queryByTestId('small-correct-indicator')).not.toBeInTheDocument();
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
describe('cross lines positioning', function () {
|
|
471
|
+
it('renders two cross lines for each point', function () {
|
|
472
|
+
var _renderLineCrossWithD8 = renderLineCrossWithData(),
|
|
473
|
+
getAllByTestId = _renderLineCrossWithD8.getAllByTestId;
|
|
474
|
+
var linePaths = getAllByTestId('line-path');
|
|
475
|
+
expect(linePaths.length).toBe(2); // Two lines per cross
|
|
476
|
+
});
|
|
477
|
+
it('positions cross lines correctly with scale', function () {
|
|
478
|
+
var _renderLineCrossWithD9 = renderLineCrossWithData({
|
|
479
|
+
x: 3,
|
|
480
|
+
y: 7
|
|
481
|
+
}),
|
|
482
|
+
getAllByTestId = _renderLineCrossWithD9.getAllByTestId;
|
|
483
|
+
var linePaths = getAllByTestId('line-path');
|
|
484
|
+
expect(linePaths.length).toBe(2);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
describe('edge cases', function () {
|
|
488
|
+
it('renders with zero coordinates', function () {
|
|
489
|
+
var _renderLineCrossWithD0 = renderLineCrossWithData({
|
|
490
|
+
x: 0,
|
|
491
|
+
y: 0
|
|
492
|
+
}),
|
|
493
|
+
container = _renderLineCrossWithD0.container;
|
|
494
|
+
expect(container).toBeInTheDocument();
|
|
495
|
+
});
|
|
496
|
+
it('renders with negative coordinates', function () {
|
|
497
|
+
var _renderLineCrossWithD1 = renderLineCrossWithData({
|
|
498
|
+
x: -5,
|
|
499
|
+
y: -10
|
|
500
|
+
}),
|
|
501
|
+
container = _renderLineCrossWithD1.container;
|
|
502
|
+
expect(container).toBeInTheDocument();
|
|
503
|
+
});
|
|
504
|
+
it('renders with large coordinates', function () {
|
|
505
|
+
var _renderLineCrossWithD10 = renderLineCrossWithData({
|
|
506
|
+
x: 1000,
|
|
507
|
+
y: 2000
|
|
508
|
+
}),
|
|
509
|
+
container = _renderLineCrossWithD10.container;
|
|
510
|
+
expect(container).toBeInTheDocument();
|
|
511
|
+
});
|
|
512
|
+
it('renders without correctness', function () {
|
|
513
|
+
var _renderLineCrossWithD11 = renderLineCrossWithData({
|
|
514
|
+
correctness: null
|
|
515
|
+
}),
|
|
516
|
+
container = _renderLineCrossWithD11.container;
|
|
517
|
+
expect(container).toBeInTheDocument();
|
|
518
|
+
});
|
|
519
|
+
it('renders without label', function () {
|
|
520
|
+
var _renderLineCrossWithD12 = renderLineCrossWithData({
|
|
521
|
+
label: undefined
|
|
522
|
+
}),
|
|
523
|
+
container = _renderLineCrossWithD12.container;
|
|
524
|
+
expect(container).toBeInTheDocument();
|
|
525
|
+
});
|
|
526
|
+
it('handles custom radius', function () {
|
|
527
|
+
var _renderLineCrossWithD13 = renderLineCrossWithData({
|
|
528
|
+
r: 12
|
|
529
|
+
}),
|
|
530
|
+
container = _renderLineCrossWithD13.container;
|
|
531
|
+
expect(container).toBeInTheDocument();
|
|
532
|
+
});
|
|
533
|
+
it('applies className', function () {
|
|
534
|
+
var _renderLineCrossWithD14 = renderLineCrossWithData({
|
|
535
|
+
className: 'custom-cross'
|
|
536
|
+
}),
|
|
537
|
+
getByTestId = _renderLineCrossWithD14.getByTestId;
|
|
538
|
+
var group = getByTestId('visx-group');
|
|
539
|
+
expect(group).toBeInTheDocument();
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
describe('hover rect sizing', function () {
|
|
543
|
+
it('component supports hover rect with proper sizing', function () {
|
|
544
|
+
var _renderLineCrossWithD15 = renderLineCrossWithData({
|
|
545
|
+
r: 10
|
|
546
|
+
}),
|
|
547
|
+
container = _renderLineCrossWithD15.container;
|
|
548
|
+
// Verify the component renders with custom radius
|
|
549
|
+
expect(container).toBeInTheDocument();
|
|
550
|
+
});
|
|
551
|
+
it('component supports hover rect centering', function () {
|
|
552
|
+
var _renderLineCrossWithD16 = renderLineCrossWithData({
|
|
553
|
+
x: 5,
|
|
554
|
+
y: 10,
|
|
555
|
+
r: 8
|
|
556
|
+
}),
|
|
557
|
+
container = _renderLineCrossWithD16.container;
|
|
558
|
+
// Verify the component renders at specified coordinates
|
|
559
|
+
expect(container).toBeInTheDocument();
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
describe('multiple data points', function () {
|
|
563
|
+
it('renders multiple crosses for multiple data points', function () {
|
|
564
|
+
var data = [{
|
|
565
|
+
x: 1,
|
|
566
|
+
y: 2,
|
|
567
|
+
label: 'A',
|
|
568
|
+
interactive: true
|
|
569
|
+
}, {
|
|
570
|
+
x: 3,
|
|
571
|
+
y: 4,
|
|
572
|
+
label: 'B',
|
|
573
|
+
interactive: true
|
|
574
|
+
}, {
|
|
575
|
+
x: 5,
|
|
576
|
+
y: 6,
|
|
577
|
+
label: 'C',
|
|
578
|
+
interactive: true
|
|
579
|
+
}];
|
|
580
|
+
var props = {
|
|
581
|
+
graphProps: (0, _utils.graphProps)(),
|
|
582
|
+
data: data
|
|
583
|
+
};
|
|
584
|
+
var _render3 = (0, _testUtils.render)(/*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
|
|
585
|
+
theme: theme
|
|
586
|
+
}, /*#__PURE__*/_react["default"].createElement(_lineCross.LineCross, props))),
|
|
587
|
+
getAllByTestId = _render3.getAllByTestId;
|
|
588
|
+
var groups = getAllByTestId('visx-group');
|
|
589
|
+
expect(groups.length).toBe(3);
|
|
590
|
+
});
|
|
591
|
+
it('renders multiple data points with proper structure', function () {
|
|
592
|
+
var data = [{
|
|
593
|
+
x: 1,
|
|
594
|
+
y: 2,
|
|
595
|
+
label: 'A',
|
|
596
|
+
interactive: true
|
|
597
|
+
}, {
|
|
598
|
+
x: 3,
|
|
599
|
+
y: 4,
|
|
600
|
+
label: 'B',
|
|
601
|
+
interactive: true
|
|
602
|
+
}];
|
|
603
|
+
var props = {
|
|
604
|
+
graphProps: (0, _utils.graphProps)(),
|
|
605
|
+
data: data
|
|
606
|
+
};
|
|
607
|
+
var _render4 = (0, _testUtils.render)(/*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
|
|
608
|
+
theme: theme
|
|
609
|
+
}, /*#__PURE__*/_react["default"].createElement(_lineCross.LineCross, props))),
|
|
610
|
+
container = _render4.container;
|
|
611
|
+
|
|
612
|
+
// Should render the component with multiple data points
|
|
613
|
+
expect(container).toBeInTheDocument();
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
//# sourceMappingURL=line-cross.test.js.map
|