-
-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathutils.test.js
More file actions
54 lines (46 loc) · 1.22 KB
/
utils.test.js
File metadata and controls
54 lines (46 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable max-len, no-undef */
import * as utils from '../src/utils';
describe('utils', () => {
describe('getClosestPoint', () => {
it('should return closest value', () => {
const value = 40;
const props = {
marks: { 0: 0, 30: 30, 60: 60 },
step: null,
min: 0,
max: 100
};
expect(utils.getClosestPoint(value, props)).toBe(30);
});
it('should return closest value (taking step into account)', () => {
const value = 40;
const props = {
marks: { 0: 0, 30: 30, 60: 60 },
step: 3,
min: 0,
max: 100
};
expect(utils.getClosestPoint(value, props)).toBe(39);
});
it('should return closest value (taking boundaries into account)', () => {
const value = 102;
const props = {
marks: {},
step: 6,
min: 0,
max: 100
};
expect(utils.getClosestPoint(value, props)).toBe(96);
});
it('should properly handle floating point arithmetic', () => {
const value = 5.3;
const props = {
marks: {},
step: 0.05,
min: 0,
max: 5.3
};
expect(utils.getClosestPoint(value, props)).toBe(5.3);
});
});
});