Debian Codegraph @

packages/popper/tests/unit/getBoundaries.padding.js

raw
1 import getBoundaries from '../../src/utils/getBoundaries';
2
3 describe('utils/getBoundaries-padding-offset', () => {
4 let node;
5
6 beforeEach(() => {
7 node = document.createElement('div');
8 document.body.appendChild(node);
9 });
10
11 afterEach(() => {
12 document.body.removeChild(node);
13 });
14
15 function expectBoundary(result, expected) {
16 const tolerance = 2;
17 expect(Math.abs(result.top - expected.top) <= tolerance).toBeTruthy();
18 expect(Math.abs(result.right - expected.right) <= tolerance).toBeTruthy();
19 expect(Math.abs(result.bottom - expected.bottom) <= tolerance).toBeTruthy();
20 expect(Math.abs(result.left - expected.left) <= tolerance).toBeTruthy();
21 }
22
23 it('returns a boundary with a single value padding offset.', () => {
24 const padding = 50;
25 const result = getBoundaries(null, null, padding, 'viewport', true);
26 expectBoundary(result, {
27 top: 50,
28 right: window.innerWidth - 50,
29 bottom: window.innerHeight - 50,
30 left: 50,
31 });
32 });
33
34 it('returns a boundary with a top and left componentized padding offset.', () => {
35 const padding = {
36 top: 50,
37 left: 100,
38 };
39 const result = getBoundaries(null, null, padding, 'viewport', true);
40 expectBoundary(result, {
41 top: 50,
42 right: window.innerWidth,
43 bottom: window.innerHeight,
44 left: 100,
45 });
46 });
47
48 it('returns a boundary with a bottom and right componentized padding offset.', () => {
49 const padding = {
50 bottom: 50,
51 right: 85,
52 };
53 const result = getBoundaries(null, null, padding, 'viewport', true);
54 expectBoundary(result, {
55 top: 0,
56 right: window.innerWidth - 85,
57 bottom: window.innerHeight - 50,
58 left: 0,
59 });
60 });
61
62 it('returns a boundary with a null padding offset.', () => {
63 const padding = null;
64 const result = getBoundaries(null, null, padding, 'viewport', true);
65 expectBoundary(result, {
66 top: 0,
67 right: window.innerWidth,
68 bottom: window.innerHeight,
69 left: 0,
70 });
71 });
72 });