UNPKG

1.93 kBTypeScriptView Raw
1jest.mock('mapbox-gl', () => ({
2 Map: {}
3}));
4
5jest.mock('../util/overlays', () => ({
6 overlayState: jest.fn(() => ({})),
7 overlayTransform: jest.fn(() => []),
8 anchors: []
9}));
10
11import * as React from 'react';
12import Cluster from '../cluster';
13import Marker from '../marker';
14import { mountWithMap, getMapMock } from '../jest/util';
15
16const coordinates = [
17 [-12.408741828510017, 58.16339752811908],
18 [-5.668629523822517, 50.06970856327533],
19 [-9.26996282865152, 42.92873605781255],
20 [-8.969410773822517, 37.03827545780658],
21 [11.024180534771233, 37.07398102421283],
22 [-9.273915168353767, 32.58161041874408]
23];
24
25const mockProjections = {
26 0: {
27 toArray() {
28 return [-63.41135717118712, 69.80779389260127];
29 }
30 },
31 1: {
32 toArray() {
33 return [120.23846281116113, 69.80779389260127];
34 }
35 },
36 2: {
37 toArray() {
38 return [120.23846281116113, -41.10548333921079];
39 }
40 },
41 3: {
42 toArray() {
43 return [-63.41135717118712, -41.10548333921079];
44 }
45 },
46 4: {
47 toArray() {
48 return [-63.41135717118712, 69.80779389260127];
49 }
50 }
51};
52
53describe('cluster', () => {
54 it('should render the correct number of cluster', () => {
55 const clusterMarkerFactory = jest.fn();
56 let unprojectCalls = 0;
57
58 mountWithMap(
59 <Cluster
60 children={coordinates.map((coord, index) => (
61 <Marker coordinates={coord} key={index} />
62 ))}
63 ClusterMarkerFactory={clusterMarkerFactory}
64 />,
65 getMapMock({
66 getZoom: jest.fn(() => 2),
67 getCanvas: jest.fn(() => ({ width: 1020, height: 800 })),
68 unproject: jest.fn(() => mockProjections[unprojectCalls++])
69 })
70 );
71
72 const call = clusterMarkerFactory.mock.calls[0];
73 // coordinates
74 expect(call[0]).toEqual([-9.11968680123703, 40.047086577057655]);
75 // pointCount
76 expect(call[1]).toEqual(2);
77 // getLeaves
78 expect(call[2]().length).toEqual(2);
79 });
80});