@pie-lib/graphing-solution-set 4.1.0-beta.7 → 4.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.
- package/package.json +3 -3
- package/lib/__tests__/bg.test.js +0 -282
- package/lib/__tests__/bg.test.js.map +0 -1
- package/lib/__tests__/coordinates-label.test.js +0 -276
- package/lib/__tests__/coordinates-label.test.js.map +0 -1
- package/lib/__tests__/graph-with-controls.test.js +0 -256
- package/lib/__tests__/graph-with-controls.test.js.map +0 -1
- package/lib/__tests__/graph.test.js +0 -113
- package/lib/__tests__/graph.test.js.map +0 -1
- package/lib/__tests__/grid-setup.test.js +0 -729
- package/lib/__tests__/grid-setup.test.js.map +0 -1
- package/lib/__tests__/grid.test.js +0 -29
- package/lib/__tests__/grid.test.js.map +0 -1
- package/lib/__tests__/labels.test.js +0 -45
- package/lib/__tests__/labels.test.js.map +0 -1
- package/lib/__tests__/mark-label.test.js +0 -133
- package/lib/__tests__/mark-label.test.js.map +0 -1
- package/lib/__tests__/toggle-bar.test.js +0 -146
- package/lib/__tests__/toggle-bar.test.js.map +0 -1
- package/lib/__tests__/tool-menu.test.js +0 -540
- package/lib/__tests__/tool-menu.test.js.map +0 -1
- package/lib/__tests__/undo-redo.test.js +0 -31
- package/lib/__tests__/undo-redo.test.js.map +0 -1
- package/lib/__tests__/use-debounce.test.js +0 -24
- package/lib/__tests__/use-debounce.test.js.map +0 -1
- package/lib/__tests__/utils.js +0 -70
- package/lib/__tests__/utils.js.map +0 -1
- package/lib/__tests__/utils.test.js +0 -123
- package/lib/__tests__/utils.test.js.map +0 -1
- package/lib/axis/__tests__/arrow.test.js +0 -60
- package/lib/axis/__tests__/arrow.test.js.map +0 -1
- package/lib/axis/__tests__/axes.test.js +0 -160
- package/lib/axis/__tests__/axes.test.js.map +0 -1
- package/lib/container/__tests__/actions.test.js +0 -108
- package/lib/container/__tests__/actions.test.js.map +0 -1
- package/lib/container/__tests__/index.test.js +0 -346
- package/lib/container/__tests__/index.test.js.map +0 -1
- package/lib/container/__tests__/marks.test.js +0 -259
- package/lib/container/__tests__/marks.test.js.map +0 -1
- package/lib/container/__tests__/middleware.test.js +0 -244
- package/lib/container/__tests__/middleware.test.js.map +0 -1
- package/lib/container/__tests__/reducer.test.js +0 -450
- package/lib/container/__tests__/reducer.test.js.map +0 -1
- package/lib/tools/line/__tests__/component.test.js +0 -45
- package/lib/tools/line/__tests__/component.test.js.map +0 -1
- package/lib/tools/polygon/__tests__/component.test.js +0 -501
- package/lib/tools/polygon/__tests__/component.test.js.map +0 -1
- package/lib/tools/polygon/__tests__/index.test.js +0 -92
- package/lib/tools/polygon/__tests__/index.test.js.map +0 -1
- package/lib/tools/polygon/__tests__/line.test.js +0 -30
- package/lib/tools/polygon/__tests__/line.test.js.map +0 -1
- package/lib/tools/polygon/__tests__/polygon.test.js +0 -61
- package/lib/tools/polygon/__tests__/polygon.test.js.map +0 -1
- package/lib/tools/shared/__tests__/arrow-head.test.js +0 -45
- package/lib/tools/shared/__tests__/arrow-head.test.js.map +0 -1
- package/lib/tools/shared/line/__tests__/index.test.js +0 -725
- package/lib/tools/shared/line/__tests__/index.test.js.map +0 -1
- package/lib/tools/shared/line/__tests__/line-path.test.js +0 -64
- package/lib/tools/shared/line/__tests__/line-path.test.js.map +0 -1
- package/lib/tools/shared/line/__tests__/with-root-edge.test.js +0 -618
- package/lib/tools/shared/line/__tests__/with-root-edge.test.js.map +0 -1
- package/lib/tools/shared/point/__tests__/arrow-point.test.js +0 -127
- package/lib/tools/shared/point/__tests__/arrow-point.test.js.map +0 -1
- package/lib/tools/shared/point/__tests__/arrow.test.js +0 -619
- package/lib/tools/shared/point/__tests__/arrow.test.js.map +0 -1
- package/lib/tools/shared/point/__tests__/base-point.test.js +0 -122
- package/lib/tools/shared/point/__tests__/base-point.test.js.map +0 -1
- package/src/__tests__/bg.test.jsx +0 -250
- package/src/__tests__/coordinates-label.test.jsx +0 -243
- package/src/__tests__/graph-with-controls.test.jsx +0 -184
- package/src/__tests__/graph.test.jsx +0 -93
- package/src/__tests__/grid-setup.test.jsx +0 -645
- package/src/__tests__/grid.test.jsx +0 -23
- package/src/__tests__/labels.test.jsx +0 -41
- package/src/__tests__/mark-label.test.jsx +0 -66
- package/src/__tests__/toggle-bar.test.jsx +0 -106
- package/src/__tests__/tool-menu.test.jsx +0 -453
- package/src/__tests__/undo-redo.test.jsx +0 -26
- package/src/__tests__/use-debounce.test.js +0 -21
- package/src/__tests__/utils.js +0 -41
- package/src/__tests__/utils.test.js +0 -105
- package/src/axis/__tests__/arrow.test.jsx +0 -43
- package/src/axis/__tests__/axes.test.jsx +0 -182
- package/src/container/__tests__/actions.test.js +0 -105
- package/src/container/__tests__/index.test.jsx +0 -227
- package/src/container/__tests__/marks.test.js +0 -172
- package/src/container/__tests__/middleware.test.js +0 -235
- package/src/container/__tests__/reducer.test.js +0 -324
- package/src/tools/line/__tests__/component.test.jsx +0 -37
- package/src/tools/polygon/__tests__/component.test.jsx +0 -487
- package/src/tools/polygon/__tests__/index.test.js +0 -65
- package/src/tools/polygon/__tests__/line.test.jsx +0 -23
- package/src/tools/polygon/__tests__/polygon.test.jsx +0 -44
- package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -33
- package/src/tools/shared/line/__tests__/index.test.jsx +0 -553
- package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -56
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -488
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
- package/src/tools/shared/point/__tests__/arrow.test.jsx +0 -469
- package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
package/src/__tests__/utils.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export const scaleMock = () => {
|
|
2
|
-
const fn = jest.fn((n) => n);
|
|
3
|
-
fn.invert = jest.fn((n) => n);
|
|
4
|
-
fn.domain = jest.fn(() => fn);
|
|
5
|
-
fn.range = jest.fn(() => fn);
|
|
6
|
-
fn.copy = jest.fn(() => scaleMock());
|
|
7
|
-
return fn;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
11
|
-
scale: {
|
|
12
|
-
x: scaleMock(),
|
|
13
|
-
y: scaleMock(),
|
|
14
|
-
},
|
|
15
|
-
snap: {
|
|
16
|
-
x: jest.fn((n) => n),
|
|
17
|
-
y: jest.fn((n) => n),
|
|
18
|
-
},
|
|
19
|
-
domain: {
|
|
20
|
-
min: dmin,
|
|
21
|
-
max: dmax,
|
|
22
|
-
step: 1,
|
|
23
|
-
},
|
|
24
|
-
range: {
|
|
25
|
-
min: rmin,
|
|
26
|
-
max: rmax,
|
|
27
|
-
step: 1,
|
|
28
|
-
},
|
|
29
|
-
size: {
|
|
30
|
-
width: 400,
|
|
31
|
-
height: 400,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const xy = (x, y, index) => {
|
|
36
|
-
const out = { x, y, index };
|
|
37
|
-
if (!Number.isFinite(index)) {
|
|
38
|
-
delete out.index;
|
|
39
|
-
}
|
|
40
|
-
return out;
|
|
41
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import * as utils from '../utils';
|
|
2
|
-
|
|
3
|
-
const xy = (x, y) => ({ x, y });
|
|
4
|
-
|
|
5
|
-
const tick = (isMajor, v) => ({
|
|
6
|
-
major: isMajor,
|
|
7
|
-
value: v,
|
|
8
|
-
x: v,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const major = tick.bind(null, true);
|
|
12
|
-
const minor = tick.bind(null, false);
|
|
13
|
-
|
|
14
|
-
describe('utils', () => {
|
|
15
|
-
describe('polygonToArea', () => {
|
|
16
|
-
const assertPolygon = (points, area) => {
|
|
17
|
-
it(`converts ${points} -> ${area}`, () => {
|
|
18
|
-
const result = utils.polygonToArea(points);
|
|
19
|
-
expect(result).toEqual(area);
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
assertPolygon([xy(0, 0), xy(1, 1), xy(1, -1)], {
|
|
23
|
-
left: 0,
|
|
24
|
-
top: 1,
|
|
25
|
-
bottom: -1,
|
|
26
|
-
right: 1,
|
|
27
|
-
});
|
|
28
|
-
assertPolygon([xy(0, 0), xy(3, 0), xy(2, -1), xy(4, -3), xy(1, -4), xy(2, -2)], {
|
|
29
|
-
left: 0,
|
|
30
|
-
top: 0,
|
|
31
|
-
bottom: -4,
|
|
32
|
-
right: 4,
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('lineToArea', () => {
|
|
37
|
-
const assertLine = (from, to, expected) => {
|
|
38
|
-
it(`${from},${to} => ${expected}`, () => {
|
|
39
|
-
const result = utils.lineToArea(from, to);
|
|
40
|
-
expect(result).toEqual(expected);
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
assertLine(xy(1, 1), xy(2, 2), { left: 1, top: 2, bottom: 1, right: 2 });
|
|
45
|
-
assertLine(xy(-1, 4), xy(4, -3), {
|
|
46
|
-
left: -1,
|
|
47
|
-
top: 4,
|
|
48
|
-
bottom: -3,
|
|
49
|
-
right: 4,
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('getTickValues', () => {
|
|
54
|
-
const assertGetTickValues = (props, expected) => {
|
|
55
|
-
it(` => ${expected}`, () => {
|
|
56
|
-
const result = utils.getTickValues(props);
|
|
57
|
-
expect(result).toEqual(expected);
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
assertGetTickValues({ min: 0, max: 10, step: 1 }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
62
|
-
assertGetTickValues({ min: 0, max: 3, step: 0.5 }, [0, 0.5, 1, 1.5, 2, 2.5, 3]);
|
|
63
|
-
assertGetTickValues({ min: -0.2, max: 2, step: 0.6 }, [0, 0.6, 1.2, 1.8]);
|
|
64
|
-
assertGetTickValues({ min: -3.4, max: 6.2, step: 1.2 }, [0, -1.2, -2.4, 1.2, 2.4, 3.6, 4.8, 6]);
|
|
65
|
-
|
|
66
|
-
assertGetTickValues(
|
|
67
|
-
{ min: 0.6, max: 4.8, step: 0.3 },
|
|
68
|
-
[0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.2, 4.5, 4.8],
|
|
69
|
-
);
|
|
70
|
-
assertGetTickValues(
|
|
71
|
-
{ min: 0.5, max: 4.9, step: 0.3 },
|
|
72
|
-
[0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.2, 4.5, 4.8],
|
|
73
|
-
);
|
|
74
|
-
assertGetTickValues(
|
|
75
|
-
{ min: 0, max: 3, step: 0.125 },
|
|
76
|
-
[
|
|
77
|
-
0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, 1.125, 1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 2, 2.125, 2.25,
|
|
78
|
-
2.375, 2.5, 2.625, 2.75, 2.875, 3,
|
|
79
|
-
],
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('countWords', () => {
|
|
84
|
-
it('should return 1 if label is undefined', () => {
|
|
85
|
-
const label = undefined;
|
|
86
|
-
const result = utils.countWords(label);
|
|
87
|
-
|
|
88
|
-
expect(result).toEqual(1);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should return 1 if label is null', () => {
|
|
92
|
-
const label = null;
|
|
93
|
-
const result = utils.countWords(label);
|
|
94
|
-
|
|
95
|
-
expect(result).toEqual(1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should return 3 if label has 3 words', () => {
|
|
99
|
-
const label = 'Number of months';
|
|
100
|
-
const result = utils.countWords(label);
|
|
101
|
-
|
|
102
|
-
expect(result).toEqual(3);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { render } from '@pie-lib/test-utils';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Arrow } from '../arrow';
|
|
4
|
-
|
|
5
|
-
describe('Arrow', () => {
|
|
6
|
-
let onChange = jest.fn();
|
|
7
|
-
|
|
8
|
-
const renderComponent = (extras) => {
|
|
9
|
-
const defaults = {
|
|
10
|
-
classes: {},
|
|
11
|
-
className: 'className',
|
|
12
|
-
onChange,
|
|
13
|
-
scale: {
|
|
14
|
-
x: jest.fn((n) => n),
|
|
15
|
-
y: jest.fn((n) => n),
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const props = { ...defaults, ...extras };
|
|
19
|
-
return render(<Arrow {...props} />);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe('rendering', () => {
|
|
23
|
-
it('renders with direction up', () => {
|
|
24
|
-
const { container } = renderComponent({ direction: 'up' });
|
|
25
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('renders with direction down', () => {
|
|
29
|
-
const { container } = renderComponent({ direction: 'down' });
|
|
30
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('renders with direction left', () => {
|
|
34
|
-
const { container } = renderComponent({ direction: 'left' });
|
|
35
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('renders with direction right', () => {
|
|
39
|
-
const { container } = renderComponent({ direction: 'right' });
|
|
40
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { render } from '@pie-lib/test-utils';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { graphProps } from '../../__tests__/utils';
|
|
4
|
-
|
|
5
|
-
import { firstNegativeValue, RawXAxis, RawYAxis, sharedValues } from '../axes';
|
|
6
|
-
|
|
7
|
-
describe('RawXAxis', () => {
|
|
8
|
-
let onChange = jest.fn();
|
|
9
|
-
|
|
10
|
-
const renderComponent = (extras) => {
|
|
11
|
-
const defaults = {
|
|
12
|
-
classes: {},
|
|
13
|
-
className: 'className',
|
|
14
|
-
onChange,
|
|
15
|
-
graphProps: graphProps(),
|
|
16
|
-
includeArrows: {
|
|
17
|
-
left: true,
|
|
18
|
-
right: true,
|
|
19
|
-
up: true,
|
|
20
|
-
down: true,
|
|
21
|
-
},
|
|
22
|
-
columnTicksValues: [-1, 0, 1],
|
|
23
|
-
skipValues: [],
|
|
24
|
-
distanceFromOriginToFirstNegativeY: 0,
|
|
25
|
-
dy: 0,
|
|
26
|
-
};
|
|
27
|
-
const props = { ...defaults, ...extras };
|
|
28
|
-
return render(<RawXAxis {...props} />);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('rendering', () => {
|
|
32
|
-
it('renders without crashing', () => {
|
|
33
|
-
const { container } = renderComponent();
|
|
34
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('RawYAxis', () => {
|
|
40
|
-
let onChange = jest.fn();
|
|
41
|
-
|
|
42
|
-
const renderComponent = (extras) => {
|
|
43
|
-
const defaults = {
|
|
44
|
-
classes: {},
|
|
45
|
-
className: 'className',
|
|
46
|
-
onChange,
|
|
47
|
-
graphProps: graphProps(),
|
|
48
|
-
includeArrows: {
|
|
49
|
-
left: true,
|
|
50
|
-
right: true,
|
|
51
|
-
up: true,
|
|
52
|
-
down: true,
|
|
53
|
-
},
|
|
54
|
-
rowTickValues: [-1, 0, 1],
|
|
55
|
-
skipValues: [],
|
|
56
|
-
};
|
|
57
|
-
const props = { ...defaults, ...extras };
|
|
58
|
-
return render(<RawYAxis {...props} />);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
describe('rendering', () => {
|
|
62
|
-
it('renders without crashing', () => {
|
|
63
|
-
const { container } = renderComponent();
|
|
64
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const customScaleMock = (distance) => {
|
|
70
|
-
const fn = jest.fn((n) => n * distance);
|
|
71
|
-
fn.invert = jest.fn((n) => n * distance);
|
|
72
|
-
fn.domain = jest.fn(() => fn);
|
|
73
|
-
fn.range = jest.fn(() => fn);
|
|
74
|
-
fn.copy = jest.fn(() => customScaleMock(distance));
|
|
75
|
-
return fn;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// Note: Instance method tests (xValues, yValues) have been removed.
|
|
79
|
-
// These methods are internal implementation details and should be tested through
|
|
80
|
-
// component rendering and integration tests that verify the axes render correctly.
|
|
81
|
-
|
|
82
|
-
describe('firstNegativeValue', () => {
|
|
83
|
-
it('should return undefined for undefined interval', () => {
|
|
84
|
-
const interval = undefined;
|
|
85
|
-
const result = firstNegativeValue(interval);
|
|
86
|
-
expect(result).toEqual(undefined);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should return undefined for empty interval', () => {
|
|
90
|
-
const interval = [];
|
|
91
|
-
const result = firstNegativeValue(interval);
|
|
92
|
-
expect(result).toEqual(undefined);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should return undefined if there is no negative in interval array', () => {
|
|
96
|
-
const interval = [1, 5, 7, 4, 5];
|
|
97
|
-
const result = firstNegativeValue(interval);
|
|
98
|
-
expect(result).toEqual(undefined);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should return first negative number from interval', () => {
|
|
102
|
-
const interval = [1, 5, 7, -2, 4, 5, -1];
|
|
103
|
-
const result = firstNegativeValue(interval);
|
|
104
|
-
expect(result).toEqual(-2);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('sharedValues', () => {
|
|
109
|
-
it('should be empty array if firstNegativeValue for one of the axes is undefined', () => {
|
|
110
|
-
// x
|
|
111
|
-
const intervalX = [1, 2, 3, 4, 5, 6];
|
|
112
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
113
|
-
const distanceFromOriginToFirstNegativeX = -22;
|
|
114
|
-
|
|
115
|
-
// y
|
|
116
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
117
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
118
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
119
|
-
|
|
120
|
-
const deltaAllowance = 5;
|
|
121
|
-
|
|
122
|
-
const result = sharedValues(
|
|
123
|
-
firstNegativeX,
|
|
124
|
-
firstNegativeY,
|
|
125
|
-
distanceFromOriginToFirstNegativeX,
|
|
126
|
-
distanceFromOriginToFirstNegativeY,
|
|
127
|
-
deltaAllowance,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
expect(result).toEqual([]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
|
|
134
|
-
// x
|
|
135
|
-
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
136
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
137
|
-
const distanceFromOriginToFirstNegativeX = -7;
|
|
138
|
-
|
|
139
|
-
// y
|
|
140
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
141
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
142
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
143
|
-
|
|
144
|
-
const deltaAllowance = 5;
|
|
145
|
-
|
|
146
|
-
const result = sharedValues(
|
|
147
|
-
firstNegativeX,
|
|
148
|
-
firstNegativeY,
|
|
149
|
-
distanceFromOriginToFirstNegativeX,
|
|
150
|
-
distanceFromOriginToFirstNegativeY,
|
|
151
|
-
deltaAllowance,
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
expect(result).toEqual([]);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
|
|
158
|
-
// x
|
|
159
|
-
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
160
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
161
|
-
const distanceFromOriginToFirstNegativeX = -20;
|
|
162
|
-
|
|
163
|
-
// y
|
|
164
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
165
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
166
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
167
|
-
|
|
168
|
-
const deltaAllowance = 5;
|
|
169
|
-
const dy = -20; // dy needs to be within the range for the condition to pass
|
|
170
|
-
|
|
171
|
-
const result = sharedValues(
|
|
172
|
-
firstNegativeX,
|
|
173
|
-
firstNegativeY,
|
|
174
|
-
distanceFromOriginToFirstNegativeX,
|
|
175
|
-
distanceFromOriginToFirstNegativeY,
|
|
176
|
-
deltaAllowance,
|
|
177
|
-
dy,
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
expect(result).toEqual([-1]);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { addMark, changeMarks } from '../actions';
|
|
2
|
-
|
|
3
|
-
describe('container actions', () => {
|
|
4
|
-
describe('addMark', () => {
|
|
5
|
-
it('creates ADD_MARK action', () => {
|
|
6
|
-
const action = addMark();
|
|
7
|
-
expect(action).toEqual({
|
|
8
|
-
type: 'ADD_MARK',
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('creates action without parameters', () => {
|
|
13
|
-
const action = addMark();
|
|
14
|
-
expect(action.type).toBe('ADD_MARK');
|
|
15
|
-
expect(Object.keys(action)).toEqual(['type']);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('changeMarks', () => {
|
|
20
|
-
it('creates CHANGE_MARKS action with marks', () => {
|
|
21
|
-
const marks = [{ id: 1, type: 'point' }];
|
|
22
|
-
const action = changeMarks(marks);
|
|
23
|
-
|
|
24
|
-
expect(action).toEqual({
|
|
25
|
-
type: 'CHANGE_MARKS',
|
|
26
|
-
marks,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('creates action with empty marks array', () => {
|
|
31
|
-
const marks = [];
|
|
32
|
-
const action = changeMarks(marks);
|
|
33
|
-
|
|
34
|
-
expect(action).toEqual({
|
|
35
|
-
type: 'CHANGE_MARKS',
|
|
36
|
-
marks: [],
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('creates action with multiple marks', () => {
|
|
41
|
-
const marks = [
|
|
42
|
-
{ id: 1, type: 'point', x: 1, y: 2 },
|
|
43
|
-
{ id: 2, type: 'line', from: { x: 0, y: 0 }, to: { x: 5, y: 5 } },
|
|
44
|
-
];
|
|
45
|
-
const action = changeMarks(marks);
|
|
46
|
-
|
|
47
|
-
expect(action.marks).toEqual(marks);
|
|
48
|
-
expect(action.marks.length).toBe(2);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('creates action with null marks', () => {
|
|
52
|
-
const marks = null;
|
|
53
|
-
const action = changeMarks(marks);
|
|
54
|
-
|
|
55
|
-
expect(action).toEqual({
|
|
56
|
-
type: 'CHANGE_MARKS',
|
|
57
|
-
marks: null,
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('creates action with undefined marks', () => {
|
|
62
|
-
const marks = undefined;
|
|
63
|
-
const action = changeMarks(marks);
|
|
64
|
-
|
|
65
|
-
expect(action).toEqual({
|
|
66
|
-
type: 'CHANGE_MARKS',
|
|
67
|
-
marks: undefined,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('preserves mark properties', () => {
|
|
72
|
-
const marks = [
|
|
73
|
-
{
|
|
74
|
-
id: 1,
|
|
75
|
-
type: 'point',
|
|
76
|
-
x: 10,
|
|
77
|
-
y: 20,
|
|
78
|
-
label: 'A',
|
|
79
|
-
correctness: { value: 'correct' },
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
const action = changeMarks(marks);
|
|
83
|
-
|
|
84
|
-
expect(action.marks[0]).toEqual(marks[0]);
|
|
85
|
-
expect(action.marks[0].correctness).toBeDefined();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('action types', () => {
|
|
90
|
-
it('has consistent action type strings', () => {
|
|
91
|
-
const addMarkAction = addMark();
|
|
92
|
-
const changeMarksAction = changeMarks([]);
|
|
93
|
-
|
|
94
|
-
expect(typeof addMarkAction.type).toBe('string');
|
|
95
|
-
expect(typeof changeMarksAction.type).toBe('string');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('has unique action types', () => {
|
|
99
|
-
const addMarkAction = addMark();
|
|
100
|
-
const changeMarksAction = changeMarks([]);
|
|
101
|
-
|
|
102
|
-
expect(addMarkAction.type).not.toBe(changeMarksAction.type);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@pie-lib/test-utils';
|
|
3
|
-
import Root, { GraphContainer } from '../index';
|
|
4
|
-
|
|
5
|
-
jest.mock('../../graph-with-controls', () => {
|
|
6
|
-
return function GraphWithControls({ marks, onChangeMarks, onUndo, onRedo, onReset, disabled }) {
|
|
7
|
-
return (
|
|
8
|
-
<div data-testid="graph-with-controls">
|
|
9
|
-
<div data-testid="marks-count">{marks?.length || 0}</div>
|
|
10
|
-
{disabled && <div data-testid="disabled-indicator">Disabled</div>}
|
|
11
|
-
<button data-testid="change-marks" onClick={() => onChangeMarks && onChangeMarks([{ id: 1 }])}>
|
|
12
|
-
Change
|
|
13
|
-
</button>
|
|
14
|
-
<button data-testid="undo" onClick={onUndo}>
|
|
15
|
-
Undo
|
|
16
|
-
</button>
|
|
17
|
-
<button data-testid="redo" onClick={onRedo}>
|
|
18
|
-
Redo
|
|
19
|
-
</button>
|
|
20
|
-
<button data-testid="reset" onClick={onReset}>
|
|
21
|
-
Reset
|
|
22
|
-
</button>
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
jest.mock('@pie-lib/drag', () => ({
|
|
29
|
-
DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
describe('Container Root Component', () => {
|
|
33
|
-
const defaultProps = {
|
|
34
|
-
marks: [],
|
|
35
|
-
onChangeMarks: jest.fn(),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const renderComponent = (props = {}) => {
|
|
39
|
-
return render(<Root {...defaultProps} {...props} />);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
describe('rendering', () => {
|
|
43
|
-
it('renders without crashing', () => {
|
|
44
|
-
const { container } = renderComponent();
|
|
45
|
-
expect(container).toBeInTheDocument();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('renders GraphWithControls', () => {
|
|
49
|
-
const { getByTestId } = renderComponent();
|
|
50
|
-
expect(getByTestId('graph-with-controls')).toBeInTheDocument();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('renders with Provider when no correctness set', () => {
|
|
54
|
-
const { container } = renderComponent({ marks: [{ id: 1, type: 'point' }] });
|
|
55
|
-
expect(container.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('renders directly when correctness is set', () => {
|
|
59
|
-
const marks = [{ id: 1, type: 'point', correctness: { value: 'correct' } }];
|
|
60
|
-
const { getByTestId } = renderComponent({ marks });
|
|
61
|
-
|
|
62
|
-
expect(getByTestId('graph-with-controls')).toBeInTheDocument();
|
|
63
|
-
expect(getByTestId('disabled-indicator')).toBeInTheDocument();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('passes marks to GraphWithControls', () => {
|
|
67
|
-
const marks = [{ id: 1 }, { id: 2 }];
|
|
68
|
-
const { getByTestId } = renderComponent({ marks });
|
|
69
|
-
expect(getByTestId('marks-count')).toHaveTextContent('2');
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('componentDidUpdate', () => {
|
|
74
|
-
it('updates store when marks prop changes', () => {
|
|
75
|
-
const onChangeMarks = jest.fn();
|
|
76
|
-
const { rerender } = render(<Root marks={[]} onChangeMarks={onChangeMarks} />);
|
|
77
|
-
|
|
78
|
-
const newMarks = [{ id: 1, type: 'point' }];
|
|
79
|
-
rerender(<Root marks={newMarks} onChangeMarks={onChangeMarks} />);
|
|
80
|
-
|
|
81
|
-
expect(onChangeMarks).not.toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('does not update when marks are equal', () => {
|
|
85
|
-
const marks = [{ id: 1, type: 'point' }];
|
|
86
|
-
const onChangeMarks = jest.fn();
|
|
87
|
-
const { rerender } = render(<Root marks={marks} onChangeMarks={onChangeMarks} />);
|
|
88
|
-
|
|
89
|
-
onChangeMarks.mockClear();
|
|
90
|
-
|
|
91
|
-
rerender(<Root marks={marks} onChangeMarks={onChangeMarks} />);
|
|
92
|
-
|
|
93
|
-
expect(onChangeMarks).not.toHaveBeenCalled();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('handles marks changing from empty to non-empty', () => {
|
|
97
|
-
const onChangeMarks = jest.fn();
|
|
98
|
-
const { rerender } = render(<Root marks={[]} onChangeMarks={onChangeMarks} />);
|
|
99
|
-
|
|
100
|
-
const newMarks = [{ id: 1 }];
|
|
101
|
-
|
|
102
|
-
expect(() => {
|
|
103
|
-
rerender(<Root marks={newMarks} onChangeMarks={onChangeMarks} />);
|
|
104
|
-
}).not.toThrow();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('handles marks changing from non-empty to empty', () => {
|
|
108
|
-
const onChangeMarks = jest.fn();
|
|
109
|
-
const { rerender } = render(<Root marks={[{ id: 1 }]} onChangeMarks={onChangeMarks} />);
|
|
110
|
-
|
|
111
|
-
expect(() => {
|
|
112
|
-
rerender(<Root marks={[]} onChangeMarks={onChangeMarks} />);
|
|
113
|
-
}).not.toThrow();
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('correctness handling', () => {
|
|
118
|
-
it('disables when any mark has correctness', () => {
|
|
119
|
-
const marks = [
|
|
120
|
-
{ id: 1, type: 'point' },
|
|
121
|
-
{ id: 2, type: 'point', correctness: { value: 'correct' } },
|
|
122
|
-
];
|
|
123
|
-
const { getByTestId } = renderComponent({ marks });
|
|
124
|
-
|
|
125
|
-
expect(getByTestId('disabled-indicator')).toBeInTheDocument();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('renders without Provider when correctness is set', () => {
|
|
129
|
-
const marks = [{ id: 1, correctness: { value: 'correct' } }];
|
|
130
|
-
const { container } = renderComponent({ marks });
|
|
131
|
-
|
|
132
|
-
expect(container.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('does not disable when no correctness is set', () => {
|
|
136
|
-
const marks = [
|
|
137
|
-
{ id: 1, type: 'point' },
|
|
138
|
-
{ id: 2, type: 'line' },
|
|
139
|
-
];
|
|
140
|
-
const { queryByTestId } = renderComponent({ marks });
|
|
141
|
-
|
|
142
|
-
expect(queryByTestId('disabled-indicator')).not.toBeInTheDocument();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('handles correctness with different values', () => {
|
|
146
|
-
const marks = [{ id: 1, correctness: { value: 'incorrect' } }];
|
|
147
|
-
const { getByTestId } = renderComponent({ marks });
|
|
148
|
-
|
|
149
|
-
expect(getByTestId('disabled-indicator')).toBeInTheDocument();
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('handles empty correctness object', () => {
|
|
153
|
-
const marks = [{ id: 1, correctness: {} }];
|
|
154
|
-
const { getByTestId } = renderComponent({ marks });
|
|
155
|
-
|
|
156
|
-
expect(getByTestId('disabled-indicator')).toBeInTheDocument();
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('props forwarding', () => {
|
|
161
|
-
it('forwards additional props to GraphWithControls', () => {
|
|
162
|
-
const { container } = renderComponent({
|
|
163
|
-
className: 'custom-class',
|
|
164
|
-
size: { width: 500, height: 500 },
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
expect(container.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('does not forward onChangeMarks and marks to GraphWithControls', () => {
|
|
171
|
-
const { getByTestId } = renderComponent({
|
|
172
|
-
marks: [{ id: 1 }],
|
|
173
|
-
onChangeMarks: jest.fn(),
|
|
174
|
-
otherProp: 'test',
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(getByTestId('graph-with-controls')).toBeInTheDocument();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('edge cases', () => {
|
|
182
|
-
it('handles empty marks array', () => {
|
|
183
|
-
const { container } = renderComponent({ marks: [] });
|
|
184
|
-
expect(container).toBeInTheDocument();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('handles marks with complex structure', () => {
|
|
188
|
-
const marks = [
|
|
189
|
-
{
|
|
190
|
-
id: 1,
|
|
191
|
-
type: 'line',
|
|
192
|
-
from: { x: 0, y: 0 },
|
|
193
|
-
to: { x: 10, y: 10 },
|
|
194
|
-
label: 'Line A',
|
|
195
|
-
correctness: { value: 'correct', label: 'Correct!' },
|
|
196
|
-
},
|
|
197
|
-
];
|
|
198
|
-
const { getByTestId } = renderComponent({ marks });
|
|
199
|
-
expect(getByTestId('graph-with-controls')).toBeInTheDocument();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('handles switching between correctness states', () => {
|
|
203
|
-
const { rerender } = render(<Root marks={[{ id: 1 }]} onChangeMarks={jest.fn()} />);
|
|
204
|
-
|
|
205
|
-
rerender(<Root marks={[{ id: 1, correctness: { value: 'correct' } }]} onChangeMarks={jest.fn()} />);
|
|
206
|
-
|
|
207
|
-
rerender(<Root marks={[{ id: 1 }]} onChangeMarks={jest.fn()} />);
|
|
208
|
-
|
|
209
|
-
expect(document.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe('GraphContainer (connected component)', () => {
|
|
215
|
-
it('is a connected component', () => {
|
|
216
|
-
expect(GraphContainer).toBeDefined();
|
|
217
|
-
expect(GraphContainer.displayName).toContain('Connect');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('maps state to props', () => {
|
|
221
|
-
expect(GraphContainer).toBeDefined();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('maps dispatch to props', () => {
|
|
225
|
-
expect(GraphContainer).toBeDefined();
|
|
226
|
-
});
|
|
227
|
-
});
|