-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathsource.spec.jsx
More file actions
91 lines (76 loc) · 2.14 KB
/
source.spec.jsx
File metadata and controls
91 lines (76 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* global document */
import test from 'tape-promise/tape';
import * as React from 'react';
import {createRoot} from 'react-dom/client';
import {Map, Source, Layer} from '@vis.gl/react-maplibre';
import {sleep, waitForMapLoad} from '../utils/test-utils';
test('Source/Layer', async t => {
const root = createRoot(document.createElement('div'));
const mapRef = {current: null};
const mapStyle = {version: 8, sources: {}, layers: []};
const geoJSON = {
type: 'Point',
coordinates: [0, 0]
};
const geoJSON2 = {
type: 'Point',
coordinates: [1, 1]
};
root.render(
<Map ref={mapRef}>
<Source id="my-data" type="geojson" data={geoJSON} />
</Map>
);
await waitForMapLoad(mapRef);
await sleep(1);
t.ok(mapRef.current.getSource('my-data'), 'Source is added');
root.render(
<Map ref={mapRef} mapStyle={mapStyle}>
<Source id="my-data" type="geojson" data={geoJSON} />
</Map>
);
await sleep(50);
t.ok(mapRef.current.getSource('my-data'), 'Source is added after style change');
root.render(
<Map ref={mapRef} mapStyle={mapStyle}>
<Source id="my-data" type="geojson" data={geoJSON2} />
</Map>
);
await sleep(1);
const sourceData = await mapRef.current.getSource('my-data')?.getData();
t.deepEqual(sourceData, geoJSON2, 'Source is updated');
root.render(<Map ref={mapRef} mapStyle={mapStyle} />);
await sleep(1);
t.notOk(mapRef.current.getSource('my-data'), 'Source is removed');
root.unmount();
t.end();
});
test('Composable Layers', async t => {
const root = createRoot(document.createElement('div'));
const mapRef = {current: null};
const geoJSON = {
type: 'Point',
coordinates: [0, 0]
};
const MyLayer = () =>
<Layer {...{
id: 'my-layer',
type: 'circle',
paint: {
'circle-radius': 10,
'circle-color': '#000000'
}
}}/>
root.render(
<Map ref={mapRef}>
<Source id="my-data" type="geojson" data={geoJSON}>
<MyLayer/>
</Source>
</Map>
);
await waitForMapLoad(mapRef);
await sleep(1);
t.ok(mapRef.current.getLayer('my-layer'), 'Layer is added');
root.unmount();
t.end();
})