@pie-lib/graphing 4.0.22 → 4.0.24-beta.1
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 -88
- package/lib/mark-label.js +7 -197
- package/lib/mark-label.js.map +1 -1
- package/lib/tools/circle/component.js +3 -34
- package/lib/tools/circle/component.js.map +1 -1
- package/lib/tools/point/component.js +8 -29
- package/lib/tools/point/component.js.map +1 -1
- package/lib/tools/polygon/component.js +6 -31
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/shared/line/index.js +3 -34
- package/lib/tools/shared/line/index.js.map +1 -1
- package/package.json +17 -17
- package/src/mark-label.jsx +8 -209
- package/src/tools/circle/component.jsx +3 -26
- package/src/tools/point/component.jsx +8 -21
- package/src/tools/polygon/component.jsx +6 -24
- package/src/tools/shared/line/index.jsx +3 -26
- package/LICENSE.md +0 -5
- 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 -198
- package/src/__tests__/graph.test.jsx +0 -796
- package/src/__tests__/grid-setup.test.jsx +0 -645
- package/src/__tests__/grid.test.jsx +0 -22
- package/src/__tests__/key-legend.test.jsx +0 -260
- package/src/__tests__/label-svg-icon.test.jsx +0 -278
- package/src/__tests__/labels.test.jsx +0 -55
- package/src/__tests__/mark-label.test.jsx +0 -437
- package/src/__tests__/toggle-bar.test.jsx +0 -146
- package/src/__tests__/tool-menu.test.jsx +0 -115
- package/src/__tests__/undo-redo.test.jsx +0 -24
- 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 -38
- package/src/axis/__tests__/axes.test.jsx +0 -216
- package/src/container/__tests__/actions.test.js +0 -105
- package/src/container/__tests__/index.test.jsx +0 -319
- 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/absolute/__tests__/component.test.jsx +0 -53
- package/src/tools/circle/__tests__/bg-circle.test.jsx +0 -26
- package/src/tools/circle/__tests__/component.test.jsx +0 -494
- package/src/tools/circle/__tests__/index.test.js +0 -480
- package/src/tools/exponential/__tests__/component.test.jsx +0 -53
- package/src/tools/exponential/__tests__/index.test.js +0 -729
- package/src/tools/line/__tests__/component.test.jsx +0 -37
- package/src/tools/parabola/__tests__/component.test.jsx +0 -48
- package/src/tools/parabola/__tests__/index.test.js +0 -470
- package/src/tools/point/__tests__/component.test.jsx +0 -475
- package/src/tools/point/__tests__/index.test.js +0 -241
- package/src/tools/polygon/__tests__/component.test.jsx +0 -471
- package/src/tools/polygon/__tests__/index.test.js +0 -294
- package/src/tools/polygon/__tests__/line.test.jsx +0 -35
- package/src/tools/polygon/__tests__/polygon.test.jsx +0 -61
- package/src/tools/ray/__tests__/component.test.jsx +0 -29
- package/src/tools/segment/__tests__/component.test.jsx +0 -28
- package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -31
- package/src/tools/shared/line/__tests__/index.test.jsx +0 -109
- package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -53
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -73
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
- package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
- package/src/tools/sine/__tests__/component.test.jsx +0 -51
- package/src/tools/vector/__tests__/component.test.jsx +0 -25
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { render } from '@pie-lib/test-utils';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import UndoRedo from '../undo-redo';
|
|
4
|
-
|
|
5
|
-
describe('UndoRedo', () => {
|
|
6
|
-
let onUndo = jest.fn();
|
|
7
|
-
let onRedo = jest.fn();
|
|
8
|
-
let onReset = jest.fn();
|
|
9
|
-
const renderComponent = (extras) => {
|
|
10
|
-
const defaults = {
|
|
11
|
-
onUndo,
|
|
12
|
-
onRedo,
|
|
13
|
-
onReset,
|
|
14
|
-
};
|
|
15
|
-
const props = { ...defaults, ...extras };
|
|
16
|
-
return render(<UndoRedo {...props} />);
|
|
17
|
-
};
|
|
18
|
-
describe('rendering', () => {
|
|
19
|
-
it('renders without crashing', () => {
|
|
20
|
-
const { container } = renderComponent();
|
|
21
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { useDebounce } from '../use-debounce';
|
|
3
|
-
|
|
4
|
-
jest.useFakeTimers();
|
|
5
|
-
|
|
6
|
-
jest.mock('react', () => ({
|
|
7
|
-
useState: jest.fn(),
|
|
8
|
-
useEffect: jest.fn((fn, deps) => fn()),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe('useDebounce', () => {
|
|
12
|
-
it('..', () => {
|
|
13
|
-
const debouncedValue = null;
|
|
14
|
-
const setDebouncedValue = jest.fn();
|
|
15
|
-
|
|
16
|
-
useState.mockReturnValue([debouncedValue, setDebouncedValue]);
|
|
17
|
-
useDebounce('foo', 1000);
|
|
18
|
-
jest.runAllTimers();
|
|
19
|
-
expect(setDebouncedValue).toHaveBeenCalledWith('foo');
|
|
20
|
-
});
|
|
21
|
-
});
|
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,38 +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
|
-
const renderComponent = (extras) => {
|
|
8
|
-
const defaults = {
|
|
9
|
-
classes: {},
|
|
10
|
-
className: 'className',
|
|
11
|
-
onChange,
|
|
12
|
-
scale: {
|
|
13
|
-
x: jest.fn((n) => n),
|
|
14
|
-
y: jest.fn((n) => n),
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
const props = { ...defaults, ...extras };
|
|
18
|
-
return render(<Arrow {...props} />);
|
|
19
|
-
};
|
|
20
|
-
describe('rendering', () => {
|
|
21
|
-
it('renders with direction up', () => {
|
|
22
|
-
const { container } = renderComponent({ direction: 'up' });
|
|
23
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
24
|
-
});
|
|
25
|
-
it('renders with direction down', () => {
|
|
26
|
-
const { container } = renderComponent({ direction: 'down' });
|
|
27
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
28
|
-
});
|
|
29
|
-
it('renders with direction left', () => {
|
|
30
|
-
const { container } = renderComponent({ direction: 'left' });
|
|
31
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
32
|
-
});
|
|
33
|
-
it('renders with direction right', () => {
|
|
34
|
-
const { container } = renderComponent({ direction: 'right' });
|
|
35
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { render } from '@pie-lib/test-utils';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { graphProps } from '../../__tests__/utils';
|
|
4
|
-
|
|
5
|
-
import Axes, { firstNegativeValue, RawXAxis, RawYAxis, sharedValues } from '../axes';
|
|
6
|
-
|
|
7
|
-
describe('RawXAxis', () => {
|
|
8
|
-
let onChange = jest.fn();
|
|
9
|
-
const renderComponent = (extras) => {
|
|
10
|
-
const defaults = {
|
|
11
|
-
classes: {},
|
|
12
|
-
className: 'className',
|
|
13
|
-
onChange,
|
|
14
|
-
graphProps: graphProps(),
|
|
15
|
-
includeArrows: {
|
|
16
|
-
left: true,
|
|
17
|
-
right: true,
|
|
18
|
-
up: true,
|
|
19
|
-
down: true,
|
|
20
|
-
},
|
|
21
|
-
columnTicksValues: [-1, 0, 1],
|
|
22
|
-
skipValues: [],
|
|
23
|
-
distanceFromOriginToFirstNegativeY: 0,
|
|
24
|
-
dy: 0,
|
|
25
|
-
};
|
|
26
|
-
const props = { ...defaults, ...extras };
|
|
27
|
-
return render(<RawXAxis {...props} />);
|
|
28
|
-
};
|
|
29
|
-
describe('rendering', () => {
|
|
30
|
-
it('renders without crashing', () => {
|
|
31
|
-
const { container } = renderComponent();
|
|
32
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('RawYAxis', () => {
|
|
38
|
-
let onChange = jest.fn();
|
|
39
|
-
const renderComponent = (extras) => {
|
|
40
|
-
const defaults = {
|
|
41
|
-
classes: {},
|
|
42
|
-
className: 'className',
|
|
43
|
-
onChange,
|
|
44
|
-
graphProps: graphProps(),
|
|
45
|
-
includeArrows: {
|
|
46
|
-
left: true,
|
|
47
|
-
right: true,
|
|
48
|
-
up: true,
|
|
49
|
-
down: true,
|
|
50
|
-
},
|
|
51
|
-
rowTickValues: [-1, 0, 1],
|
|
52
|
-
skipValues: [],
|
|
53
|
-
};
|
|
54
|
-
const props = { ...defaults, ...extras };
|
|
55
|
-
return render(<RawYAxis {...props} />);
|
|
56
|
-
};
|
|
57
|
-
describe('rendering', () => {
|
|
58
|
-
it('renders without crashing', () => {
|
|
59
|
-
const { container } = renderComponent();
|
|
60
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const customScaleMock = (distance) => {
|
|
66
|
-
const fn = jest.fn((n) => n * distance);
|
|
67
|
-
fn.invert = jest.fn((n) => n * distance);
|
|
68
|
-
fn.domain = jest.fn(() => fn);
|
|
69
|
-
fn.range = jest.fn(() => fn);
|
|
70
|
-
fn.copy = jest.fn(() => customScaleMock(distance));
|
|
71
|
-
return fn;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
describe('Axes', () => {
|
|
75
|
-
let onChange = jest.fn();
|
|
76
|
-
|
|
77
|
-
const customGraphProps = {
|
|
78
|
-
...graphProps(),
|
|
79
|
-
domain: {
|
|
80
|
-
min: -2,
|
|
81
|
-
max: 2,
|
|
82
|
-
labelStep: 1,
|
|
83
|
-
step: 1,
|
|
84
|
-
},
|
|
85
|
-
range: {
|
|
86
|
-
min: -2,
|
|
87
|
-
max: 2,
|
|
88
|
-
step: 1,
|
|
89
|
-
labelStep: 1,
|
|
90
|
-
},
|
|
91
|
-
scale: {
|
|
92
|
-
x: customScaleMock(200),
|
|
93
|
-
y: customScaleMock(150),
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const renderComponent = (extras) => {
|
|
98
|
-
const defaults = {
|
|
99
|
-
classes: {},
|
|
100
|
-
className: 'className',
|
|
101
|
-
onChange,
|
|
102
|
-
graphProps: customGraphProps,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const props = { ...defaults, ...extras };
|
|
106
|
-
return render(<Axes {...props} />);
|
|
107
|
-
};
|
|
108
|
-
describe('rendering', () => {
|
|
109
|
-
it('renders without crashing', () => {
|
|
110
|
-
const { container } = renderComponent();
|
|
111
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('firstNegativeValue', () => {
|
|
117
|
-
it('should return undefined for undefined interval', () => {
|
|
118
|
-
const interval = undefined;
|
|
119
|
-
const result = firstNegativeValue(interval);
|
|
120
|
-
expect(result).toEqual(undefined);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should return undefined for empty interval', () => {
|
|
124
|
-
const interval = [];
|
|
125
|
-
const result = firstNegativeValue(interval);
|
|
126
|
-
expect(result).toEqual(undefined);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should return undefined if there is no negative in interval array', () => {
|
|
130
|
-
const interval = [1, 5, 7, 4, 5];
|
|
131
|
-
const result = firstNegativeValue(interval);
|
|
132
|
-
expect(result).toEqual(undefined);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should return first negative number from interval', () => {
|
|
136
|
-
const interval = [1, 5, 7, -2, 4, 5, -1];
|
|
137
|
-
const result = firstNegativeValue(interval);
|
|
138
|
-
expect(result).toEqual(-2);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('sharedValues', () => {
|
|
143
|
-
it('should be empty array if firstNegativeValue for one of the axes is undefined', () => {
|
|
144
|
-
// x
|
|
145
|
-
const intervalX = [1, 2, 3, 4, 5, 6];
|
|
146
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
147
|
-
const distanceFromOriginToFirstNegativeX = -22;
|
|
148
|
-
|
|
149
|
-
// y
|
|
150
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
151
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
152
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
153
|
-
|
|
154
|
-
const deltaAllowance = 5;
|
|
155
|
-
|
|
156
|
-
const result = sharedValues(
|
|
157
|
-
firstNegativeX,
|
|
158
|
-
firstNegativeY,
|
|
159
|
-
distanceFromOriginToFirstNegativeX,
|
|
160
|
-
distanceFromOriginToFirstNegativeY,
|
|
161
|
-
deltaAllowance,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
expect(result).toEqual([]);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
|
|
168
|
-
// x
|
|
169
|
-
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
170
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
171
|
-
const distanceFromOriginToFirstNegativeX = -7;
|
|
172
|
-
|
|
173
|
-
// y
|
|
174
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
175
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
176
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
177
|
-
|
|
178
|
-
const deltaAllowance = 5;
|
|
179
|
-
|
|
180
|
-
const result = sharedValues(
|
|
181
|
-
firstNegativeX,
|
|
182
|
-
firstNegativeY,
|
|
183
|
-
distanceFromOriginToFirstNegativeX,
|
|
184
|
-
distanceFromOriginToFirstNegativeY,
|
|
185
|
-
deltaAllowance,
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
expect(result).toEqual([]);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
|
|
192
|
-
// x
|
|
193
|
-
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
194
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
195
|
-
const distanceFromOriginToFirstNegativeX = -20;
|
|
196
|
-
|
|
197
|
-
// y
|
|
198
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
199
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
200
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
201
|
-
|
|
202
|
-
const deltaAllowance = 5;
|
|
203
|
-
const dy = -20; // dy needs to be within the range for the condition to pass
|
|
204
|
-
|
|
205
|
-
const result = sharedValues(
|
|
206
|
-
firstNegativeX,
|
|
207
|
-
firstNegativeY,
|
|
208
|
-
distanceFromOriginToFirstNegativeX,
|
|
209
|
-
distanceFromOriginToFirstNegativeY,
|
|
210
|
-
deltaAllowance,
|
|
211
|
-
dy,
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
expect(result).toEqual([-1]);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -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
|
-
});
|