/* global setTimeout */
import {Map} from 'react-map-gl';
import * as React from 'react';
import {create, act} from 'react-test-renderer';
import test from 'tape-promise/tape';
import {sleep} from '../utils/test-utils';
test('Map', async t => {
t.ok(Map, 'Map is defined');
const mapRef = {current: null};
let onloadCalled = 0;
const onLoad = () => onloadCalled++;
let map;
act(() => {
map = create(
);
});
t.ok(map.root, 'Rendered ');
t.is(mapRef.current.getCenter().lng, -100, 'longitude is set');
t.is(mapRef.current.getCenter().lat, 40, 'latitude is set');
t.is(mapRef.current.getZoom(), 4, 'zoom is set');
act(() => {
map.update();
});
t.is(mapRef.current.getCenter().lng, -122, 'longitude is updated');
t.is(mapRef.current.getCenter().lat, 38, 'latitude is updated');
t.is(mapRef.current.getZoom(), 14, 'zoom is updated');
await sleep(1);
t.is(onloadCalled, 1, 'onLoad is called');
map.unmount();
t.end();
});
test('Map#uncontrolled', async t => {
t.plan(5);
const lastLat = 40;
function onRender(e) {
const {lat} = e.target.getCenter();
t.ok(lastLat > lat, 'animating');
}
act(() => {
create(