1 | jest.mock('mapbox-gl', () => ({
|
2 | default: {},
|
3 | LngLat: {}
|
4 | }));
|
5 |
|
6 | import { overlayTransform, OverlayParams, anchors } from '../util/overlays';
|
7 |
|
8 | describe('overlayTransform', () => {
|
9 | it('Should transform position anchor and offset accordingly', () => {
|
10 | const overlayProps: OverlayParams = {
|
11 | anchor: anchors[1],
|
12 |
|
13 | offset: { x: 10, y: 20 } as any,
|
14 |
|
15 | position: { x: 1000, y: 2000 } as any
|
16 | };
|
17 |
|
18 | const res = overlayTransform(overlayProps);
|
19 |
|
20 | expect(res).toEqual([
|
21 | 'translate(1000px, 2000px)',
|
22 | 'translate(10px, 20px)',
|
23 | 'translate(-50%, 0)'
|
24 | ]);
|
25 | });
|
26 |
|
27 | it('Should transform position and offset only', () => {
|
28 |
|
29 | const overlayProps: any = {
|
30 | offset: { x: 10, y: 20 },
|
31 | position: { x: 1000, y: 2000 }
|
32 | };
|
33 |
|
34 | const res = overlayTransform(overlayProps);
|
35 |
|
36 | expect(res).toEqual(['translate(1000px, 2000px)', 'translate(10px, 20px)']);
|
37 | });
|
38 |
|
39 | it('Should not add an undefined offset', () => {
|
40 |
|
41 | const overlayProps: any = {
|
42 | offset: { x: undefined, y: 20 },
|
43 | position: { x: 1000, y: 2000 }
|
44 | };
|
45 |
|
46 | const res = overlayTransform(overlayProps);
|
47 |
|
48 | expect(res).toEqual(['translate(1000px, 2000px)']);
|
49 | });
|
50 |
|
51 | it('Should add offset of 0', () => {
|
52 |
|
53 | const overlayProps: any = {
|
54 | offset: { x: 0, y: 20 },
|
55 | position: { x: 1000, y: 2000 }
|
56 | };
|
57 |
|
58 | const res = overlayTransform(overlayProps);
|
59 |
|
60 | expect(res).toEqual(['translate(1000px, 2000px)', 'translate(0px, 20px)']);
|
61 | });
|
62 | });
|