forked from floating-ui/floating-ui
/
getBoundaries.padding.js
73 lines (65 loc) · 1.96 KB
/
getBoundaries.padding.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import getBoundaries from '../../src/utils/getBoundaries';
import getFixedPositionOffsetParent from '../../src/utils/getFixedPositionOffsetParent';
describe('utils/getBoundaries-padding-offset', () => {
let node;
beforeEach(() => {
node = document.createElement('div');
document.body.appendChild(node);
});
afterEach(() => {
document.body.removeChild(node);
});
function expectBoundary(result, expected) {
const tolerance = 3;
expect(Math.abs(result.top - expected.top) <= tolerance).toBeTruthy();
expect(Math.abs(result.right - expected.right) <= tolerance).toBeTruthy();
expect(Math.abs(result.bottom - expected.bottom) <= tolerance).toBeTruthy();
expect(Math.abs(result.left - expected.left) <= tolerance).toBeTruthy();
}
it('returns a boundary with a single value padding offset.', () => {
const padding = 50;
const result = getBoundaries(null, null, padding, 'viewport', true);
expectBoundary(result, {
top: 50,
right: 735,
bottom: 550,
left: 50,
});
});
it('returns a boundary with a top and left componentized padding offset.', () => {
const padding = {
top: 50,
left: 100,
};
const result = getBoundaries(null, null, padding, 'viewport', true);
expectBoundary(result, {
top: 50,
right: 785,
bottom: 600,
left: 100,
});
});
it('returns a boundary with a bottom and right componentized padding offset.', () => {
const padding = {
bottom: 50,
right: 85,
};
const result = getBoundaries(null, null, padding, 'viewport', true);
expectBoundary(result, {
top: 0,
right: 700,
bottom: 550,
left: 0,
});
});
it('returns a boundary with a null padding offset.', () => {
const padding = null;
const result = getBoundaries(null, null, padding, 'viewport', true);
expectBoundary(result, {
top: 0,
right: 785,
bottom: 600,
left: 0,
});
});
});