mobility-toolbox-js 2.0.0-beta.8 → 2.0.1-beta.13
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/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/{src/api/tralis → api}/TralisAPIUtils.js +2 -32
- package/api/index.js +3 -0
- package/{index.html → api/typedefs.js} +0 -0
- package/common/Tracker.js +93 -0
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{src/api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +81 -0
- package/{src/common → common}/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +213 -0
- package/{src/common → common}/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +24 -0
- package/common/mixins/SearchMixin.js +110 -0
- package/common/mixins/TralisLayerMixin.js +479 -0
- package/common/styles/index.js +4 -0
- package/{src/common → common}/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +8 -0
- package/{src/common → common}/styles/trackerSimpleStyle.js +4 -8
- package/{src/common → common}/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +23 -0
- package/{src/doc/examples/ol-mapbox-layer.md → common/typedefs.js} +0 -0
- package/common/utils/createTrackerFilters.js +56 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/{src/common → common}/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/{src/common → common}/utils/getMapboxStyleUrl.js +3 -13
- package/{src/common → common}/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -0
- package/common/utils/removeDuplicate.js +8 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/{src/common → common}/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +20 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/index.js +8 -0
- package/mapbox/controls/CopyrightControl.js +29 -0
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -0
- package/mapbox/layers/Layer.js +57 -0
- package/mapbox/layers/Layer.test.js +182 -0
- package/mapbox/layers/TralisLayer.js +182 -0
- package/{src/mapbox → mapbox}/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/{src/mapbox → mapbox}/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +42 -0
- package/ol/controls/CopyrightControl.test.js +165 -0
- package/ol/controls/RoutingControl.js +387 -0
- package/ol/controls/RoutingControl.test.js +151 -0
- package/ol/controls/StopFinderControl.js +10 -0
- package/ol/controls/StopFinderControl.test.js +48 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -0
- package/ol/layers/Layer.js +88 -0
- package/ol/layers/Layer.test.js +174 -0
- package/ol/layers/MapboxLayer.js +203 -0
- package/{src/ol → ol}/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +187 -0
- package/{src/ol → ol}/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +139 -0
- package/ol/layers/RoutingLayer.js +61 -0
- package/{src/ol → ol}/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +185 -0
- package/ol/layers/TralisLayer.test.js +79 -0
- package/ol/layers/VectorLayer.js +22 -0
- package/{src/ol → ol}/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +38 -0
- package/ol/layers/WMSLayer.test.js +76 -0
- package/ol/layers/index.js +8 -0
- package/{src/ol → ol}/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +43 -0
- package/ol/styles/index.js +2 -0
- package/package.json +34 -74
- package/.babelrc +0 -6
- package/.esdoc.json +0 -17
- package/.eslintignore +0 -1
- package/.github/workflows/conventional-pr-title.yml +0 -21
- package/.github/workflows/cypress.yml +0 -29
- package/.github/workflows/nodejs.yml +0 -28
- package/.husky/commit-msg +0 -4
- package/.husky/post-checkout +0 -4
- package/.husky/post-merge +0 -4
- package/.husky/post-rebase +0 -4
- package/.husky/pre-commit +0 -4
- package/.neutrinorc.js +0 -176
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -10
- package/LICENSE +0 -21
- package/__mocks__/mapbox-gl.js +0 -81
- package/__mocks__/maplibre-gl.js +0 -81
- package/commitlint.config.js +0 -1
- package/cypress/fixtures/example.json +0 -5
- package/cypress/integration/examples/api.spec.js +0 -7
- package/cypress/integration/examples/examples.spec.js +0 -7
- package/cypress/integration/examples/navigation.spec.js +0 -29
- package/cypress/plugins/index.js +0 -21
- package/cypress/support/commands.js +0 -25
- package/cypress/support/index.js +0 -20
- package/cypress.json +0 -4
- package/data/fetchRoute.json +0 -292
- package/data/fetchTrajectories.json +0 -18
- package/data/fetchTrajectoryById.json +0 -3
- package/data/fetchTrajectoryStations.json +0 -18
- package/data/stopsSearch.json +0 -15
- package/documentation.yml +0 -4
- package/esdoc/README.md +0 -27
- package/esdoc/plugins/MyPlugin.js +0 -69
- package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
- package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
- package/esdoc/plugins/externals-plugin/externals.js +0 -96
- package/global-setup.js +0 -3
- package/indexweb.html +0 -49
- package/jest.config.js +0 -5
- package/pull_request_template.md +0 -17
- package/renovate.json +0 -4
- package/scripts/read-pkg-json.js +0 -22
- package/src/api/index.js +0 -3
- package/src/api/routing/RoutingAPI.js +0 -44
- package/src/api/routing/RoutingAPI.test.js +0 -41
- package/src/api/stops/StopsAPI.js +0 -41
- package/src/api/stops/StopsAPI.test.js +0 -34
- package/src/api/tralis/TralisAPI.js +0 -731
- package/src/api/tralis/TralisAPI.test.js +0 -75
- package/src/api/tralis/WebSocketConnector.js +0 -338
- package/src/api/tralis/typedefs.js +0 -81
- package/src/assets/Lato-Black.ttf +0 -0
- package/src/assets/Lato-BlackItalic.ttf +0 -0
- package/src/assets/Lato-Bold.ttf +0 -0
- package/src/assets/Lato-BoldItalic.ttf +0 -0
- package/src/assets/Lato-Italic.ttf +0 -0
- package/src/assets/Lato-Light.ttf +0 -0
- package/src/assets/Lato-LightItalic.ttf +0 -0
- package/src/assets/Lato-Regular.ttf +0 -0
- package/src/assets/Lato-Thin.ttf +0 -0
- package/src/assets/Lato-ThinItalic.ttf +0 -0
- package/src/assets/OFL.txt +0 -93
- package/src/common/Tracker.js +0 -197
- package/src/common/api/api.js +0 -64
- package/src/common/api/api.test.js +0 -68
- package/src/common/controls/Control.js +0 -146
- package/src/common/index.js +0 -5
- package/src/common/layers/Layer.js +0 -404
- package/src/common/mixins/CopyrightMixin.js +0 -48
- package/src/common/mixins/SearchMixin.js +0 -176
- package/src/common/mixins/TralisLayerMixin.js +0 -930
- package/src/common/styles/index.js +0 -4
- package/src/common/styles/trackerDelayStyle.js +0 -17
- package/src/common/trackerConfig.test.js +0 -25
- package/src/common/typedefs.js +0 -23
- package/src/common/utils/createTrackerFilters.js +0 -87
- package/src/common/utils/createTrackerFilters.test.js +0 -95
- package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/src/common/utils/index.js +0 -5
- package/src/common/utils/removeDuplicate.js +0 -22
- package/src/common/utils/removeDuplicate.test.js +0 -22
- package/src/common/utils/timeUtils.js +0 -44
- package/src/common/utils/timeUtils.test.js +0 -16
- package/src/doc/App.js +0 -116
- package/src/doc/App.scss +0 -51
- package/src/doc/_redirects +0 -2
- package/src/doc/components/CodeSandboxButton.js +0 -103
- package/src/doc/components/Documentation.js +0 -40
- package/src/doc/components/Esdoc/Anchor.js +0 -57
- package/src/doc/components/Esdoc/ClassDoc.js +0 -272
- package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
- package/src/doc/components/Esdoc/DetailDocs.js +0 -281
- package/src/doc/components/Esdoc/DetailHTML.js +0 -33
- package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
- package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
- package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
- package/src/doc/components/Esdoc/Esdoc.js +0 -63
- package/src/doc/components/Esdoc/EsdocContent.js +0 -51
- package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
- package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
- package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
- package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
- package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
- package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
- package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
- package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
- package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
- package/src/doc/components/Esdoc/NavDoc.js +0 -112
- package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
- package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
- package/src/doc/components/Esdoc/Properties.js +0 -89
- package/src/doc/components/Esdoc/README.md +0 -45
- package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
- package/src/doc/components/Esdoc/SingleDoc.js +0 -31
- package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
- package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
- package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
- package/src/doc/components/Esdoc/css/identifiers.css +0 -38
- package/src/doc/components/Esdoc/css/search.css +0 -76
- package/src/doc/components/Esdoc/css/style.css +0 -603
- package/src/doc/components/Esdoc/index.js +0 -7
- package/src/doc/components/Example.js +0 -153
- package/src/doc/components/Examples.js +0 -183
- package/src/doc/components/Home.js +0 -106
- package/src/doc/components/TrackerExample.js +0 -38
- package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
- package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
- package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
- package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
- package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
- package/src/doc/examples/mb-copyright.html +0 -26
- package/src/doc/examples/mb-copyright.js +0 -37
- package/src/doc/examples/mb-tracker.html +0 -1
- package/src/doc/examples/mb-tracker.js +0 -39
- package/src/doc/examples/mb-tracker.md +0 -1
- package/src/doc/examples/mb-tralis.html +0 -1
- package/src/doc/examples/mb-tralis.js +0 -34
- package/src/doc/examples/ol-copyright.html +0 -26
- package/src/doc/examples/ol-copyright.js +0 -43
- package/src/doc/examples/ol-mapbox-layer.html +0 -1
- package/src/doc/examples/ol-mapbox-layer.js +0 -28
- package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
- package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
- package/src/doc/examples/ol-query.html +0 -32
- package/src/doc/examples/ol-query.js +0 -83
- package/src/doc/examples/ol-routing.html +0 -26
- package/src/doc/examples/ol-routing.js +0 -59
- package/src/doc/examples/ol-routing.md +0 -1
- package/src/doc/examples/ol-stop-finder.html +0 -15
- package/src/doc/examples/ol-stop-finder.js +0 -31
- package/src/doc/examples/ol-stop-finder.md +0 -1
- package/src/doc/examples/ol-tracker.html +0 -1
- package/src/doc/examples/ol-tracker.js +0 -44
- package/src/doc/examples/ol-tracker.md +0 -1
- package/src/doc/examples/ol-tralis.html +0 -5
- package/src/doc/examples/ol-tralis.js +0 -57
- package/src/doc/examples/tralis-live-map.html +0 -1
- package/src/doc/examples/tralis-live-map.js +0 -51
- package/src/doc/examples/tralis-live-map.md +0 -3
- package/src/doc/examples.js +0 -107
- package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
- package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
- package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
- package/src/doc/img/examples/mapbox.jpg +0 -0
- package/src/doc/img/examples/mapbox_style.jpg +0 -0
- package/src/doc/img/examples/ol-copyright.png +0 -0
- package/src/doc/img/examples/query_objects.jpg +0 -0
- package/src/doc/img/examples/routing.jpg +0 -0
- package/src/doc/img/examples/simple_map.jpg +0 -0
- package/src/doc/img/examples/stops.jpg +0 -0
- package/src/doc/img/favico.ico +0 -0
- package/src/doc/index.js +0 -21
- package/src/iife.js +0 -7
- package/src/index.js +0 -10
- package/src/mapbox/controls/CopyrightControl.js +0 -58
- package/src/mapbox/controls/index.js +0 -2
- package/src/mapbox/index.js +0 -4
- package/src/mapbox/layers/Layer.js +0 -118
- package/src/mapbox/layers/Layer.test.js +0 -202
- package/src/mapbox/layers/TralisLayer.js +0 -329
- package/src/mapbox/layers/index.js +0 -2
- package/src/ol/README.md +0 -0
- package/src/ol/controls/CopyrightControl.js +0 -80
- package/src/ol/controls/CopyrightControl.test.js +0 -211
- package/src/ol/controls/RoutingControl.js +0 -752
- package/src/ol/controls/RoutingControl.test.js +0 -216
- package/src/ol/controls/StopFinderControl.js +0 -38
- package/src/ol/controls/StopFinderControl.test.js +0 -59
- package/src/ol/controls/index.js +0 -3
- package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/src/ol/index.js +0 -5
- package/src/ol/layers/Layer.js +0 -193
- package/src/ol/layers/Layer.test.js +0 -197
- package/src/ol/layers/MapboxLayer.js +0 -378
- package/src/ol/layers/MapboxStyleLayer.js +0 -417
- package/src/ol/layers/MaplibreLayer.js +0 -280
- package/src/ol/layers/RoutingLayer.js +0 -91
- package/src/ol/layers/TralisLayer.js +0 -359
- package/src/ol/layers/TralisLayer.test.js +0 -97
- package/src/ol/layers/VectorLayer.js +0 -43
- package/src/ol/layers/WMSLayer.js +0 -80
- package/src/ol/layers/WMSLayer.test.js +0 -84
- package/src/ol/layers/index.js +0 -8
- package/src/ol/styles/fullTrajectoryStyle.js +0 -51
- package/src/ol/styles/index.js +0 -2
- package/src/setupTests.js +0 -15
- package/webpack.config.js +0 -6
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import WS from
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
describe(
|
|
5
|
-
describe('#constructor', () => {
|
|
1
|
+
import WS from "jest-websocket-mock";
|
|
2
|
+
import WebSocketAPI from "./WebSocketAPI";
|
|
3
|
+
describe("WebSocketAPI", () => {
|
|
4
|
+
describe("#constructor", () => {
|
|
6
5
|
let server;
|
|
7
6
|
let server2;
|
|
8
|
-
|
|
9
7
|
beforeEach(() => {
|
|
10
8
|
server = new WS(`ws://foo:1234`);
|
|
11
9
|
server2 = new WS(`ws://foo:12345`);
|
|
12
10
|
});
|
|
13
|
-
|
|
14
11
|
afterEach(() => {
|
|
15
12
|
server.close();
|
|
16
13
|
server2.close();
|
|
17
14
|
WS.clean();
|
|
18
15
|
});
|
|
19
|
-
|
|
20
|
-
describe('#constructor', () => {
|
|
16
|
+
describe("#constructor", () => {
|
|
21
17
|
test("doesn't connect.", async () => {
|
|
22
|
-
const client = new
|
|
18
|
+
const client = new WebSocketAPI();
|
|
23
19
|
expect(client.websocket).toBe();
|
|
24
20
|
expect(client.closed).toBe(false);
|
|
25
21
|
expect(client.closing).toBe(false);
|
|
@@ -27,44 +23,42 @@ describe('WebSocketConnector', () => {
|
|
|
27
23
|
expect(client.open).toBe(false);
|
|
28
24
|
});
|
|
29
25
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// eslint-disable-next-line no-unused-vars
|
|
34
|
-
const client = new Connector();
|
|
26
|
+
describe("#close", () => {
|
|
27
|
+
test("should close the websocket and clear some property", async () => {
|
|
28
|
+
const client = new WebSocketAPI();
|
|
35
29
|
const subsc2 = {
|
|
36
|
-
params:
|
|
37
|
-
cb: () => {
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
params: "foo",
|
|
31
|
+
cb: () => {
|
|
32
|
+
},
|
|
33
|
+
errorCb: () => {
|
|
34
|
+
},
|
|
35
|
+
quiet: false
|
|
40
36
|
};
|
|
41
37
|
client.subscriptions = [subsc2];
|
|
42
|
-
client.messagesOnOpen = [
|
|
38
|
+
client.messagesOnOpen = ["GET foo"];
|
|
43
39
|
client.connect(`ws://foo:1234`);
|
|
44
40
|
client.websocket.addEventListener = jest.fn();
|
|
45
41
|
client.websocket.removeEventListener = jest.fn();
|
|
46
42
|
client.websocket.close = jest.fn();
|
|
47
43
|
await server.connected;
|
|
48
44
|
expect(client.websocket).toBeDefined();
|
|
49
|
-
expect(client.messagesOnOpen).toEqual([
|
|
45
|
+
expect(client.messagesOnOpen).toEqual(["GET foo"]);
|
|
50
46
|
client.close();
|
|
51
47
|
expect(client.messagesOnOpen).toEqual([]);
|
|
52
48
|
expect(client.websocket).toBeNull();
|
|
53
49
|
});
|
|
54
50
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const client = new Connector();
|
|
51
|
+
describe("#connect", () => {
|
|
52
|
+
test("create a new WebSocket.", async () => {
|
|
53
|
+
const client = new WebSocketAPI();
|
|
59
54
|
client.connect(`ws://foo:1234`);
|
|
60
55
|
await server.connected;
|
|
61
|
-
client.send(
|
|
62
|
-
await expect(server).toReceiveMessage(
|
|
63
|
-
expect(server).toHaveReceivedMessages([
|
|
56
|
+
client.send("hello");
|
|
57
|
+
await expect(server).toReceiveMessage("hello");
|
|
58
|
+
expect(server).toHaveReceivedMessages(["hello"]);
|
|
64
59
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const client = new Connector();
|
|
60
|
+
test("close previous connection.", async () => {
|
|
61
|
+
const client = new WebSocketAPI();
|
|
68
62
|
client.connect(`ws://foo:1234`);
|
|
69
63
|
await server.connected;
|
|
70
64
|
expect(client.websocket).toBeDefined();
|
|
@@ -74,96 +68,89 @@ describe('WebSocketConnector', () => {
|
|
|
74
68
|
expect(old.readyState).toBe(WebSocket.CLOSING);
|
|
75
69
|
expect(client.websocket.readyState).toBe(WebSocket.CONNECTING);
|
|
76
70
|
});
|
|
77
|
-
|
|
78
|
-
test('call onOpen function', async () => {
|
|
71
|
+
test("call onOpen function", async () => {
|
|
79
72
|
const onOpen = jest.fn();
|
|
80
|
-
const client = new
|
|
73
|
+
const client = new WebSocketAPI();
|
|
81
74
|
client.subscribe = jest.fn();
|
|
82
75
|
client.connect(`ws://foo:1234`, onOpen);
|
|
83
76
|
await server.connected;
|
|
84
77
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
85
78
|
expect(onOpen).toHaveBeenCalledTimes(1);
|
|
86
79
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const client = new Connector();
|
|
80
|
+
test("subscribe previous subscriptions on open (quiet or not)", async () => {
|
|
81
|
+
const client = new WebSocketAPI();
|
|
90
82
|
client.subscribe = jest.fn();
|
|
91
83
|
client.send = jest.fn();
|
|
92
84
|
const subsc = {
|
|
93
|
-
params:
|
|
94
|
-
cb: () => {
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
params: "foo",
|
|
86
|
+
cb: () => {
|
|
87
|
+
},
|
|
88
|
+
errorCb: () => {
|
|
89
|
+
},
|
|
90
|
+
quiet: true
|
|
97
91
|
};
|
|
98
92
|
const subsc2 = {
|
|
99
|
-
params:
|
|
100
|
-
cb: () => {
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
params: "foo",
|
|
94
|
+
cb: () => {
|
|
95
|
+
},
|
|
96
|
+
errorCb: () => {
|
|
97
|
+
},
|
|
98
|
+
quiet: false
|
|
103
99
|
};
|
|
104
100
|
client.subscriptions = [subsc, subsc2];
|
|
105
|
-
|
|
106
101
|
client.connect(`ws://foo:1234`);
|
|
107
102
|
await server.connected;
|
|
108
103
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
109
104
|
expect(client.subscribe).toHaveBeenCalledTimes(2);
|
|
110
105
|
client.subscribe.mockReset();
|
|
111
|
-
|
|
112
106
|
client.connect(`ws://foo:12345`);
|
|
113
107
|
await server2.connected;
|
|
114
108
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
115
109
|
expect(client.subscribe).toHaveBeenCalledTimes(2);
|
|
116
|
-
expect(client.subscribe).toHaveBeenCalledWith(
|
|
117
|
-
subsc.params,
|
|
118
|
-
subsc.cb,
|
|
119
|
-
subsc.errorCb,
|
|
120
|
-
subsc.quiet,
|
|
121
|
-
);
|
|
110
|
+
expect(client.subscribe).toHaveBeenCalledWith(subsc.params, subsc.cb, subsc.errorCb, subsc.quiet);
|
|
122
111
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const client = new Connector();
|
|
112
|
+
test("send GET and SUB for not quiet previous subscriptions", async () => {
|
|
113
|
+
const client = new WebSocketAPI();
|
|
126
114
|
client.send = jest.fn();
|
|
127
115
|
const subsc = {
|
|
128
|
-
params: { channel:
|
|
129
|
-
cb: () => {
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
params: { channel: "foo" },
|
|
117
|
+
cb: () => {
|
|
118
|
+
},
|
|
119
|
+
errorCb: () => {
|
|
120
|
+
},
|
|
121
|
+
quiet: false
|
|
132
122
|
};
|
|
133
123
|
client.subscriptions = [subsc];
|
|
134
|
-
|
|
135
124
|
client.connect(`ws://foo:1234`);
|
|
136
125
|
client.websocket.addEventListener = jest.fn();
|
|
137
126
|
client.websocket.removeEventListener = jest.fn();
|
|
138
127
|
await server.connected;
|
|
139
128
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
140
129
|
expect(client.send).toHaveBeenCalledTimes(2);
|
|
141
|
-
expect(client.send.mock.calls[0]).toEqual([
|
|
142
|
-
expect(client.send.mock.calls[1]).toEqual([
|
|
130
|
+
expect(client.send.mock.calls[0]).toEqual(["GET foo"]);
|
|
131
|
+
expect(client.send.mock.calls[1]).toEqual(["SUB foo"]);
|
|
143
132
|
client.send.mockReset();
|
|
144
|
-
|
|
145
133
|
client.connect(`ws://foo:12345`);
|
|
146
134
|
client.websocket.addEventListener = jest.fn();
|
|
147
135
|
client.websocket.removeEventListener = jest.fn();
|
|
148
136
|
await server2.connected;
|
|
149
137
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
150
|
-
// not quiet subscriptions will send GET and SUB requests.
|
|
151
138
|
expect(client.send).toHaveBeenCalledTimes(2);
|
|
152
|
-
expect(client.send.mock.calls[0]).toEqual([
|
|
153
|
-
expect(client.send.mock.calls[1]).toEqual([
|
|
139
|
+
expect(client.send.mock.calls[0]).toEqual(["GET foo"]);
|
|
140
|
+
expect(client.send.mock.calls[1]).toEqual(["SUB foo"]);
|
|
154
141
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const client = new Connector();
|
|
142
|
+
test("doesn send GET and SUB for quiet previous subscriptions", async () => {
|
|
143
|
+
const client = new WebSocketAPI();
|
|
158
144
|
client.send = jest.fn();
|
|
159
145
|
const subsc = {
|
|
160
|
-
params: { channel:
|
|
161
|
-
cb: () => {
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
params: { channel: "foo" },
|
|
147
|
+
cb: () => {
|
|
148
|
+
},
|
|
149
|
+
errorCb: () => {
|
|
150
|
+
},
|
|
151
|
+
quiet: true
|
|
164
152
|
};
|
|
165
153
|
client.subscriptions = [subsc];
|
|
166
|
-
|
|
167
154
|
client.connect(`ws://foo:1234`);
|
|
168
155
|
client.websocket.addEventListener = jest.fn();
|
|
169
156
|
client.websocket.removeEventListener = jest.fn();
|
|
@@ -171,24 +158,20 @@ describe('WebSocketConnector', () => {
|
|
|
171
158
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
172
159
|
expect(client.send).toHaveBeenCalledTimes(0);
|
|
173
160
|
client.send.mockReset();
|
|
174
|
-
|
|
175
161
|
client.connect(`ws://foo:12345`);
|
|
176
162
|
client.websocket.addEventListener = jest.fn();
|
|
177
163
|
client.websocket.removeEventListener = jest.fn();
|
|
178
164
|
await server2.connected;
|
|
179
165
|
expect(client.websocket.readyState).toBe(WebSocket.OPEN);
|
|
180
|
-
// not quiet subscriptions will send GET and SUB requests.
|
|
181
166
|
expect(client.send).toHaveBeenCalledTimes(0);
|
|
182
167
|
});
|
|
183
168
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// eslint-disable-next-line no-unused-vars
|
|
188
|
-
const client = new Connector();
|
|
169
|
+
describe("#subscribe", () => {
|
|
170
|
+
test("adds subscription to subscriptions array", async () => {
|
|
171
|
+
const client = new WebSocketAPI();
|
|
189
172
|
client.connect(`ws://foo:1234`);
|
|
190
173
|
await server.connected;
|
|
191
|
-
const params = { channel:
|
|
174
|
+
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
192
175
|
const cb = jest.fn();
|
|
193
176
|
const errorCb = jest.fn();
|
|
194
177
|
client.subscribe(params, cb, errorCb);
|
|
@@ -197,54 +180,44 @@ describe('WebSocketConnector', () => {
|
|
|
197
180
|
expect(client.subscriptions[0].cb).toBe(cb);
|
|
198
181
|
expect(client.subscriptions[0].errorCb).toBe(errorCb);
|
|
199
182
|
expect(client.subscriptions[0].quiet).toBe(false);
|
|
200
|
-
|
|
201
|
-
const obj = { source: 'bar baz', client_reference: 'id' };
|
|
183
|
+
const obj = { source: "bar baz", client_reference: "id" };
|
|
202
184
|
server.send(JSON.stringify(obj));
|
|
203
|
-
|
|
204
185
|
expect(cb).toHaveBeenCalledTimes(1);
|
|
205
186
|
expect(cb).toHaveBeenCalledWith(obj);
|
|
206
187
|
});
|
|
207
|
-
|
|
208
188
|
test("doesn't duplicate subscriptions", async () => {
|
|
209
|
-
|
|
210
|
-
const client = new Connector();
|
|
189
|
+
const client = new WebSocketAPI();
|
|
211
190
|
client.connect(`ws://foo:1234`);
|
|
212
191
|
await server.connected;
|
|
213
|
-
const params = { channel:
|
|
192
|
+
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
214
193
|
const cb = jest.fn();
|
|
215
194
|
const errorCb = jest.fn();
|
|
216
195
|
client.subscribe(params, cb, errorCb, true);
|
|
217
196
|
client.subscribe(params, cb, errorCb, true);
|
|
218
197
|
expect(client.subscriptions.length).toBe(1);
|
|
219
|
-
|
|
220
|
-
const obj = { source: 'bar baz', client_reference: 'id' };
|
|
198
|
+
const obj = { source: "bar baz", client_reference: "id" };
|
|
221
199
|
server.send(JSON.stringify(obj));
|
|
222
|
-
|
|
223
200
|
expect(cb).toHaveBeenCalledTimes(1);
|
|
224
201
|
expect(cb).toHaveBeenCalledWith(obj);
|
|
225
202
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// eslint-disable-next-line no-unused-vars
|
|
229
|
-
const client = new Connector();
|
|
203
|
+
test("send GET and SUB requests.", async () => {
|
|
204
|
+
const client = new WebSocketAPI();
|
|
230
205
|
client.connect(`ws://foo:1234`);
|
|
231
206
|
client.send = jest.fn();
|
|
232
|
-
const params = { channel:
|
|
207
|
+
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
233
208
|
const cb = jest.fn();
|
|
234
209
|
const errorCb = jest.fn();
|
|
235
210
|
client.subscribe(params, cb, errorCb);
|
|
236
211
|
expect(client.send).toHaveBeenCalledTimes(2);
|
|
237
|
-
expect(client.send).toHaveBeenCalledWith(
|
|
238
|
-
expect(client.send).toHaveBeenCalledWith(
|
|
212
|
+
expect(client.send).toHaveBeenCalledWith("GET bar baz id");
|
|
213
|
+
expect(client.send).toHaveBeenCalledWith("SUB bar baz id");
|
|
239
214
|
client.send.mockRestore();
|
|
240
215
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// eslint-disable-next-line no-unused-vars
|
|
244
|
-
const client = new Connector();
|
|
216
|
+
test("should register callback without sending GET and SUB requests (quiet=true).", async () => {
|
|
217
|
+
const client = new WebSocketAPI();
|
|
245
218
|
client.connect(`ws://foo:1234`);
|
|
246
219
|
await server.connected;
|
|
247
|
-
const params = { channel:
|
|
220
|
+
const params = { channel: "bar", args: ["baz"], id: "id" };
|
|
248
221
|
const cb = jest.fn();
|
|
249
222
|
const errorCb = jest.fn();
|
|
250
223
|
client.send = jest.fn();
|
|
@@ -258,14 +231,12 @@ describe('WebSocketConnector', () => {
|
|
|
258
231
|
client.send.mockRestore();
|
|
259
232
|
});
|
|
260
233
|
});
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
// eslint-disable-next-line no-unused-vars
|
|
265
|
-
const client = new Connector();
|
|
234
|
+
describe("#unsubscribe", () => {
|
|
235
|
+
test("should only unsubscribe the subscription using the good cb", async () => {
|
|
236
|
+
const client = new WebSocketAPI();
|
|
266
237
|
client.connect(`ws://foo:1234`);
|
|
267
238
|
await server.connected;
|
|
268
|
-
const params = { channel:
|
|
239
|
+
const params = { channel: "foo", id: "id" };
|
|
269
240
|
const cb = jest.fn();
|
|
270
241
|
const cb2 = jest.fn();
|
|
271
242
|
client.subscribe(params, cb);
|
|
@@ -275,27 +246,22 @@ describe('WebSocketConnector', () => {
|
|
|
275
246
|
expect(client.subscriptions[0].cb).toBe(cb);
|
|
276
247
|
expect(client.subscriptions[1].params).toBe(params);
|
|
277
248
|
expect(client.subscriptions[1].cb).toBe(cb2);
|
|
278
|
-
|
|
279
|
-
client.unsubscribe('foo', cb);
|
|
249
|
+
client.unsubscribe("foo", cb);
|
|
280
250
|
expect(client.subscriptions.length).toBe(1);
|
|
281
|
-
|
|
282
251
|
expect(cb).toHaveBeenCalledTimes(0);
|
|
283
252
|
expect(cb2).toHaveBeenCalledTimes(0);
|
|
284
|
-
const obj = { source:
|
|
253
|
+
const obj = { source: "foo", client_reference: "id" };
|
|
285
254
|
server.send(JSON.stringify(obj));
|
|
286
|
-
|
|
287
255
|
expect(cb2).toHaveBeenCalledTimes(1);
|
|
288
256
|
expect(cb).toHaveBeenCalledTimes(0);
|
|
289
257
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// eslint-disable-next-line no-unused-vars
|
|
293
|
-
const client = new Connector();
|
|
258
|
+
test("should unsubscribe all subscriptions related to a channel", () => {
|
|
259
|
+
const client = new WebSocketAPI();
|
|
294
260
|
client.connect(`ws://foo:1234`);
|
|
295
261
|
client.websocket.removeEventListener = jest.fn();
|
|
296
262
|
client.websocket.addEventListener = jest.fn();
|
|
297
|
-
const params = { channel:
|
|
298
|
-
const params2 = { channel:
|
|
263
|
+
const params = { channel: "foo" };
|
|
264
|
+
const params2 = { channel: "bar" };
|
|
299
265
|
const cb = jest.fn();
|
|
300
266
|
const cb2 = jest.fn();
|
|
301
267
|
client.subscribe(params, cb);
|
|
@@ -305,49 +271,38 @@ describe('WebSocketConnector', () => {
|
|
|
305
271
|
client.subscribe(params2, cb2);
|
|
306
272
|
expect(client.subscriptions.length).toBe(3);
|
|
307
273
|
expect(client.websocket.removeEventListener).toBeCalledTimes(2);
|
|
308
|
-
expect(
|
|
309
|
-
|
|
310
|
-
(c) => c[0] === 'message',
|
|
311
|
-
).length,
|
|
312
|
-
).toBe(5);
|
|
313
|
-
|
|
314
|
-
client.unsubscribe('foo');
|
|
274
|
+
expect(client.websocket.addEventListener.mock.calls.filter((c) => c[0] === "message").length).toBe(5);
|
|
275
|
+
client.unsubscribe("foo");
|
|
315
276
|
expect(client.subscriptions.length).toBe(1);
|
|
316
277
|
expect(client.subscriptions[0].params).toBe(params2);
|
|
317
278
|
expect(client.subscriptions[0].cb).toBe(cb2);
|
|
318
279
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
// eslint-disable-next-line no-unused-vars
|
|
322
|
-
const client = new Connector();
|
|
280
|
+
test("send DEL when there is no more unquiet subscriptions on the channel", async () => {
|
|
281
|
+
const client = new WebSocketAPI();
|
|
323
282
|
client.connect(`ws://foo:1234`);
|
|
324
283
|
await server.connected;
|
|
325
284
|
client.send = jest.fn();
|
|
326
285
|
client.websocket.removeEventListener = jest.fn();
|
|
327
286
|
client.websocket.addEventListener = jest.fn();
|
|
328
|
-
const params = { channel:
|
|
287
|
+
const params = { channel: "foo" };
|
|
329
288
|
const cb = jest.fn();
|
|
330
289
|
client.subscribe(params, cb);
|
|
331
|
-
expect(client.send).toHaveBeenCalledWith(
|
|
332
|
-
expect(client.send).toHaveBeenCalledWith(
|
|
333
|
-
|
|
334
|
-
client.
|
|
335
|
-
expect(client.send).toHaveBeenCalledWith('DEL foo');
|
|
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");
|
|
336
294
|
});
|
|
337
|
-
|
|
338
295
|
test("doesn't send DEL when we unsubscribe a quiet channel", () => {
|
|
339
|
-
|
|
340
|
-
const client = new Connector();
|
|
296
|
+
const client = new WebSocketAPI();
|
|
341
297
|
client.connect(`ws://foo:1234`);
|
|
342
298
|
client.send = jest.fn();
|
|
343
299
|
client.websocket.removeEventListener = jest.fn();
|
|
344
300
|
client.websocket.addEventListener = jest.fn();
|
|
345
|
-
const params = { channel:
|
|
301
|
+
const params = { channel: "foo" };
|
|
346
302
|
const cb = jest.fn();
|
|
347
303
|
client.subscribe(params, cb, null, true);
|
|
348
304
|
expect(cb).toHaveBeenCalledTimes(0);
|
|
349
|
-
|
|
350
|
-
client.unsubscribe('foo');
|
|
305
|
+
client.unsubscribe("foo");
|
|
351
306
|
expect(cb).toHaveBeenCalledTimes(0);
|
|
352
307
|
client.send.mockRestore();
|
|
353
308
|
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import BaseObject from "ol/Object";
|
|
2
|
+
class Control extends BaseObject {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
super(options);
|
|
5
|
+
this.defineProperties(options);
|
|
6
|
+
const { active } = {
|
|
7
|
+
active: options.active !== false,
|
|
8
|
+
...options
|
|
9
|
+
};
|
|
10
|
+
this.active = active;
|
|
11
|
+
}
|
|
12
|
+
defineProperties(options) {
|
|
13
|
+
const { target, element, render } = {
|
|
14
|
+
...options
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperties(this, {
|
|
17
|
+
active: {
|
|
18
|
+
get: () => this.get("active"),
|
|
19
|
+
set: (newActive) => {
|
|
20
|
+
this.set("active", newActive);
|
|
21
|
+
if (newActive) {
|
|
22
|
+
this.activate();
|
|
23
|
+
} else {
|
|
24
|
+
this.deactivate();
|
|
25
|
+
}
|
|
26
|
+
this.render();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
map: {
|
|
30
|
+
get: () => this.get("map"),
|
|
31
|
+
set: (map) => {
|
|
32
|
+
if (this.map && this.element && this.element.parentNode) {
|
|
33
|
+
this.element.parentNode.removeChild(this.element);
|
|
34
|
+
}
|
|
35
|
+
this.deactivate();
|
|
36
|
+
this.set("map", map);
|
|
37
|
+
if (this.map) {
|
|
38
|
+
const targett = this.target || this.map.getTargetElement && this.map.getTargetElement() || this.map.getContainer && this.map.getContainer();
|
|
39
|
+
if (!this.element) {
|
|
40
|
+
this.createDefaultElement();
|
|
41
|
+
}
|
|
42
|
+
if (this.element) {
|
|
43
|
+
targett.appendChild(this.element);
|
|
44
|
+
}
|
|
45
|
+
if (this.active) {
|
|
46
|
+
this.activate();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
this.render();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
target: {
|
|
53
|
+
value: target
|
|
54
|
+
},
|
|
55
|
+
element: {
|
|
56
|
+
value: element,
|
|
57
|
+
writable: true
|
|
58
|
+
},
|
|
59
|
+
render: {
|
|
60
|
+
value: render || this.render,
|
|
61
|
+
writable: true
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
attachToMap(map) {
|
|
66
|
+
this.map = map;
|
|
67
|
+
}
|
|
68
|
+
detachFromMap() {
|
|
69
|
+
this.map = null;
|
|
70
|
+
}
|
|
71
|
+
activate() {
|
|
72
|
+
this.deactivate();
|
|
73
|
+
}
|
|
74
|
+
deactivate() {
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
}
|
|
78
|
+
createDefaultElement() {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export default Control;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import Control from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
test('should be activated by default', () => {
|
|
1
|
+
import Control from "./Control";
|
|
2
|
+
describe("Control", () => {
|
|
3
|
+
test("should be activated by default", () => {
|
|
5
4
|
const control = new Control();
|
|
6
5
|
expect(control.active).toBe(true);
|
|
7
6
|
});
|
|
8
|
-
|
|
9
|
-
test('should not be activated if set to false in the options', () => {
|
|
7
|
+
test("should not be activated if set to false in the options", () => {
|
|
10
8
|
const control = new Control({ active: false });
|
|
11
9
|
expect(control.active).toBe(false);
|
|
12
10
|
});
|
|
13
|
-
|
|
14
|
-
test('should call activate/deactivate when active is set to true/false', () => {
|
|
11
|
+
test("should call activate/deactivate when active is set to true/false", () => {
|
|
15
12
|
const control = new Control();
|
|
16
|
-
const spy1 = jest.spyOn(control,
|
|
17
|
-
const spy2 = jest.spyOn(control,
|
|
18
|
-
const spy3 = jest.spyOn(control,
|
|
13
|
+
const spy1 = jest.spyOn(control, "activate");
|
|
14
|
+
const spy2 = jest.spyOn(control, "deactivate");
|
|
15
|
+
const spy3 = jest.spyOn(control, "render");
|
|
19
16
|
control.active = false;
|
|
20
17
|
expect(spy1).toBeCalledTimes(0);
|
|
21
18
|
expect(spy2).toBeCalledTimes(1);
|
|
@@ -25,74 +22,66 @@ describe('Control', () => {
|
|
|
25
22
|
expect(spy2).toBeCalledTimes(2);
|
|
26
23
|
expect(spy3).toBeCalledTimes(2);
|
|
27
24
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const target = document.createElement('div');
|
|
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");
|
|
32
28
|
const control = new Control({
|
|
33
|
-
element
|
|
29
|
+
element
|
|
34
30
|
});
|
|
35
|
-
const spy1 = jest.spyOn(control,
|
|
36
|
-
const spy2 = jest.spyOn(control,
|
|
37
|
-
const spy3 = jest.spyOn(control,
|
|
31
|
+
const spy1 = jest.spyOn(control, "activate");
|
|
32
|
+
const spy2 = jest.spyOn(control, "deactivate");
|
|
33
|
+
const spy3 = jest.spyOn(control, "render");
|
|
38
34
|
control.map = {
|
|
39
35
|
getContainer() {
|
|
40
36
|
return target;
|
|
41
|
-
}
|
|
37
|
+
}
|
|
42
38
|
};
|
|
43
39
|
expect(target.childNodes[0]).toBe(element);
|
|
44
40
|
expect(spy1).toBeCalledTimes(1);
|
|
45
41
|
expect(spy2).toBeCalledTimes(2);
|
|
46
42
|
expect(spy3).toBeCalledTimes(1);
|
|
47
|
-
|
|
48
|
-
control.map = null;
|
|
43
|
+
control.detachFromMap();
|
|
49
44
|
expect(target.childNodes[0]).toBe();
|
|
50
45
|
expect(spy1).toBeCalledTimes(1);
|
|
51
46
|
expect(spy2).toBeCalledTimes(3);
|
|
52
47
|
expect(spy3).toBeCalledTimes(2);
|
|
53
48
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const target = document.createElement('div');
|
|
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");
|
|
58
52
|
const control = new Control({
|
|
59
53
|
target,
|
|
60
|
-
element
|
|
54
|
+
element
|
|
61
55
|
});
|
|
62
|
-
const spy1 = jest.spyOn(control,
|
|
63
|
-
const spy2 = jest.spyOn(control,
|
|
64
|
-
const spy3 = jest.spyOn(control,
|
|
56
|
+
const spy1 = jest.spyOn(control, "activate");
|
|
57
|
+
const spy2 = jest.spyOn(control, "deactivate");
|
|
58
|
+
const spy3 = jest.spyOn(control, "render");
|
|
65
59
|
control.map = {};
|
|
66
60
|
expect(target.childNodes[0]).toBe(element);
|
|
67
61
|
expect(spy1).toBeCalledTimes(1);
|
|
68
62
|
expect(spy2).toBeCalledTimes(2);
|
|
69
63
|
expect(spy3).toBeCalledTimes(1);
|
|
70
|
-
|
|
71
|
-
control.map = null;
|
|
64
|
+
control.detachFromMap();
|
|
72
65
|
expect(target.childNodes[0]).toBe();
|
|
73
66
|
expect(spy1).toBeCalledTimes(1);
|
|
74
67
|
expect(spy2).toBeCalledTimes(3);
|
|
75
68
|
expect(spy3).toBeCalledTimes(2);
|
|
76
69
|
});
|
|
77
|
-
|
|
78
|
-
test('set a custom render method', () => {
|
|
70
|
+
test("set a custom render method", () => {
|
|
79
71
|
const spy = jest.fn();
|
|
80
|
-
// eslint-disable-next-line no-unused-vars
|
|
81
72
|
const control = new Control({
|
|
82
|
-
render: spy
|
|
73
|
+
render: spy
|
|
83
74
|
});
|
|
84
75
|
expect(spy).toBeCalledTimes(1);
|
|
85
76
|
});
|
|
86
|
-
|
|
87
|
-
test('pass function params to custom render method', () => {
|
|
77
|
+
test("pass function params to custom render method", () => {
|
|
88
78
|
const spy = jest.fn();
|
|
89
|
-
// eslint-disable-next-line no-unused-vars
|
|
90
79
|
const control = new Control({
|
|
91
|
-
render: spy
|
|
80
|
+
render: spy
|
|
92
81
|
});
|
|
93
|
-
control.render(
|
|
82
|
+
control.render("foo", "bar");
|
|
94
83
|
expect(spy).toBeCalledTimes(2);
|
|
95
|
-
expect(spy.mock.calls[1][0]).toBe(
|
|
96
|
-
expect(spy.mock.calls[1][1]).toBe(
|
|
84
|
+
expect(spy.mock.calls[1][0]).toBe("foo");
|
|
85
|
+
expect(spy.mock.calls[1][1]).toBe("bar");
|
|
97
86
|
});
|
|
98
87
|
});
|
package/common/index.js
ADDED