@pie-lib/graphing 4.1.0-beta.8 → 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.
Files changed (49) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/bg.test.jsx +0 -250
  3. package/src/__tests__/coordinates-label.test.jsx +0 -243
  4. package/src/__tests__/graph-with-controls.test.jsx +0 -198
  5. package/src/__tests__/graph.test.jsx +0 -721
  6. package/src/__tests__/grid-setup.test.jsx +0 -645
  7. package/src/__tests__/grid.test.jsx +0 -22
  8. package/src/__tests__/key-legend.test.jsx +0 -260
  9. package/src/__tests__/label-svg-icon.test.jsx +0 -278
  10. package/src/__tests__/labels.test.jsx +0 -55
  11. package/src/__tests__/mark-label.test.jsx +0 -63
  12. package/src/__tests__/toggle-bar.test.jsx +0 -146
  13. package/src/__tests__/tool-menu.test.jsx +0 -115
  14. package/src/__tests__/undo-redo.test.jsx +0 -24
  15. package/src/__tests__/use-debounce.test.js +0 -21
  16. package/src/__tests__/utils.js +0 -41
  17. package/src/__tests__/utils.test.js +0 -105
  18. package/src/axis/__tests__/arrow.test.jsx +0 -38
  19. package/src/axis/__tests__/axes.test.jsx +0 -216
  20. package/src/container/__tests__/actions.test.js +0 -105
  21. package/src/container/__tests__/index.test.jsx +0 -319
  22. package/src/container/__tests__/marks.test.js +0 -172
  23. package/src/container/__tests__/middleware.test.js +0 -235
  24. package/src/container/__tests__/reducer.test.js +0 -324
  25. package/src/tools/absolute/__tests__/component.test.jsx +0 -53
  26. package/src/tools/circle/__tests__/bg-circle.test.jsx +0 -26
  27. package/src/tools/circle/__tests__/component.test.jsx +0 -494
  28. package/src/tools/circle/__tests__/index.test.js +0 -480
  29. package/src/tools/exponential/__tests__/component.test.jsx +0 -53
  30. package/src/tools/exponential/__tests__/index.test.js +0 -729
  31. package/src/tools/line/__tests__/component.test.jsx +0 -37
  32. package/src/tools/parabola/__tests__/component.test.jsx +0 -48
  33. package/src/tools/parabola/__tests__/index.test.js +0 -470
  34. package/src/tools/point/__tests__/component.test.jsx +0 -349
  35. package/src/tools/point/__tests__/index.test.js +0 -241
  36. package/src/tools/polygon/__tests__/component.test.jsx +0 -471
  37. package/src/tools/polygon/__tests__/index.test.js +0 -294
  38. package/src/tools/polygon/__tests__/line.test.jsx +0 -35
  39. package/src/tools/polygon/__tests__/polygon.test.jsx +0 -61
  40. package/src/tools/ray/__tests__/component.test.jsx +0 -29
  41. package/src/tools/segment/__tests__/component.test.jsx +0 -28
  42. package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -31
  43. package/src/tools/shared/line/__tests__/index.test.jsx +0 -109
  44. package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -53
  45. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -73
  46. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
  47. package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
  48. package/src/tools/sine/__tests__/component.test.jsx +0 -51
  49. package/src/tools/vector/__tests__/component.test.jsx +0 -25
@@ -1,146 +0,0 @@
1
- import { render, screen } from '@pie-lib/test-utils';
2
- import userEvent from '@testing-library/user-event';
3
- import React from 'react';
4
-
5
- import { ToggleBar } from '../toggle-bar';
6
-
7
- jest.mock('@pie-lib/drag', () => ({
8
- DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
9
- }));
10
-
11
- jest.mock('@dnd-kit/core', () => ({
12
- useDraggable: jest.fn(() => ({
13
- attributes: {
14
- role: 'button',
15
- tabIndex: 0,
16
- },
17
- listeners: {
18
- onPointerDown: jest.fn(),
19
- },
20
- setNodeRef: jest.fn(),
21
- transform: null,
22
- transition: null,
23
- isDragging: false,
24
- })),
25
- useDroppable: jest.fn(() => ({
26
- setNodeRef: jest.fn(),
27
- isOver: false,
28
- active: null,
29
- })),
30
- }));
31
-
32
- jest.mock('@dnd-kit/utilities', () => ({
33
- CSS: {
34
- Transform: {
35
- toString: jest.fn((transform) => (transform ? 'translate3d(0, 0, 0)' : '')),
36
- },
37
- },
38
- }));
39
-
40
- jest.mock('@dnd-kit/sortable', () => ({
41
- arrayMove: jest.fn((array, from, to) => {
42
- const newArray = [...array];
43
- const [removed] = newArray.splice(from, 1);
44
- newArray.splice(to, 0, removed);
45
- return newArray;
46
- }),
47
- }));
48
-
49
- jest.mock('@pie-lib/translator', () => ({
50
- translator: {
51
- t: (key) => {
52
- const parts = key.split('.');
53
- return parts[parts.length - 1];
54
- },
55
- },
56
- }));
57
-
58
- describe('ToggleBar', () => {
59
- let onChange = jest.fn();
60
- let onChangeToolsOrder = jest.fn();
61
-
62
- beforeEach(() => {
63
- onChange.mockClear();
64
- onChangeToolsOrder.mockClear();
65
- });
66
-
67
- const renderComponent = (extras) => {
68
- const defaults = {
69
- className: 'className',
70
- onChange,
71
- onChangeToolsOrder,
72
- options: ['point', 'line'],
73
- language: 'en',
74
- };
75
- const props = { ...defaults, ...extras };
76
- return render(<ToggleBar {...props} />);
77
- };
78
-
79
- describe('rendering', () => {
80
- it('renders without crashing', () => {
81
- const { container } = renderComponent();
82
- expect(container.firstChild).toBeInTheDocument();
83
- });
84
-
85
- it('renders tool buttons for valid tools', () => {
86
- renderComponent({ options: ['point', 'line', 'circle'] });
87
- expect(screen.getByText(/point/i)).toBeInTheDocument();
88
- expect(screen.getByText(/line/i)).toBeInTheDocument();
89
- expect(screen.getByText(/circle/i)).toBeInTheDocument();
90
- });
91
-
92
- it('does not render invalid tool options', () => {
93
- renderComponent({ options: ['point', 'invalid-tool', 'line'] });
94
- expect(screen.getByText(/point/i)).toBeInTheDocument();
95
- expect(screen.getByText(/line/i)).toBeInTheDocument();
96
- expect(screen.queryByText(/invalid-tool/i)).not.toBeInTheDocument();
97
- });
98
-
99
- it('highlights selected tool', () => {
100
- const { container } = renderComponent({ selectedToolType: 'line' });
101
- const selectedButton = screen.getByText(/line/i).closest('button');
102
- expect(selectedButton).toHaveAttribute('value', 'line');
103
- });
104
- });
105
-
106
- describe('interactions', () => {
107
- it('calls onChange when tool button is clicked', async () => {
108
- const user = userEvent.setup();
109
- renderComponent({ options: ['point', 'line'] });
110
-
111
- const pointButton = screen.getByText(/point/i).closest('button');
112
- await user.click(pointButton);
113
-
114
- expect(onChange).toHaveBeenCalledWith('point');
115
- });
116
-
117
- it('calls onChange with selected tool type', async () => {
118
- const user = userEvent.setup();
119
- renderComponent({ options: ['point', 'line'], selectedToolType: 'point' });
120
-
121
- const lineButton = screen.getByText(/line/i).closest('button');
122
- await user.click(lineButton);
123
-
124
- expect(onChange).toHaveBeenCalledWith('line');
125
- });
126
-
127
- it('disables buttons when disabled prop is true', () => {
128
- renderComponent({ disabled: true, options: ['point', 'line'] });
129
-
130
- const pointButton = screen.getByText(/point/i).closest('button');
131
- const lineButton = screen.getByText(/line/i).closest('button');
132
-
133
- expect(pointButton).toBeDisabled();
134
- expect(lineButton).toBeDisabled();
135
- });
136
-
137
- it('does not call onChange when disabled', () => {
138
- renderComponent({ disabled: true, options: ['point'] });
139
-
140
- const pointButton = screen.getByText(/point/i).closest('button');
141
- expect(pointButton).toBeDisabled();
142
- // Note: Cannot test click on disabled button with pointer-events: none
143
- // The disabled state is verified above
144
- });
145
- });
146
- });
@@ -1,115 +0,0 @@
1
- import { render, screen } from '@pie-lib/test-utils';
2
- import userEvent from '@testing-library/user-event';
3
- import React from 'react';
4
-
5
- import ToolMenu from '../tool-menu';
6
-
7
- jest.mock('@pie-lib/drag', () => ({
8
- DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
9
- }));
10
-
11
- jest.mock('@dnd-kit/core', () => ({
12
- useDraggable: jest.fn(() => ({
13
- attributes: {
14
- role: 'button',
15
- tabIndex: 0,
16
- },
17
- listeners: {
18
- onPointerDown: jest.fn(),
19
- },
20
- setNodeRef: jest.fn(),
21
- transform: null,
22
- transition: null,
23
- isDragging: false,
24
- })),
25
- useDroppable: jest.fn(() => ({
26
- setNodeRef: jest.fn(),
27
- isOver: false,
28
- active: null,
29
- })),
30
- }));
31
-
32
- jest.mock('@dnd-kit/utilities', () => ({
33
- CSS: {
34
- Transform: {
35
- toString: jest.fn((transform) => (transform ? 'translate3d(0, 0, 0)' : '')),
36
- },
37
- },
38
- }));
39
-
40
- jest.mock('@dnd-kit/sortable', () => ({
41
- arrayMove: jest.fn((array, from, to) => {
42
- const newArray = [...array];
43
- const [removed] = newArray.splice(from, 1);
44
- newArray.splice(to, 0, removed);
45
- return newArray;
46
- }),
47
- }));
48
-
49
- describe('ToolMenu', () => {
50
- let onChange = jest.fn();
51
- let onChangeTools = jest.fn();
52
-
53
- beforeEach(() => {
54
- onChange.mockClear();
55
- onChangeTools.mockClear();
56
- });
57
-
58
- const renderComponent = (extras) => {
59
- const defaults = {
60
- className: 'className',
61
- onChange,
62
- onChangeTools,
63
- currentToolType: 'point',
64
- toolbarTools: ['point', 'line'],
65
- language: 'en',
66
- };
67
- const props = { ...defaults, ...extras };
68
- return render(<ToolMenu {...props} />);
69
- };
70
-
71
- describe('rendering', () => {
72
- it('renders without crashing', () => {
73
- const { container } = renderComponent();
74
- expect(container.firstChild).toBeInTheDocument();
75
- });
76
-
77
- it('renders ToggleBar with correct props', () => {
78
- renderComponent({ toolbarTools: ['point', 'line', 'circle'] });
79
- expect(screen.getByText(/point/i)).toBeInTheDocument();
80
- expect(screen.getByText(/line/i)).toBeInTheDocument();
81
- expect(screen.getByText(/circle/i)).toBeInTheDocument();
82
- });
83
-
84
- it('passes currentToolType to ToggleBar', () => {
85
- renderComponent({ currentToolType: 'line' });
86
- const selectedButton = screen.getByText(/line/i).closest('button');
87
- expect(selectedButton).toBeInTheDocument();
88
- });
89
- });
90
-
91
- describe('interactions', () => {
92
- it('calls onChange when tool is selected', async () => {
93
- const user = userEvent.setup();
94
- renderComponent();
95
-
96
- const lineButton = screen.getByText(/line/i).closest('button');
97
- await user.click(lineButton);
98
-
99
- expect(onChange).toHaveBeenCalledWith('line');
100
- });
101
-
102
- it('calls onChangeTools when tools order changes', () => {
103
- renderComponent({ draggableTools: true });
104
- // Note: Drag-and-drop testing requires more complex setup with @dnd-kit/test-utils
105
- // For now, we verify the component renders with draggableTools enabled
106
- expect(screen.getByText(/point/i)).toBeInTheDocument();
107
- });
108
-
109
- it('disables tools when disabled prop is true', () => {
110
- renderComponent({ disabled: true });
111
- const pointButton = screen.getByText(/point/i).closest('button');
112
- expect(pointButton).toBeDisabled();
113
- });
114
- });
115
- });
@@ -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
- });
@@ -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
- });