-
Notifications
You must be signed in to change notification settings - Fork 596
/
Copy pathstatic.test.js
92 lines (78 loc) · 2.67 KB
/
static.test.js
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
92
/* eslint no-shadow:[0] */
import test from 'node:test';
import assert from 'node:assert/strict';
import StaticMode from '@mapbox/mapbox-gl-draw-static-mode';
import {spy} from 'sinon';
import MapboxDraw from '../index.js';
import {setupAfterNextRender} from './utils/after_next_render.js';
import makeMouseEvent from './utils/make_mouse_event.js';
import getGeoJSON from './utils/get_geojson.js';
import createMap from './utils/create_map.js';
test('static', async (t) => {
const map = createMap();
const opts = {
modes: {
static: StaticMode
},
defaultMode: 'static'
};
const Draw = new MapboxDraw(opts);
map.addControl(Draw);
spy(map, 'fire');
map.dragPan.disable();
spy(map.dragPan, 'disable');
const afterNextRender = setupAfterNextRender(map);
const cleanUp = function() {
Draw.deleteAll();
map.fire.resetHistory();
};
const getFireArgs = function() {
const args = [];
for (let i = 0; i < map.fire.callCount; i++) {
args.push(map.fire.getCall(i).args);
}
return args;
};
t.test('static - init map for tests', () => {
const done = function() {
map.off('load', done);
};
if (map.loaded()) {
done();
} else {
map.on('load', done);
}
});
await t.test('static - box select', async () => {
Draw.add(getGeoJSON('negativePoint'));
Draw.add(getGeoJSON('point'));
map.fire.resetHistory();
await afterNextRender();
map.dragPan.disable.resetHistory();
map.fire('mousedown', makeMouseEvent(0, 0, { shiftKey: true }));
assert.equal(map.dragPan.disable.callCount, 0, 'dragPan is still enabled');
map.fire('mousemove', makeMouseEvent(15, 15, { shiftKey: true }));
map.fire('mouseup', makeMouseEvent(15, 15, { shiftKey: true }));
const args = getFireArgs().filter(arg => arg[0] === 'draw.selectionchange');
assert.equal(args.length, 0, 'should have zero selectionchange events');
cleanUp();
});
await t.test('static - try clicking many features', async () => {
const features = [getGeoJSON('point'), getGeoJSON('line'), getGeoJSON('square')];
Draw.add({
type: 'FeatureCollection',
features
});
map.fire.resetHistory();
await afterNextRender();
map.fire('mousedown', makeMouseEvent(10, 10));
map.fire('mouseup', makeMouseEvent(10, 10));
map.fire('mousemove', makeMouseEvent(1.5, 1.5));
map.fire('mouseup', makeMouseEvent(1.5, 1.5));
map.fire('mousemove', makeMouseEvent(1, 1));
map.fire('mouseup', makeMouseEvent(1, 1));
const args = getFireArgs().filter(arg => arg[0] === 'draw.selectionchange');
assert.equal(args.length, 0, 'should have zero selectionchange events');
cleanUp();
});
});