Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/main/test/components/controls.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('Controls', async t => {
const mapRef = {current: null};

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<AttributionControl />
</Map>
);
Expand All @@ -26,7 +26,7 @@ test('Controls', async t => {
t.ok(rootContainer.querySelector('.mapboxgl-ctrl-attrib'), 'Rendered <AttributionControl />');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<FullscreenControl />
</Map>
);
Expand All @@ -35,7 +35,7 @@ test('Controls', async t => {

const geolocateControlRef = {current: null};
root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<GeolocateControl ref={geolocateControlRef} />
</Map>
);
Expand All @@ -44,15 +44,15 @@ test('Controls', async t => {
t.ok(geolocateControlRef.current, 'GeolocateControl created');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<NavigationControl />
</Map>
);
await sleep(1);
t.ok(rootContainer.querySelector('.mapboxgl-ctrl-zoom-in'), 'Rendered <NavigationControl />');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<ScaleControl />
</Map>
);
Expand Down
8 changes: 4 additions & 4 deletions modules/main/test/components/layer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('Source/Layer', async t => {
};

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Source id="my-data" type="geojson" data={geoJSON}>
<Layer id="my-layer" {...pointLayer} />
</Source>
Expand All @@ -45,7 +45,7 @@ test('Source/Layer', async t => {
t.ok(layer, 'Layer is added');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Source id="my-data" type="geojson" data={geoJSON}>
<Layer id="my-layer" {...pointLayer2} />
</Source>
Expand All @@ -55,7 +55,7 @@ test('Source/Layer', async t => {
t.is(layer.visibility, 'none', 'Layer is updated');

root.render(
<Map ref={mapRef} mapStyle={mapStyle}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')} mapStyle={mapStyle}>
<Source id="my-data" type="geojson" data={geoJSON}>
<Layer id="my-layer" {...pointLayer2} />
</Source>
Expand All @@ -64,7 +64,7 @@ test('Source/Layer', async t => {
await sleep(50);
t.ok(mapRef.current.getLayer('my-layer'), 'Layer is added after style change');

root.render(<Map ref={mapRef} mapStyle={mapStyle} />);
root.render(<Map ref={mapRef} mapLib={import('mapbox-gl-v1')} mapStyle={mapStyle} />);
await sleep(1);
t.notOk(mapRef.current.getSource('my-data'), 'Source is removed');
t.notOk(mapRef.current.getLayer('my-layer'), 'Layer is removed');
Expand Down
22 changes: 20 additions & 2 deletions modules/main/test/components/map.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ test('Map', async t => {
const onLoad = () => onloadCalled++;

root.render(
<Map ref={mapRef} initialViewState={{longitude: -100, latitude: 40, zoom: 4}} onLoad={onLoad} />
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v1')}
initialViewState={{longitude: -100, latitude: 40, zoom: 4}}
onLoad={onLoad}
/>
);

await waitForMapLoad(mapRef);
Expand All @@ -26,7 +31,16 @@ test('Map', async t => {
t.is(mapRef.current.getCenter().lat, 40, 'latitude is set');
t.is(mapRef.current.getZoom(), 4, 'zoom is set');

root.render(<Map ref={mapRef} longitude={-122} latitude={38} zoom={14} onLoad={onLoad} />);
root.render(
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v1')}
longitude={-122}
latitude={38}
zoom={14}
onLoad={onLoad}
/>
);
await sleep(1);

t.is(mapRef.current.getCenter().lng, -122, 'longitude is updated');
Expand Down Expand Up @@ -63,6 +77,7 @@ test('Map#uncontrolled', t => {
root.render(
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v1')}
initialViewState={{longitude: -100, latitude: 40, zoom: 4}}
onLoad={onLoad}
onRender={onRender}
Expand Down Expand Up @@ -90,6 +105,7 @@ test('Map#controlled#no-update', t => {
root.render(
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v1')}
longitude={-100}
latitude={40}
zoom={4}
Expand Down Expand Up @@ -129,6 +145,7 @@ test('Map#controlled#mirror-back', t => {
return (
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v1')}
{...viewState}
onLoad={onLoad}
onMove={e => setViewState(e.viewState)}
Expand Down Expand Up @@ -170,6 +187,7 @@ test('Map#controlled#delayed-update', t => {
return (
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v1')}
{...viewState}
onLoad={onLoad}
onMove={e => setTimeout(() => setViewState(e.viewState))}
Expand Down
14 changes: 7 additions & 7 deletions modules/main/test/components/marker.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Marker', async t => {
const mapRef = {current: null};

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Marker ref={markerRef} longitude={-122} latitude={38} />
</Map>
);
Expand All @@ -31,7 +31,7 @@ test('Marker', async t => {
const rotationAlignment = marker.getRotationAlignment();

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Marker ref={markerRef} longitude={-122} latitude={38} offset={[0, 0]} />
</Map>
);
Expand All @@ -40,16 +40,16 @@ test('Marker', async t => {

let callbackType = '';
root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Marker
ref={markerRef}
longitude={-122}
latitude={38}
offset={[0, 1]}
rotation={30}
draggable
pitchAlignment="viewport"
rotationAlignment="viewport"
pitchAlignment="map"
rotationAlignment="map"
onDragStart={() => (callbackType = 'dragstart')}
onDrag={() => (callbackType = 'drag')}
onDragEnd={() => (callbackType = 'dragend')}
Expand All @@ -71,13 +71,13 @@ test('Marker', async t => {
marker.fire('dragend');
t.is(callbackType, 'dragend', 'onDragEnd called');

root.render(<Map ref={mapRef} />);
root.render(<Map ref={mapRef} mapLib={import('mapbox-gl-v1')} />);
await sleep(1);

t.notOk(markerRef.current, 'marker is removed');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Marker ref={markerRef} longitude={-100} latitude={40}>
<div id="marker-content" />
</Marker>
Expand Down
8 changes: 4 additions & 4 deletions modules/main/test/components/popup.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('Popup', async t => {
const popupRef = {current: null};

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Popup ref={popupRef} longitude={-122} latitude={38} offset={[0, 10]}>
You are here
</Popup>
Expand All @@ -27,7 +27,7 @@ test('Popup', async t => {
const {anchor, offset, maxWidth} = popup.options;

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Popup ref={popupRef} longitude={-122} latitude={38} offset={[0, 10]}>
<div id="popup-content">You are here</div>
</Popup>
Expand All @@ -39,7 +39,7 @@ test('Popup', async t => {
t.ok(rootContainer.querySelector('#popup-content'), 'content is rendered');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Popup
ref={popupRef}
longitude={-122}
Expand All @@ -59,7 +59,7 @@ test('Popup', async t => {
t.not(maxWidth, popup.options.maxWidth, 'maxWidth is updated');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Popup ref={popupRef} longitude={-122} latitude={38} className="classA">
<div id="popup-content">You are here</div>
</Popup>
Expand Down
8 changes: 4 additions & 4 deletions modules/main/test/components/source.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('Source/Layer', async t => {
};

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')}>
<Source id="my-data" type="geojson" data={geoJSON} />
</Map>
);
Expand All @@ -28,23 +28,23 @@ test('Source/Layer', async t => {
t.ok(mapRef.current.getSource('my-data'), 'Source is added');

root.render(
<Map ref={mapRef} mapStyle={mapStyle}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')} 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}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v1')} mapStyle={mapStyle}>
<Source id="my-data" type="geojson" data={geoJSON2} />
</Map>
);
await sleep(1);
const sourceData = await mapRef.current.getSource('my-data')?._data;
t.deepEqual(sourceData, geoJSON2, 'Source is updated');

root.render(<Map ref={mapRef} mapStyle={mapStyle} />);
root.render(<Map ref={mapRef} mapLib={import('mapbox-gl-v1')} mapStyle={mapStyle} />);
await sleep(1);
t.notOk(mapRef.current.getSource('my-data'), 'Source is removed');

Expand Down
6 changes: 3 additions & 3 deletions modules/main/test/components/use-map.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test('useMap', async t => {

root.render(
<MapProvider>
<Map id="mapA" />
<Map id="mapB" ref={mapRef} />
<Map id="mapA" mapLib={import('mapbox-gl-v1')} />
<Map id="mapB" ref={mapRef} mapLib={import('mapbox-gl-v1')} />
<TestControl />
</MapProvider>
);
Expand All @@ -29,7 +29,7 @@ test('useMap', async t => {

root.render(
<MapProvider>
<Map id="mapA" />
<Map id="mapA" mapLib={import('mapbox-gl-v1')} />
<TestControl />
</MapProvider>
);
Expand Down
11 changes: 6 additions & 5 deletions modules/react-mapbox/test/components/controls.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import * as React from 'react';
import {createRoot} from 'react-dom/client';
import test from 'tape-promise/tape';
import {sleep, waitForMapLoad} from '../utils/test-utils';
import {MapboxAccessToken} from '../utils/token';

test('Controls', async t => {
const rootContainer = document.createElement('div');
const root = createRoot(rootContainer);
const mapRef = {current: null};

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v3')} mapboxAccessToken={MapboxAccessToken}>
<AttributionControl />
</Map>
);
Expand All @@ -26,7 +27,7 @@ test('Controls', async t => {
t.ok(rootContainer.querySelector('.mapboxgl-ctrl-attrib'), 'Rendered <AttributionControl />');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v3')} mapboxAccessToken={MapboxAccessToken}>
<FullscreenControl />
</Map>
);
Expand All @@ -35,7 +36,7 @@ test('Controls', async t => {

const geolocateControlRef = {current: null};
root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v3')} mapboxAccessToken={MapboxAccessToken}>
<GeolocateControl ref={geolocateControlRef} />
</Map>
);
Expand All @@ -44,15 +45,15 @@ test('Controls', async t => {
t.ok(geolocateControlRef.current, 'GeolocateControl created');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v3')} mapboxAccessToken={MapboxAccessToken}>
<NavigationControl />
</Map>
);
await sleep(1);
t.ok(rootContainer.querySelector('.mapboxgl-ctrl-zoom-in'), 'Rendered <NavigationControl />');

root.render(
<Map ref={mapRef}>
<Map ref={mapRef} mapLib={import('mapbox-gl-v3')} mapboxAccessToken={MapboxAccessToken}>
<ScaleControl />
</Map>
);
Expand Down
Loading
Loading