UNPKG

1.96 kBTypeScriptView Raw
1import * as React from 'react';
2import GeoJSONLayer from '../geojson-layer';
3import { getMapMock, mountWithMap } from '../jest/util';
4
5describe('GeoJSONLayer', () => {
6 const fillPaint = { 'fill-color': '#001122' };
7 const data = { type: 'FeatureCollection', features: [] };
8
9 it('Should call addLayer with provided layerOptions', () => {
10 const mapMock = getMapMock();
11
12 const GeoJSONLayerComp = (
13 <GeoJSONLayer
14 fillPaint={fillPaint}
15 data={data}
16 layerOptions={{ minzoom: 13 }}
17 />
18 );
19
20 mountWithMap(GeoJSONLayerComp, mapMock);
21
22 const addFillLayerCall = mapMock.addLayer.mock.calls.find(([call]) =>
23 call.id.endsWith('-fill')
24 );
25
26 expect(addFillLayerCall).toEqual([
27 {
28 id: 'geojson-1-fill',
29 source: 'geojson-1',
30 type: 'fill',
31 layout: { visibility: 'visible' },
32 minzoom: 13,
33 paint: { 'fill-color': '#001122' }
34 },
35 undefined
36 ]);
37 });
38
39 it('Should call addLayer when no layerOptions provided', () => {
40 const GeoJSONLayerComp = <GeoJSONLayer fillPaint={fillPaint} data={data} />;
41 const mapMock = getMapMock();
42
43 mountWithMap(GeoJSONLayerComp, mapMock);
44
45 const addFillLayerCall = mapMock.addLayer.mock.calls.find(([call]) =>
46 call.id.endsWith('-fill')
47 );
48
49 expect(addFillLayerCall).toEqual([
50 {
51 id: 'geojson-2-fill',
52 source: 'geojson-2',
53 type: 'fill',
54 layout: { visibility: 'visible' },
55 paint: { 'fill-color': '#001122' }
56 },
57 undefined
58 ]);
59 });
60
61 it('Should start listening onClick mouse event', () => {
62 const GeoJSONLayerComp = (
63 <GeoJSONLayer fillPaint={fillPaint} data={data} fillOnClick={jest.fn()} />
64 );
65 const mapMock = getMapMock();
66 mountWithMap(GeoJSONLayerComp, mapMock);
67
68 expect(mapMock.on.mock.calls[0][0]).toEqual('click');
69 expect(mapMock.on.mock.calls[0][1]).toEqual('geojson-3-fill');
70 });
71});