mobility-toolbox-js 2.0.0-beta.35 → 2.0.0-beta.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/common/api/HttpAPI.d.ts +4 -4
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +6 -2
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +57 -31
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +2 -4
- package/common/styles/realtimeSimpleStyle.js +1 -1
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/index.d.ts +4 -0
- package/mapbox/index.d.ts +1 -0
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mbt.js +56 -32
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +2 -1
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/index.d.ts +1 -0
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +4 -0
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/package.json +5 -2
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import WS from 'jest-websocket-mock';
|
|
11
|
+
import WebSocketAPI from './WebSocketAPI';
|
|
12
|
+
describe('WebSocketAPI', () => {
|
|
13
|
+
describe('#constructor', () => {
|
|
14
|
+
let server;
|
|
15
|
+
let server2;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
server = new WS(`ws://foo:1234`);
|
|
18
|
+
server2 = new WS(`ws://foo:12345`);
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
server.close();
|
|
22
|
+
server2.close();
|
|
23
|
+
WS.clean();
|
|
24
|
+
});
|
|
25
|
+
describe('#constructor', () => {
|
|
26
|
+
test("doesn't connect.", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const client = new WebSocketAPI();
|
|
28
|
+
expect(client.websocket).toBe();
|
|
29
|
+
expect(client.closed).toBe(false);
|
|
30
|
+
expect(client.closing).toBe(false);
|
|
31
|
+
expect(client.connecting).toBe(false);
|
|
32
|
+
expect(client.open).toBe(false);
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
describe('#close', () => {
|
|
36
|
+
test('should close the websocket and clear some property', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
// eslint-disable-next-line no-unused-vars
|
|
38
|
+
const client = new WebSocketAPI();
|
|
39
|
+
const subsc2 = {
|
|
40
|
+
params: 'foo',
|
|
41
|
+
cb: () => { },
|
|
42
|
+
errorCb: () => { },
|
|
43
|
+
quiet: false,
|
|
44
|
+
};
|
|
45
|
+
client.subscriptions = [subsc2];
|
|
46
|
+
client.messagesOnOpen = ['GET foo'];
|
|
47
|
+
client.connect(`ws://foo:1234`);
|
|
48
|
+
client.websocket.addEventListener = jest.fn();
|
|
49
|
+
client.websocket.removeEventListener = jest.fn();
|
|
50
|
+
client.websocket.close = jest.fn();
|
|
51
|
+
yield server.connected;
|
|
52
|
+
expect(client.websocket).toBeDefined();
|
|
53
|
+
expect(client.messagesOnOpen).toEqual(['GET foo']);
|
|
54
|
+
client.close();
|
|
55
|
+
expect(client.messagesOnOpen).toEqual([]);
|
|
56
|
+
expect(client.websocket).toBeNull();
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
describe('#connect', () => {
|
|
60
|
+
test('create a new WebSocket.', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const client = new WebSocketAPI();
|
|
62
|
+
client.connect(`ws://foo:1234`);
|
|
63
|
+
yield server.connected;
|
|
64
|
+
client.send('hello');
|
|
65
|
+
yield expect(server).toReceiveMessage('hello');
|
|
66
|
+
expect(server).toHaveReceivedMessages(['hello']);
|
|
67
|
+
}));
|
|
68
|
+
test('close previous connection.', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const client = new WebSocketAPI();
|
|
70
|
+
client.connect(`ws://foo:1234`);
|
|
71
|
+
yield server.connected;
|
|
72
|
+
expect(client.websocket).toBeDefined();
|
|
73
|
+
const old = client.websocket;
|
|
74
|
+
expect(old.readyState).toBe(WebSocket.OPEN);
|
|
75
|
+
client.connect(`ws://foo:12345`);
|
|
76
|
+
expect(old.readyState).toBe(WebSocket.CLOSING);
|
|
77
|
+
expect(client.websocket.readyState).toBe(WebSocket.CONNECTING);
|
|
78
|
+
}));
|
|
79
|
+
test('call onOpen function', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const onOpen = jest.fn();
|
|
81
|
+
const client = new WebSocketAPI();
|
|
82
|
+
client.subscribe = jest.fn();
|
|
83
|
+
client.connect(`ws://foo:1234`, onOpen);
|
|
84
|
+
yield server.connected;
|
|
85
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
86
|
+
expect(onOpen).toHaveBeenCalledTimes(1);
|
|
87
|
+
}));
|
|
88
|
+
test('subscribe previous subscriptions on open (quiet or not)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const client = new WebSocketAPI();
|
|
90
|
+
client.subscribe = jest.fn();
|
|
91
|
+
client.send = jest.fn();
|
|
92
|
+
const subsc = {
|
|
93
|
+
params: 'foo',
|
|
94
|
+
cb: () => { },
|
|
95
|
+
errorCb: () => { },
|
|
96
|
+
quiet: true,
|
|
97
|
+
};
|
|
98
|
+
const subsc2 = {
|
|
99
|
+
params: 'foo',
|
|
100
|
+
cb: () => { },
|
|
101
|
+
errorCb: () => { },
|
|
102
|
+
quiet: false,
|
|
103
|
+
};
|
|
104
|
+
client.subscriptions = [subsc, subsc2];
|
|
105
|
+
client.connect(`ws://foo:1234`);
|
|
106
|
+
yield server.connected;
|
|
107
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
108
|
+
expect(client.subscribe).toHaveBeenCalledTimes(2);
|
|
109
|
+
client.subscribe.mockReset();
|
|
110
|
+
client.connect(`ws://foo:12345`);
|
|
111
|
+
yield server2.connected;
|
|
112
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
113
|
+
expect(client.subscribe).toHaveBeenCalledTimes(2);
|
|
114
|
+
expect(client.subscribe).toHaveBeenCalledWith(subsc.params, subsc.cb, subsc.errorCb, subsc.quiet);
|
|
115
|
+
}));
|
|
116
|
+
test('send GET and SUB for not quiet previous subscriptions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const client = new WebSocketAPI();
|
|
118
|
+
client.send = jest.fn();
|
|
119
|
+
const subsc = {
|
|
120
|
+
params: { channel: 'foo' },
|
|
121
|
+
cb: () => { },
|
|
122
|
+
errorCb: () => { },
|
|
123
|
+
quiet: false,
|
|
124
|
+
};
|
|
125
|
+
client.subscriptions = [subsc];
|
|
126
|
+
client.connect(`ws://foo:1234`);
|
|
127
|
+
client.websocket.addEventListener = jest.fn();
|
|
128
|
+
client.websocket.removeEventListener = jest.fn();
|
|
129
|
+
yield server.connected;
|
|
130
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
131
|
+
expect(client.send).toHaveBeenCalledTimes(2);
|
|
132
|
+
expect(client.send.mock.calls[0]).toEqual(['GET foo']);
|
|
133
|
+
expect(client.send.mock.calls[1]).toEqual(['SUB foo']);
|
|
134
|
+
client.send.mockReset();
|
|
135
|
+
client.connect(`ws://foo:12345`);
|
|
136
|
+
client.websocket.addEventListener = jest.fn();
|
|
137
|
+
client.websocket.removeEventListener = jest.fn();
|
|
138
|
+
yield server2.connected;
|
|
139
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
140
|
+
// not quiet subscriptions will send GET and SUB requests.
|
|
141
|
+
expect(client.send).toHaveBeenCalledTimes(2);
|
|
142
|
+
expect(client.send.mock.calls[0]).toEqual(['GET foo']);
|
|
143
|
+
expect(client.send.mock.calls[1]).toEqual(['SUB foo']);
|
|
144
|
+
}));
|
|
145
|
+
test('doesn\t send GET and SUB for quiet previous subscriptions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
const client = new WebSocketAPI();
|
|
147
|
+
client.send = jest.fn();
|
|
148
|
+
const subsc = {
|
|
149
|
+
params: { channel: 'foo' },
|
|
150
|
+
cb: () => { },
|
|
151
|
+
errorCb: () => { },
|
|
152
|
+
quiet: true,
|
|
153
|
+
};
|
|
154
|
+
client.subscriptions = [subsc];
|
|
155
|
+
client.connect(`ws://foo:1234`);
|
|
156
|
+
client.websocket.addEventListener = jest.fn();
|
|
157
|
+
client.websocket.removeEventListener = jest.fn();
|
|
158
|
+
yield server.connected;
|
|
159
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
160
|
+
expect(client.send).toHaveBeenCalledTimes(0);
|
|
161
|
+
client.send.mockReset();
|
|
162
|
+
client.connect(`ws://foo:12345`);
|
|
163
|
+
client.websocket.addEventListener = jest.fn();
|
|
164
|
+
client.websocket.removeEventListener = jest.fn();
|
|
165
|
+
yield server2.connected;
|
|
166
|
+
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
167
|
+
// not quiet subscriptions will send GET and SUB requests.
|
|
168
|
+
expect(client.send).toHaveBeenCalledTimes(0);
|
|
169
|
+
}));
|
|
170
|
+
});
|
|
171
|
+
describe('#get', () => {
|
|
172
|
+
test('listen to message event', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
// eslint-disable-next-line no-unused-vars
|
|
174
|
+
const client = new WebSocketAPI();
|
|
175
|
+
client.connect(`ws://foo:1234`);
|
|
176
|
+
yield server.connected;
|
|
177
|
+
const params = { channel: 'get', args: ['baz'], id: 'id' };
|
|
178
|
+
const cb = jest.fn();
|
|
179
|
+
const errorCb = jest.fn();
|
|
180
|
+
client.get(params, cb, errorCb);
|
|
181
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
182
|
+
const obj = { source: 'get baz', client_reference: 'id' };
|
|
183
|
+
server.send(JSON.stringify(obj));
|
|
184
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
185
|
+
expect(cb).toHaveBeenCalledWith(obj);
|
|
186
|
+
}));
|
|
187
|
+
test('unlisten after receiving one response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
+
// eslint-disable-next-line no-unused-vars
|
|
189
|
+
const client = new WebSocketAPI();
|
|
190
|
+
client.connect(`ws://foo:1234`);
|
|
191
|
+
yield server.connected;
|
|
192
|
+
const params = { channel: 'get', args: ['baz'], id: 'id' };
|
|
193
|
+
const cb = jest.fn();
|
|
194
|
+
const errorCb = jest.fn();
|
|
195
|
+
client.get(params, cb, errorCb);
|
|
196
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
197
|
+
const obj = { source: 'get baz', client_reference: 'id' };
|
|
198
|
+
server.send(JSON.stringify(obj));
|
|
199
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
200
|
+
server.send(JSON.stringify(obj));
|
|
201
|
+
server.send(JSON.stringify(obj));
|
|
202
|
+
server.send(JSON.stringify(obj));
|
|
203
|
+
server.send(JSON.stringify(obj));
|
|
204
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
205
|
+
}));
|
|
206
|
+
test('call (then remove) good callbacks on multiple requests', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
207
|
+
// eslint-disable-next-line no-unused-vars
|
|
208
|
+
const client = new WebSocketAPI();
|
|
209
|
+
client.connect(`ws://foo:1234`);
|
|
210
|
+
yield server.connected;
|
|
211
|
+
const params = { channel: 'get', args: ['baz'], id: 'id' };
|
|
212
|
+
const cb = jest.fn();
|
|
213
|
+
const errorCb = jest.fn();
|
|
214
|
+
client.get(params, cb, errorCb);
|
|
215
|
+
const params2 = { channel: 'get', args: ['foo'], id: 'id' };
|
|
216
|
+
const cb2 = jest.fn();
|
|
217
|
+
const errorCb2 = jest.fn();
|
|
218
|
+
client.get(params2, cb2, errorCb2);
|
|
219
|
+
client.get(params, cb2, errorCb);
|
|
220
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
221
|
+
const obj = { source: 'get baz', client_reference: 'id' };
|
|
222
|
+
server.send(JSON.stringify(obj));
|
|
223
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
224
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
225
|
+
server.send(JSON.stringify({ source: 'get foo', client_reference: 'id' }));
|
|
226
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(cb2).toHaveBeenCalledTimes(2);
|
|
228
|
+
}));
|
|
229
|
+
});
|
|
230
|
+
describe('#subscribe', () => {
|
|
231
|
+
test('adds subscription to subscriptions array', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
|
+
// eslint-disable-next-line no-unused-vars
|
|
233
|
+
const client = new WebSocketAPI();
|
|
234
|
+
client.connect(`ws://foo:1234`);
|
|
235
|
+
yield server.connected;
|
|
236
|
+
const params = { channel: 'bar', args: ['baz'], id: 'id' };
|
|
237
|
+
const cb = jest.fn();
|
|
238
|
+
const errorCb = jest.fn();
|
|
239
|
+
client.subscribe(params, cb, errorCb);
|
|
240
|
+
expect(client.subscriptions.length).toBe(1);
|
|
241
|
+
expect(client.subscriptions[0].params).toBe(params);
|
|
242
|
+
expect(client.subscriptions[0].cb).toBe(cb);
|
|
243
|
+
expect(client.subscriptions[0].errorCb).toBe(errorCb);
|
|
244
|
+
expect(client.subscriptions[0].quiet).toBe(false);
|
|
245
|
+
const obj = { source: 'bar baz', client_reference: 'id' };
|
|
246
|
+
server.send(JSON.stringify(obj));
|
|
247
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(cb).toHaveBeenCalledWith(obj);
|
|
249
|
+
}));
|
|
250
|
+
test("doesn't duplicate subscriptions", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
251
|
+
// eslint-disable-next-line no-unused-vars
|
|
252
|
+
const client = new WebSocketAPI();
|
|
253
|
+
client.connect(`ws://foo:1234`);
|
|
254
|
+
yield server.connected;
|
|
255
|
+
const params = { channel: 'bar', args: ['baz'], id: 'id' };
|
|
256
|
+
const cb = jest.fn();
|
|
257
|
+
const errorCb = jest.fn();
|
|
258
|
+
client.subscribe(params, cb, errorCb, true);
|
|
259
|
+
client.subscribe(params, cb, errorCb, true);
|
|
260
|
+
expect(client.subscriptions.length).toBe(1);
|
|
261
|
+
const obj = { source: 'bar baz', client_reference: 'id' };
|
|
262
|
+
server.send(JSON.stringify(obj));
|
|
263
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
264
|
+
expect(cb).toHaveBeenCalledWith(obj);
|
|
265
|
+
}));
|
|
266
|
+
test('send GET and SUB requests.', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
267
|
+
// eslint-disable-next-line no-unused-vars
|
|
268
|
+
const client = new WebSocketAPI();
|
|
269
|
+
client.connect(`ws://foo:1234`);
|
|
270
|
+
client.send = jest.fn();
|
|
271
|
+
const params = { channel: 'bar', args: ['baz'], id: 'id' };
|
|
272
|
+
const cb = jest.fn();
|
|
273
|
+
const errorCb = jest.fn();
|
|
274
|
+
client.subscribe(params, cb, errorCb);
|
|
275
|
+
expect(client.send).toHaveBeenCalledTimes(2);
|
|
276
|
+
expect(client.send).toHaveBeenCalledWith('GET bar baz id');
|
|
277
|
+
expect(client.send).toHaveBeenCalledWith('SUB bar baz id');
|
|
278
|
+
client.send.mockRestore();
|
|
279
|
+
}));
|
|
280
|
+
test('should register callback without sending GET and SUB requests (quiet=true).', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
// eslint-disable-next-line no-unused-vars
|
|
282
|
+
const client = new WebSocketAPI();
|
|
283
|
+
client.connect(`ws://foo:1234`);
|
|
284
|
+
yield server.connected;
|
|
285
|
+
const params = { channel: 'bar', args: ['baz'], id: 'id' };
|
|
286
|
+
const cb = jest.fn();
|
|
287
|
+
const errorCb = jest.fn();
|
|
288
|
+
client.send = jest.fn();
|
|
289
|
+
client.subscribe(params, cb, errorCb, true);
|
|
290
|
+
expect(client.subscriptions.length).toBe(1);
|
|
291
|
+
expect(client.subscriptions[0].params).toBe(params);
|
|
292
|
+
expect(client.subscriptions[0].cb).toBe(cb);
|
|
293
|
+
expect(client.subscriptions[0].errorCb).toBe(errorCb);
|
|
294
|
+
expect(client.subscriptions[0].quiet).toBe(true);
|
|
295
|
+
expect(client.send).toBeCalledTimes(0);
|
|
296
|
+
client.send.mockRestore();
|
|
297
|
+
}));
|
|
298
|
+
});
|
|
299
|
+
describe('#unsubscribe', () => {
|
|
300
|
+
test('should only unsubscribe the subscription using the good cb', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
+
// eslint-disable-next-line no-unused-vars
|
|
302
|
+
const client = new WebSocketAPI();
|
|
303
|
+
client.connect(`ws://foo:1234`);
|
|
304
|
+
yield server.connected;
|
|
305
|
+
const params = { channel: 'foo', id: 'id' };
|
|
306
|
+
const cb = jest.fn();
|
|
307
|
+
const cb2 = jest.fn();
|
|
308
|
+
client.subscribe(params, cb);
|
|
309
|
+
client.subscribe(params, cb2);
|
|
310
|
+
expect(client.subscriptions.length).toBe(2);
|
|
311
|
+
expect(client.subscriptions[0].params).toBe(params);
|
|
312
|
+
expect(client.subscriptions[0].cb).toBe(cb);
|
|
313
|
+
expect(client.subscriptions[1].params).toBe(params);
|
|
314
|
+
expect(client.subscriptions[1].cb).toBe(cb2);
|
|
315
|
+
client.unsubscribe('foo', cb);
|
|
316
|
+
expect(client.subscriptions.length).toBe(1);
|
|
317
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
318
|
+
expect(cb2).toHaveBeenCalledTimes(0);
|
|
319
|
+
const obj = { source: 'foo', client_reference: 'id' };
|
|
320
|
+
server.send(JSON.stringify(obj));
|
|
321
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
322
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
323
|
+
}));
|
|
324
|
+
test('should unsubscribe all subscriptions related to a channel', () => {
|
|
325
|
+
// eslint-disable-next-line no-unused-vars
|
|
326
|
+
const client = new WebSocketAPI();
|
|
327
|
+
client.connect(`ws://foo:1234`);
|
|
328
|
+
client.websocket.removeEventListener = jest.fn();
|
|
329
|
+
client.websocket.addEventListener = jest.fn();
|
|
330
|
+
const params = { channel: 'foo' };
|
|
331
|
+
const params2 = { channel: 'bar' };
|
|
332
|
+
const cb = jest.fn();
|
|
333
|
+
const cb2 = jest.fn();
|
|
334
|
+
client.subscribe(params, cb);
|
|
335
|
+
client.subscribe(params, cb);
|
|
336
|
+
client.subscribe(params, cb);
|
|
337
|
+
client.subscribe(params, cb2);
|
|
338
|
+
client.subscribe(params2, cb2);
|
|
339
|
+
expect(client.subscriptions.length).toBe(3);
|
|
340
|
+
expect(client.websocket.removeEventListener).toBeCalledTimes(2);
|
|
341
|
+
expect(client.websocket.addEventListener.mock.calls.filter((c) => c[0] === 'message').length).toBe(5);
|
|
342
|
+
client.unsubscribe('foo');
|
|
343
|
+
expect(client.subscriptions.length).toBe(1);
|
|
344
|
+
expect(client.subscriptions[0].params).toBe(params2);
|
|
345
|
+
expect(client.subscriptions[0].cb).toBe(cb2);
|
|
346
|
+
});
|
|
347
|
+
test('send DEL when there is no more unquiet subscriptions on the channel', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
348
|
+
// eslint-disable-next-line no-unused-vars
|
|
349
|
+
const client = new WebSocketAPI();
|
|
350
|
+
client.connect(`ws://foo:1234`);
|
|
351
|
+
yield server.connected;
|
|
352
|
+
client.send = jest.fn();
|
|
353
|
+
client.websocket.removeEventListener = jest.fn();
|
|
354
|
+
client.websocket.addEventListener = jest.fn();
|
|
355
|
+
const params = { channel: 'foo' };
|
|
356
|
+
const cb = jest.fn();
|
|
357
|
+
client.subscribe(params, cb);
|
|
358
|
+
expect(client.send).toHaveBeenCalledWith('GET foo');
|
|
359
|
+
expect(client.send).toHaveBeenCalledWith('SUB foo');
|
|
360
|
+
client.unsubscribe('foo');
|
|
361
|
+
expect(client.send).toHaveBeenCalledWith('DEL foo');
|
|
362
|
+
}));
|
|
363
|
+
test("doesn't send DEL when we unsubscribe a quiet channel", () => {
|
|
364
|
+
// eslint-disable-next-line no-unused-vars
|
|
365
|
+
const client = new WebSocketAPI();
|
|
366
|
+
client.connect(`ws://foo:1234`);
|
|
367
|
+
client.send = jest.fn();
|
|
368
|
+
client.websocket.removeEventListener = jest.fn();
|
|
369
|
+
client.websocket.addEventListener = jest.fn();
|
|
370
|
+
const params = { channel: 'foo' };
|
|
371
|
+
const cb = jest.fn();
|
|
372
|
+
client.subscribe(params, cb, null, true);
|
|
373
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
374
|
+
client.unsubscribe('foo');
|
|
375
|
+
expect(cb).toHaveBeenCalledTimes(0);
|
|
376
|
+
client.send.mockRestore();
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Control.test.d.ts","sourceRoot":"","sources":["../../../src/common/controls/Control.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Control from './Control';
|
|
2
|
+
describe('Control', () => {
|
|
3
|
+
test('should be activated by default', () => {
|
|
4
|
+
const control = new Control();
|
|
5
|
+
expect(control.active).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
test('should not be activated if set to false in the options', () => {
|
|
8
|
+
const control = new Control({ active: false });
|
|
9
|
+
expect(control.active).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
test('should call activate/deactivate when active is set to true/false', () => {
|
|
12
|
+
const control = new Control();
|
|
13
|
+
const spy1 = jest.spyOn(control, 'activate');
|
|
14
|
+
const spy2 = jest.spyOn(control, 'deactivate');
|
|
15
|
+
const spy3 = jest.spyOn(control, 'render');
|
|
16
|
+
control.active = false;
|
|
17
|
+
expect(spy1).toBeCalledTimes(0);
|
|
18
|
+
expect(spy2).toBeCalledTimes(1);
|
|
19
|
+
expect(spy3).toBeCalledTimes(1);
|
|
20
|
+
control.active = true;
|
|
21
|
+
expect(spy1).toBeCalledTimes(1);
|
|
22
|
+
expect(spy2).toBeCalledTimes(2);
|
|
23
|
+
expect(spy3).toBeCalledTimes(2);
|
|
24
|
+
});
|
|
25
|
+
test('should append/remove the element to the map container when map is set', () => {
|
|
26
|
+
const element = document.createElement('div');
|
|
27
|
+
const target = document.createElement('div');
|
|
28
|
+
const control = new Control({
|
|
29
|
+
element,
|
|
30
|
+
});
|
|
31
|
+
const spy1 = jest.spyOn(control, 'activate');
|
|
32
|
+
const spy2 = jest.spyOn(control, 'deactivate');
|
|
33
|
+
const spy3 = jest.spyOn(control, 'render');
|
|
34
|
+
control.map = {
|
|
35
|
+
getContainer() {
|
|
36
|
+
return target;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
expect(target.childNodes[0]).toBe(element);
|
|
40
|
+
expect(spy1).toBeCalledTimes(1);
|
|
41
|
+
expect(spy2).toBeCalledTimes(2);
|
|
42
|
+
expect(spy3).toBeCalledTimes(1);
|
|
43
|
+
control.detachFromMap();
|
|
44
|
+
expect(target.childNodes[0]).toBe();
|
|
45
|
+
expect(spy1).toBeCalledTimes(1);
|
|
46
|
+
expect(spy2).toBeCalledTimes(3);
|
|
47
|
+
expect(spy3).toBeCalledTimes(2);
|
|
48
|
+
});
|
|
49
|
+
test('should append/remove the element to the target property when map is set', () => {
|
|
50
|
+
const element = document.createElement('div');
|
|
51
|
+
const target = document.createElement('div');
|
|
52
|
+
const control = new Control({
|
|
53
|
+
target,
|
|
54
|
+
element,
|
|
55
|
+
});
|
|
56
|
+
const spy1 = jest.spyOn(control, 'activate');
|
|
57
|
+
const spy2 = jest.spyOn(control, 'deactivate');
|
|
58
|
+
const spy3 = jest.spyOn(control, 'render');
|
|
59
|
+
control.map = {};
|
|
60
|
+
expect(target.childNodes[0]).toBe(element);
|
|
61
|
+
expect(spy1).toBeCalledTimes(1);
|
|
62
|
+
expect(spy2).toBeCalledTimes(2);
|
|
63
|
+
expect(spy3).toBeCalledTimes(1);
|
|
64
|
+
control.detachFromMap();
|
|
65
|
+
expect(target.childNodes[0]).toBe();
|
|
66
|
+
expect(spy1).toBeCalledTimes(1);
|
|
67
|
+
expect(spy2).toBeCalledTimes(3);
|
|
68
|
+
expect(spy3).toBeCalledTimes(2);
|
|
69
|
+
});
|
|
70
|
+
test('set a custom render method', () => {
|
|
71
|
+
const spy = jest.fn();
|
|
72
|
+
// eslint-disable-next-line no-unused-vars
|
|
73
|
+
const control = new Control({
|
|
74
|
+
render: spy,
|
|
75
|
+
});
|
|
76
|
+
expect(spy).toBeCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
test('pass function params to custom render method', () => {
|
|
79
|
+
const spy = jest.fn();
|
|
80
|
+
// eslint-disable-next-line no-unused-vars
|
|
81
|
+
const control = new Control({
|
|
82
|
+
render: spy,
|
|
83
|
+
});
|
|
84
|
+
control.render('foo', 'bar');
|
|
85
|
+
expect(spy).toBeCalledTimes(2);
|
|
86
|
+
expect(spy.mock.calls[1][0]).toBe('foo');
|
|
87
|
+
expect(spy.mock.calls[1][1]).toBe('bar');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Layer.test.d.ts","sourceRoot":"","sources":["../../../src/common/layers/Layer.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
2
|
+
import VectorSource from 'ol/source/Vector';
|
|
3
|
+
import Layer from './Layer';
|
|
4
|
+
const olLayer = new VectorLayer({ source: new VectorSource() });
|
|
5
|
+
describe('Layer', () => {
|
|
6
|
+
test('should initialize.', () => {
|
|
7
|
+
const layer = new Layer({ name: 'Layer', olLayer });
|
|
8
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
9
|
+
});
|
|
10
|
+
test('should define default properties.', () => {
|
|
11
|
+
const options = {
|
|
12
|
+
name: 'Layer',
|
|
13
|
+
key: 'Layerkey',
|
|
14
|
+
olLayer,
|
|
15
|
+
};
|
|
16
|
+
const layer = new Layer(options);
|
|
17
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
18
|
+
expect(layer.options).toEqual(options);
|
|
19
|
+
expect(layer.name).toEqual(options.name);
|
|
20
|
+
expect(layer.key).toEqual('Layerkey');
|
|
21
|
+
expect(layer.hitTolerance).toBe(5);
|
|
22
|
+
expect(layer.copyrights).toEqual([]);
|
|
23
|
+
expect(layer.visible).toBe(true);
|
|
24
|
+
expect(layer.properties).toEqual({});
|
|
25
|
+
expect(layer.map).toBe(undefined);
|
|
26
|
+
expect(layer.group).toBe(undefined);
|
|
27
|
+
});
|
|
28
|
+
test('should be visible by default.', () => {
|
|
29
|
+
const layer = new Layer();
|
|
30
|
+
expect(layer.visible).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
test('should be hidden using constructor.', () => {
|
|
33
|
+
const layer = new Layer({ visible: false });
|
|
34
|
+
expect(layer.visible).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
test('should be hidden using setter.', () => {
|
|
37
|
+
const layer = new Layer();
|
|
38
|
+
layer.visible = false;
|
|
39
|
+
expect(layer.visible).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
test('should visibility stay unchanged', () => {
|
|
42
|
+
const layer = new Layer();
|
|
43
|
+
layer.visible = false;
|
|
44
|
+
expect(layer.visible).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
test('should return its name.', () => {
|
|
47
|
+
const layer = new Layer({ name: 'Layer' });
|
|
48
|
+
expect(layer.name).toEqual('Layer');
|
|
49
|
+
});
|
|
50
|
+
test('should called detachFromMap on initialization.', () => {
|
|
51
|
+
const layer = new Layer();
|
|
52
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
53
|
+
layer.attachToMap();
|
|
54
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
55
|
+
});
|
|
56
|
+
test('should properties correctly set and get.', () => {
|
|
57
|
+
const layer = new Layer({
|
|
58
|
+
name: 'Layer',
|
|
59
|
+
olLayer,
|
|
60
|
+
properties: {
|
|
61
|
+
abc: 'foo',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
65
|
+
expect(layer.get('abc')).toEqual('foo');
|
|
66
|
+
layer.set('abc', 'bar');
|
|
67
|
+
expect(layer.get('abc')).toEqual('bar');
|
|
68
|
+
});
|
|
69
|
+
test('should set children', () => {
|
|
70
|
+
const layer = new Layer({
|
|
71
|
+
children: [new Layer(), new Layer()],
|
|
72
|
+
});
|
|
73
|
+
expect(layer.children.length).toBe(2);
|
|
74
|
+
expect(layer.children[0].parent).toBe(layer);
|
|
75
|
+
expect(layer.children[1].parent).toBe(layer);
|
|
76
|
+
});
|
|
77
|
+
test('should initialize copyrights property.', () => {
|
|
78
|
+
const layer = new Layer({
|
|
79
|
+
name: 'Layer',
|
|
80
|
+
olLayer,
|
|
81
|
+
copyrights: ['©: copyright', 'another copyright'],
|
|
82
|
+
});
|
|
83
|
+
expect(layer.copyrights[0]).toEqual('©: copyright');
|
|
84
|
+
});
|
|
85
|
+
test('should set and get copyright property.', () => {
|
|
86
|
+
const layer = new Layer({
|
|
87
|
+
name: 'Layer',
|
|
88
|
+
olLayer,
|
|
89
|
+
});
|
|
90
|
+
expect(layer).toBeInstanceOf(Layer);
|
|
91
|
+
expect(layer.copyright).toEqual(undefined);
|
|
92
|
+
layer.copyright = '© OSM Contributors';
|
|
93
|
+
expect(layer.copyright).toEqual('© OSM Contributors');
|
|
94
|
+
});
|
|
95
|
+
describe('#attachToMap()', () => {
|
|
96
|
+
test('should set map.', () => {
|
|
97
|
+
const layer = new Layer({
|
|
98
|
+
name: 'Layer',
|
|
99
|
+
olLayer,
|
|
100
|
+
});
|
|
101
|
+
expect(layer.map).toBe(undefined);
|
|
102
|
+
const obj = {};
|
|
103
|
+
layer.attachToMap(obj);
|
|
104
|
+
expect(layer.map).toBe(obj);
|
|
105
|
+
});
|
|
106
|
+
test('should call terminate.', () => {
|
|
107
|
+
const layer = new Layer({
|
|
108
|
+
name: 'Layer',
|
|
109
|
+
olLayer,
|
|
110
|
+
});
|
|
111
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
112
|
+
layer.attachToMap();
|
|
113
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('#getFeatureInfoAtCoordinate()', () => {
|
|
117
|
+
test('return an empty fetaureInfo object and display an error message', (done) => {
|
|
118
|
+
// eslint-disable-next-line no-console
|
|
119
|
+
console.error = jest.fn();
|
|
120
|
+
const layer = new Layer({
|
|
121
|
+
name: 'Layer',
|
|
122
|
+
olLayer,
|
|
123
|
+
});
|
|
124
|
+
const coord = [0, 0];
|
|
125
|
+
layer.getFeatureInfoAtCoordinate(coord).then((featureInfo) => {
|
|
126
|
+
expect(featureInfo.features).toEqual([]);
|
|
127
|
+
expect(featureInfo.layer).toEqual(layer);
|
|
128
|
+
expect(featureInfo.coordinate).toEqual(coord);
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
expect(console.error).toHaveBeenCalledTimes(1);
|
|
131
|
+
done();
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.error.mockRestore();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserInteractionsLayerMixin.test.d.ts","sourceRoot":"","sources":["../../../src/common/mixins/UserInteractionsLayerMixin.test.js"],"names":[],"mappings":""}
|