mobility-toolbox-js 2.0.0-beta.30 → 2.0.0-beta.34
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/api/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +626 -343
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +65 -15
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +70 -12
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +10 -3
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +72 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +82 -30
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +313 -168
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/controls/Control.js +167 -78
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +18 -2
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/layers/Layer.js +251 -134
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.js +70 -22
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.js +240 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +698 -429
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.js +195 -107
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +222 -121
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +24 -4
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +236 -190
- package/common/styles/realtimeDelayStyle.d.ts +11 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +25 -7
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -17
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +21 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/cleanStopTime.js +28 -17
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +34 -22
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +28 -16
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.js +75 -54
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -13
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +24 -17
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +77 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +11 -2
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +20 -10
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +63 -39
- package/common/utils/index.d.ts +12 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +37 -9
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +29 -7
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +111 -78
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +21 -17
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +47 -18
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/common/utils/trackerConfig.js +171 -118
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +7 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -7
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +72 -28
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +6 -1
- package/mapbox/index.d.ts +5 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +20 -4
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +137 -54
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +310 -183
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +7 -2
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mapbox/utils.js +54 -29
- package/mbt.js +2052 -2109
- package/mbt.js.map +3 -3
- package/mbt.min.js +18 -18
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +89 -41
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +666 -371
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +59 -10
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +9 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +21 -5
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +178 -81
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +131 -198
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +382 -186
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +67 -138
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +327 -184
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +111 -56
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +71 -21
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +105 -37
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +19 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +44 -40
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +7 -2
- package/package.json +14 -36
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +15 -0
- package/types/index.d.ts +7 -6
- package/types/routing.d.ts +25 -25
- package/types/stops.d.ts +19 -19
- package/api/RealtimeAPI.test.js +0 -67
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.test.js +0 -134
- package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/common/utils/trackerConfig.test.js +0 -23
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/RealtimeLayer.test.js +0 -10
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -146
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -175
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -226
- package/ol/layers/RealtimeLayer.test.js +0 -67
- package/ol/layers/RoutingLayer.test.js +0 -39
- package/ol/layers/VectorLayer.test.js +0 -76
- package/ol/layers/WMSLayer.test.js +0 -57
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import WS from "jest-websocket-mock";
|
|
2
|
-
import WebSocketAPI from "./WebSocketAPI";
|
|
3
|
-
describe("WebSocketAPI", () => {
|
|
4
|
-
describe("#constructor", () => {
|
|
5
|
-
let server;
|
|
6
|
-
let server2;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
server = new WS(`ws://foo:1234`);
|
|
9
|
-
server2 = new WS(`ws://foo:12345`);
|
|
10
|
-
});
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
server.close();
|
|
13
|
-
server2.close();
|
|
14
|
-
WS.clean();
|
|
15
|
-
});
|
|
16
|
-
describe("#constructor", () => {
|
|
17
|
-
test("doesn't connect.", async () => {
|
|
18
|
-
const client = new WebSocketAPI();
|
|
19
|
-
expect(client.websocket).toBe();
|
|
20
|
-
expect(client.closed).toBe(false);
|
|
21
|
-
expect(client.closing).toBe(false);
|
|
22
|
-
expect(client.connecting).toBe(false);
|
|
23
|
-
expect(client.open).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe("#close", () => {
|
|
27
|
-
test("should close the websocket and clear some property", async () => {
|
|
28
|
-
const client = new WebSocketAPI();
|
|
29
|
-
const subsc2 = {
|
|
30
|
-
params: "foo",
|
|
31
|
-
cb: () => {
|
|
32
|
-
},
|
|
33
|
-
errorCb: () => {
|
|
34
|
-
},
|
|
35
|
-
quiet: false
|
|
36
|
-
};
|
|
37
|
-
client.subscriptions = [subsc2];
|
|
38
|
-
client.messagesOnOpen = ["GET foo"];
|
|
39
|
-
client.connect(`ws://foo:1234`);
|
|
40
|
-
client.websocket.addEventListener = jest.fn();
|
|
41
|
-
client.websocket.removeEventListener = jest.fn();
|
|
42
|
-
client.websocket.close = jest.fn();
|
|
43
|
-
await server.connected;
|
|
44
|
-
expect(client.websocket).toBeDefined();
|
|
45
|
-
expect(client.messagesOnOpen).toEqual(["GET foo"]);
|
|
46
|
-
client.close();
|
|
47
|
-
expect(client.messagesOnOpen).toEqual([]);
|
|
48
|
-
expect(client.websocket).toBeNull();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe("#connect", () => {
|
|
52
|
-
test("create a new WebSocket.", async () => {
|
|
53
|
-
const client = new WebSocketAPI();
|
|
54
|
-
client.connect(`ws://foo:1234`);
|
|
55
|
-
await server.connected;
|
|
56
|
-
client.send("hello");
|
|
57
|
-
await expect(server).toReceiveMessage("hello");
|
|
58
|
-
expect(server).toHaveReceivedMessages(["hello"]);
|
|
59
|
-
});
|
|
60
|
-
test("close previous connection.", async () => {
|
|
61
|
-
const client = new WebSocketAPI();
|
|
62
|
-
client.connect(`ws://foo:1234`);
|
|
63
|
-
await server.connected;
|
|
64
|
-
expect(client.websocket).toBeDefined();
|
|
65
|
-
const old = client.websocket;
|
|
66
|
-
expect(old.readyState).toBe(WebSocket.OPEN);
|
|
67
|
-
client.connect(`ws://foo:12345`);
|
|
68
|
-
expect(old.readyState).toBe(WebSocket.CLOSING);
|
|
69
|
-
expect(client.websocket.readyState).toBe(WebSocket.CONNECTING);
|
|
70
|
-
});
|
|
71
|
-
test("call onOpen function", async () => {
|
|
72
|
-
const onOpen = jest.fn();
|
|
73
|
-
const client = new WebSocketAPI();
|
|
74
|
-
client.subscribe = jest.fn();
|
|
75
|
-
client.connect(`ws://foo:1234`, onOpen);
|
|
76
|
-
await server.connected;
|
|
77
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
78
|
-
expect(onOpen).toHaveBeenCalledTimes(1);
|
|
79
|
-
});
|
|
80
|
-
test("subscribe previous subscriptions on open (quiet or not)", async () => {
|
|
81
|
-
const client = new WebSocketAPI();
|
|
82
|
-
client.subscribe = jest.fn();
|
|
83
|
-
client.send = jest.fn();
|
|
84
|
-
const subsc = {
|
|
85
|
-
params: "foo",
|
|
86
|
-
cb: () => {
|
|
87
|
-
},
|
|
88
|
-
errorCb: () => {
|
|
89
|
-
},
|
|
90
|
-
quiet: true
|
|
91
|
-
};
|
|
92
|
-
const subsc2 = {
|
|
93
|
-
params: "foo",
|
|
94
|
-
cb: () => {
|
|
95
|
-
},
|
|
96
|
-
errorCb: () => {
|
|
97
|
-
},
|
|
98
|
-
quiet: false
|
|
99
|
-
};
|
|
100
|
-
client.subscriptions = [subsc, subsc2];
|
|
101
|
-
client.connect(`ws://foo:1234`);
|
|
102
|
-
await server.connected;
|
|
103
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
104
|
-
expect(client.subscribe).toHaveBeenCalledTimes(2);
|
|
105
|
-
client.subscribe.mockReset();
|
|
106
|
-
client.connect(`ws://foo:12345`);
|
|
107
|
-
await server2.connected;
|
|
108
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
109
|
-
expect(client.subscribe).toHaveBeenCalledTimes(2);
|
|
110
|
-
expect(client.subscribe).toHaveBeenCalledWith(subsc.params, subsc.cb, subsc.errorCb, subsc.quiet);
|
|
111
|
-
});
|
|
112
|
-
test("send GET and SUB for not quiet previous subscriptions", async () => {
|
|
113
|
-
const client = new WebSocketAPI();
|
|
114
|
-
client.send = jest.fn();
|
|
115
|
-
const subsc = {
|
|
116
|
-
params: { channel: "foo" },
|
|
117
|
-
cb: () => {
|
|
118
|
-
},
|
|
119
|
-
errorCb: () => {
|
|
120
|
-
},
|
|
121
|
-
quiet: false
|
|
122
|
-
};
|
|
123
|
-
client.subscriptions = [subsc];
|
|
124
|
-
client.connect(`ws://foo:1234`);
|
|
125
|
-
client.websocket.addEventListener = jest.fn();
|
|
126
|
-
client.websocket.removeEventListener = jest.fn();
|
|
127
|
-
await server.connected;
|
|
128
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
129
|
-
expect(client.send).toHaveBeenCalledTimes(2);
|
|
130
|
-
expect(client.send.mock.calls[0]).toEqual(["GET foo"]);
|
|
131
|
-
expect(client.send.mock.calls[1]).toEqual(["SUB foo"]);
|
|
132
|
-
client.send.mockReset();
|
|
133
|
-
client.connect(`ws://foo:12345`);
|
|
134
|
-
client.websocket.addEventListener = jest.fn();
|
|
135
|
-
client.websocket.removeEventListener = jest.fn();
|
|
136
|
-
await server2.connected;
|
|
137
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
138
|
-
expect(client.send).toHaveBeenCalledTimes(2);
|
|
139
|
-
expect(client.send.mock.calls[0]).toEqual(["GET foo"]);
|
|
140
|
-
expect(client.send.mock.calls[1]).toEqual(["SUB foo"]);
|
|
141
|
-
});
|
|
142
|
-
test("doesn send GET and SUB for quiet previous subscriptions", async () => {
|
|
143
|
-
const client = new WebSocketAPI();
|
|
144
|
-
client.send = jest.fn();
|
|
145
|
-
const subsc = {
|
|
146
|
-
params: { channel: "foo" },
|
|
147
|
-
cb: () => {
|
|
148
|
-
},
|
|
149
|
-
errorCb: () => {
|
|
150
|
-
},
|
|
151
|
-
quiet: true
|
|
152
|
-
};
|
|
153
|
-
client.subscriptions = [subsc];
|
|
154
|
-
client.connect(`ws://foo:1234`);
|
|
155
|
-
client.websocket.addEventListener = jest.fn();
|
|
156
|
-
client.websocket.removeEventListener = jest.fn();
|
|
157
|
-
await server.connected;
|
|
158
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
159
|
-
expect(client.send).toHaveBeenCalledTimes(0);
|
|
160
|
-
client.send.mockReset();
|
|
161
|
-
client.connect(`ws://foo:12345`);
|
|
162
|
-
client.websocket.addEventListener = jest.fn();
|
|
163
|
-
client.websocket.removeEventListener = jest.fn();
|
|
164
|
-
await server2.connected;
|
|
165
|
-
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
166
|
-
expect(client.send).toHaveBeenCalledTimes(0);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe("#subscribe", () => {
|
|
170
|
-
test("adds subscription to subscriptions array", async () => {
|
|
171
|
-
const client = new WebSocketAPI();
|
|
172
|
-
client.connect(`ws://foo:1234`);
|
|
173
|
-
await server.connected;
|
|
174
|
-
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
175
|
-
const cb = jest.fn();
|
|
176
|
-
const errorCb = jest.fn();
|
|
177
|
-
client.subscribe(params, cb, errorCb);
|
|
178
|
-
expect(client.subscriptions.length).toBe(1);
|
|
179
|
-
expect(client.subscriptions[0].params).toBe(params);
|
|
180
|
-
expect(client.subscriptions[0].cb).toBe(cb);
|
|
181
|
-
expect(client.subscriptions[0].errorCb).toBe(errorCb);
|
|
182
|
-
expect(client.subscriptions[0].quiet).toBe(false);
|
|
183
|
-
const obj = { source: "bar baz", client_reference: "id" };
|
|
184
|
-
server.send(JSON.stringify(obj));
|
|
185
|
-
expect(cb).toHaveBeenCalledTimes(1);
|
|
186
|
-
expect(cb).toHaveBeenCalledWith(obj);
|
|
187
|
-
});
|
|
188
|
-
test("doesn't duplicate subscriptions", async () => {
|
|
189
|
-
const client = new WebSocketAPI();
|
|
190
|
-
client.connect(`ws://foo:1234`);
|
|
191
|
-
await server.connected;
|
|
192
|
-
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
193
|
-
const cb = jest.fn();
|
|
194
|
-
const errorCb = jest.fn();
|
|
195
|
-
client.subscribe(params, cb, errorCb, true);
|
|
196
|
-
client.subscribe(params, cb, errorCb, true);
|
|
197
|
-
expect(client.subscriptions.length).toBe(1);
|
|
198
|
-
const obj = { source: "bar baz", client_reference: "id" };
|
|
199
|
-
server.send(JSON.stringify(obj));
|
|
200
|
-
expect(cb).toHaveBeenCalledTimes(1);
|
|
201
|
-
expect(cb).toHaveBeenCalledWith(obj);
|
|
202
|
-
});
|
|
203
|
-
test("send GET and SUB requests.", async () => {
|
|
204
|
-
const client = new WebSocketAPI();
|
|
205
|
-
client.connect(`ws://foo:1234`);
|
|
206
|
-
client.send = jest.fn();
|
|
207
|
-
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
208
|
-
const cb = jest.fn();
|
|
209
|
-
const errorCb = jest.fn();
|
|
210
|
-
client.subscribe(params, cb, errorCb);
|
|
211
|
-
expect(client.send).toHaveBeenCalledTimes(2);
|
|
212
|
-
expect(client.send).toHaveBeenCalledWith("GET bar baz id");
|
|
213
|
-
expect(client.send).toHaveBeenCalledWith("SUB bar baz id");
|
|
214
|
-
client.send.mockRestore();
|
|
215
|
-
});
|
|
216
|
-
test("should register callback without sending GET and SUB requests (quiet=true).", async () => {
|
|
217
|
-
const client = new WebSocketAPI();
|
|
218
|
-
client.connect(`ws://foo:1234`);
|
|
219
|
-
await server.connected;
|
|
220
|
-
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
221
|
-
const cb = jest.fn();
|
|
222
|
-
const errorCb = jest.fn();
|
|
223
|
-
client.send = jest.fn();
|
|
224
|
-
client.subscribe(params, cb, errorCb, true);
|
|
225
|
-
expect(client.subscriptions.length).toBe(1);
|
|
226
|
-
expect(client.subscriptions[0].params).toBe(params);
|
|
227
|
-
expect(client.subscriptions[0].cb).toBe(cb);
|
|
228
|
-
expect(client.subscriptions[0].errorCb).toBe(errorCb);
|
|
229
|
-
expect(client.subscriptions[0].quiet).toBe(true);
|
|
230
|
-
expect(client.send).toBeCalledTimes(0);
|
|
231
|
-
client.send.mockRestore();
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
describe("#unsubscribe", () => {
|
|
235
|
-
test("should only unsubscribe the subscription using the good cb", async () => {
|
|
236
|
-
const client = new WebSocketAPI();
|
|
237
|
-
client.connect(`ws://foo:1234`);
|
|
238
|
-
await server.connected;
|
|
239
|
-
const params = { channel: "foo", id: "id" };
|
|
240
|
-
const cb = jest.fn();
|
|
241
|
-
const cb2 = jest.fn();
|
|
242
|
-
client.subscribe(params, cb);
|
|
243
|
-
client.subscribe(params, cb2);
|
|
244
|
-
expect(client.subscriptions.length).toBe(2);
|
|
245
|
-
expect(client.subscriptions[0].params).toBe(params);
|
|
246
|
-
expect(client.subscriptions[0].cb).toBe(cb);
|
|
247
|
-
expect(client.subscriptions[1].params).toBe(params);
|
|
248
|
-
expect(client.subscriptions[1].cb).toBe(cb2);
|
|
249
|
-
client.unsubscribe("foo", cb);
|
|
250
|
-
expect(client.subscriptions.length).toBe(1);
|
|
251
|
-
expect(cb).toHaveBeenCalledTimes(0);
|
|
252
|
-
expect(cb2).toHaveBeenCalledTimes(0);
|
|
253
|
-
const obj = { source: "foo", client_reference: "id" };
|
|
254
|
-
server.send(JSON.stringify(obj));
|
|
255
|
-
expect(cb2).toHaveBeenCalledTimes(1);
|
|
256
|
-
expect(cb).toHaveBeenCalledTimes(0);
|
|
257
|
-
});
|
|
258
|
-
test("should unsubscribe all subscriptions related to a channel", () => {
|
|
259
|
-
const client = new WebSocketAPI();
|
|
260
|
-
client.connect(`ws://foo:1234`);
|
|
261
|
-
client.websocket.removeEventListener = jest.fn();
|
|
262
|
-
client.websocket.addEventListener = jest.fn();
|
|
263
|
-
const params = { channel: "foo" };
|
|
264
|
-
const params2 = { channel: "bar" };
|
|
265
|
-
const cb = jest.fn();
|
|
266
|
-
const cb2 = jest.fn();
|
|
267
|
-
client.subscribe(params, cb);
|
|
268
|
-
client.subscribe(params, cb);
|
|
269
|
-
client.subscribe(params, cb);
|
|
270
|
-
client.subscribe(params, cb2);
|
|
271
|
-
client.subscribe(params2, cb2);
|
|
272
|
-
expect(client.subscriptions.length).toBe(3);
|
|
273
|
-
expect(client.websocket.removeEventListener).toBeCalledTimes(2);
|
|
274
|
-
expect(client.websocket.addEventListener.mock.calls.filter((c) => c[0] === "message").length).toBe(5);
|
|
275
|
-
client.unsubscribe("foo");
|
|
276
|
-
expect(client.subscriptions.length).toBe(1);
|
|
277
|
-
expect(client.subscriptions[0].params).toBe(params2);
|
|
278
|
-
expect(client.subscriptions[0].cb).toBe(cb2);
|
|
279
|
-
});
|
|
280
|
-
test("send DEL when there is no more unquiet subscriptions on the channel", async () => {
|
|
281
|
-
const client = new WebSocketAPI();
|
|
282
|
-
client.connect(`ws://foo:1234`);
|
|
283
|
-
await server.connected;
|
|
284
|
-
client.send = jest.fn();
|
|
285
|
-
client.websocket.removeEventListener = jest.fn();
|
|
286
|
-
client.websocket.addEventListener = jest.fn();
|
|
287
|
-
const params = { channel: "foo" };
|
|
288
|
-
const cb = jest.fn();
|
|
289
|
-
client.subscribe(params, cb);
|
|
290
|
-
expect(client.send).toHaveBeenCalledWith("GET foo");
|
|
291
|
-
expect(client.send).toHaveBeenCalledWith("SUB foo");
|
|
292
|
-
client.unsubscribe("foo");
|
|
293
|
-
expect(client.send).toHaveBeenCalledWith("DEL foo");
|
|
294
|
-
});
|
|
295
|
-
test("doesn't send DEL when we unsubscribe a quiet channel", () => {
|
|
296
|
-
const client = new WebSocketAPI();
|
|
297
|
-
client.connect(`ws://foo:1234`);
|
|
298
|
-
client.send = jest.fn();
|
|
299
|
-
client.websocket.removeEventListener = jest.fn();
|
|
300
|
-
client.websocket.addEventListener = jest.fn();
|
|
301
|
-
const params = { channel: "foo" };
|
|
302
|
-
const cb = jest.fn();
|
|
303
|
-
client.subscribe(params, cb, null, true);
|
|
304
|
-
expect(cb).toHaveBeenCalledTimes(0);
|
|
305
|
-
client.unsubscribe("foo");
|
|
306
|
-
expect(cb).toHaveBeenCalledTimes(0);
|
|
307
|
-
client.send.mockRestore();
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
const control = new Control({
|
|
73
|
-
render: spy
|
|
74
|
-
});
|
|
75
|
-
expect(spy).toBeCalledTimes(1);
|
|
76
|
-
});
|
|
77
|
-
test("pass function params to custom render method", () => {
|
|
78
|
-
const spy = jest.fn();
|
|
79
|
-
const control = new Control({
|
|
80
|
-
render: spy
|
|
81
|
-
});
|
|
82
|
-
control.render("foo", "bar");
|
|
83
|
-
expect(spy).toBeCalledTimes(2);
|
|
84
|
-
expect(spy.mock.calls[1][0]).toBe("foo");
|
|
85
|
-
expect(spy.mock.calls[1][1]).toBe("bar");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,134 +0,0 @@
|
|
|
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(void 0);
|
|
26
|
-
expect(layer.group).toBe(void 0);
|
|
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(void 0);
|
|
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(void 0);
|
|
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
|
-
console.error = jest.fn();
|
|
119
|
-
const layer = new Layer({
|
|
120
|
-
name: "Layer",
|
|
121
|
-
olLayer
|
|
122
|
-
});
|
|
123
|
-
const coord = [0, 0];
|
|
124
|
-
layer.getFeatureInfoAtCoordinate(coord).then((featureInfo) => {
|
|
125
|
-
expect(featureInfo.features).toEqual([]);
|
|
126
|
-
expect(featureInfo.layer).toEqual(layer);
|
|
127
|
-
expect(featureInfo.coordinate).toEqual(coord);
|
|
128
|
-
expect(console.error).toHaveBeenCalledTimes(1);
|
|
129
|
-
done();
|
|
130
|
-
console.error.mockRestore();
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|