Debian Codegraph @

packages/popper/tests/unit/parseOffset.js

raw
1 import { parseOffset } from '../../src/modifiers/offset';
2
3 const popperOffsets = {
4 top: 0,
5 left: 0,
6 right: 100,
7 bottom: 100,
8 width: 100,
9 height: 100,
10 };
11
12 const referenceOffsets = popperOffsets;
13
14 describe('parseOffset', () => {
15 it('parses `10px 10px` and throws deprecation warning', () => {
16 console.warn = jasmine.createSpy('warn');
17 expect(
18 parseOffset('10px 10px', referenceOffsets, popperOffsets, 'bottom')
19 ).toEqual([10, 10]);
20 expect(console.warn).toHaveBeenCalledWith(
21 'Offsets separated by white space(s) are deprecated, use a comma (,) instead.'
22 );
23 });
24
25 const cases = [
26 ['10,10', [10, 10]],
27 ['10px, -10px', [10, -10]],
28 ['10px, 10px', [10, 10]],
29 ['10px + 5%, 10px - 5%', [10 + 5, 10 - 5]],
30 ['-10px + 5%, -10px - 5%', [-10 + 5, -10 - 5]],
31 ['5%p, 5%r', [5, 5]],
32 ['100%+50px, 100px-10+10%', [100 + 50, 100 - 10 + 10]],
33 ['100% + 50% + 10%, 100%', [100 + 50 + 10, 100]],
34 ['100%p - 10%r, 100%', [100 - 10, 100]],
35 ['100%p - -10%r, 100%', [100 - -10, 100]],
36 ['+10px - -10% + -10%r', [10 - -10 + -10, 0]],
37 ];
38
39 cases.forEach(([input, output]) => {
40 it(`parses '${input}'`, () => {
41 expect(
42 parseOffset(input, referenceOffsets, popperOffsets, 'bottom')
43 ).toEqual(output);
44 });
45 });
46 });