Debian Codegraph @

packages/popper/tests/functional/computeStyle.js

raw
1 import Popper from '../../src/index.js';
2
3 import '@popperjs/test-utils';
4 const jasmineWrapper = document.getElementById('jasmineWrapper');
5 const arrowSize = 5;
6
7 // Utils
8 import appendNewPopper from '@popperjs/test-utils/utils/appendNewPopper';
9 import appendNewRef from '@popperjs/test-utils/utils/appendNewRef';
10 import getRect from '../utils/getRect';
11
12 [true, false].forEach((positionFixed) => {
13 beforeEach(function(){
14 Popper.Defaults.positionFixed = positionFixed;
15 });
16
17 describe('[computeStyle]' + (positionFixed ? ' Fixed' : ''), () => {
18 describe('x="top" y="left"', () => {
19 it('positions a popper on the body correctly', (done) => {
20 const reference = appendNewRef(1);
21 const popper = appendNewPopper(2);
22
23 new Popper(reference, popper, {
24 modifiers: {
25 computeStyle: {
26 x: 'top',
27 y: 'left',
28 },
29 },
30 onCreate(data) {
31 const popRect = getRect(popper);
32 const refRect = getRect(reference);
33 expect(popRect.top - arrowSize).toBeApprox(refRect.bottom);
34 expect(popRect.left).toBeApprox(5);
35 data.instance.destroy();
36 done();
37 },
38 });
39 });
40
41 it('positions a popper on a scrolled body correctly', (done) => {
42 jasmineWrapper.style.height = '500vh';
43 jasmineWrapper.style.width = '500vw';
44
45 const reference = appendNewRef(1);
46 const popper = appendNewPopper(2);
47
48 new Popper(reference, popper, {
49 modifiers: {
50 computeStyle: {
51 x: 'top',
52 y: 'left',
53 },
54 },
55 onCreate(data) {
56 const popRect = getRect(popper);
57 const refRect = getRect(reference);
58 expect(popRect.top - arrowSize).toBeApprox(refRect.bottom);
59 expect(popRect.left).toBeApprox(5);
60 jasmineWrapper.style.cssText = null;
61 data.instance.destroy();
62 done();
63 },
64 });
65 });
66 });
67 });
68 });