@open-pioneer/map-test-utils 0.2.2 → 0.3.0
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/CHANGELOG.md +20 -0
- package/index.d.ts +26 -1
- package/index.js +15 -4
- package/index.js.map +1 -1
- package/package.json +14 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @open-pioneer/map-test-utils
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a11bf72: mock vector layer rendering during tests
|
|
8
|
+
- 9334e81: Update to OpenLayers 9
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 1a8ad89: Update package.json metadata
|
|
13
|
+
- Updated dependencies [1a8ad89]
|
|
14
|
+
- Updated dependencies [a11bf72]
|
|
15
|
+
- Updated dependencies [fc6bf82]
|
|
16
|
+
- Updated dependencies [a0d8882]
|
|
17
|
+
- Updated dependencies [6162979]
|
|
18
|
+
- Updated dependencies [9334e81]
|
|
19
|
+
- Updated dependencies [ac7fdd1]
|
|
20
|
+
- Updated dependencies [13ea342]
|
|
21
|
+
- @open-pioneer/map@0.4.0
|
|
22
|
+
|
|
3
23
|
## 0.2.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpServiceRequestInit } from "@open-pioneer/http";
|
|
2
|
+
import { ExtentConfig, Layer, MapModel, MapRegistry, OlMapOptions, SimpleLayerConfig } from "@open-pioneer/map";
|
|
2
3
|
import { MapRegistryImpl } from "@open-pioneer/map/services";
|
|
3
4
|
export interface SimpleMapOptions {
|
|
5
|
+
/** Center coordinates for the map. */
|
|
4
6
|
center?: {
|
|
5
7
|
x: number;
|
|
6
8
|
y: number;
|
|
7
9
|
};
|
|
10
|
+
/** Zoom level of the map. */
|
|
8
11
|
zoom?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Initial extent (don't mix with center / zoom).
|
|
14
|
+
*/
|
|
9
15
|
extent?: ExtentConfig;
|
|
16
|
+
/**
|
|
17
|
+
* The map's projection.
|
|
18
|
+
*/
|
|
10
19
|
projection?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Layers used by the map.
|
|
22
|
+
*/
|
|
11
23
|
layers?: (SimpleLayerConfig | Layer)[];
|
|
24
|
+
/**
|
|
25
|
+
* Overrides fetching of network resources (such as service capabilities).
|
|
26
|
+
*/
|
|
27
|
+
fetch?: (resource: URL, init: HttpServiceRequestInit | undefined) => Promise<Response>;
|
|
28
|
+
/**
|
|
29
|
+
* Passed to the open layers map constructor.
|
|
30
|
+
*/
|
|
12
31
|
advanced?: OlMapOptions;
|
|
32
|
+
/**
|
|
33
|
+
* Disables the initial view when set to true.
|
|
34
|
+
*/
|
|
13
35
|
noInitialView?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Disables the default projection when set to true.
|
|
38
|
+
*/
|
|
14
39
|
noProjection?: boolean;
|
|
15
40
|
}
|
|
16
41
|
/**
|
package/index.js
CHANGED
|
@@ -58,10 +58,14 @@ async function setupMap(options) {
|
|
|
58
58
|
advanced: options?.advanced
|
|
59
59
|
};
|
|
60
60
|
const httpService = {
|
|
61
|
-
async fetch() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
async fetch(resource, init) {
|
|
62
|
+
if (options?.fetch) {
|
|
63
|
+
const url = new URL(resource, "http://localhost:1234");
|
|
64
|
+
return options.fetch(url, init);
|
|
65
|
+
}
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Network requests are not implemented (override fetch via map test utils if your test requires network access)."
|
|
68
|
+
);
|
|
65
69
|
}
|
|
66
70
|
};
|
|
67
71
|
const registry = await createService(MapRegistryImpl, {
|
|
@@ -88,6 +92,13 @@ class MapConfigProviderImpl {
|
|
|
88
92
|
return Promise.resolve(this.mapConfig);
|
|
89
93
|
}
|
|
90
94
|
}
|
|
95
|
+
function mockVectorLayer() {
|
|
96
|
+
const div = document.createElement("div");
|
|
97
|
+
VectorLayer.prototype.render = () => {
|
|
98
|
+
return div;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
mockVectorLayer();
|
|
91
102
|
|
|
92
103
|
export { createServiceOptions, setupMap, waitForInitialExtent, waitForMapMount };
|
|
93
104
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n ExtentConfig,\n InitialViewConfig,\n MapConfig,\n MapConfigProvider,\n MapModel,\n MapRegistry,\n OlMapOptions,\n SimpleLayer,\n SimpleLayerConfig
|
|
1
|
+
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { HttpService, HttpServiceRequestInit } from \"@open-pioneer/http\";\nimport {\n ExtentConfig,\n InitialViewConfig,\n Layer,\n MapConfig,\n MapConfigProvider,\n MapModel,\n MapRegistry,\n OlMapOptions,\n SimpleLayer,\n SimpleLayerConfig\n} from \"@open-pioneer/map\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport VectorLayer from \"ol/layer/Vector\";\n\n// Importing internals: needed for test support\nimport { MapRegistryImpl } from \"@open-pioneer/map/services\";\n\nexport interface SimpleMapOptions {\n /** Center coordinates for the map. */\n center?: { x: number; y: number };\n\n /** Zoom level of the map. */\n zoom?: number;\n\n /**\n * Initial extent (don't mix with center / zoom).\n */\n extent?: ExtentConfig;\n\n /**\n * The map's projection.\n */\n projection?: string;\n\n /**\n * Layers used by the map.\n */\n layers?: (SimpleLayerConfig | Layer)[];\n\n /**\n * Overrides fetching of network resources (such as service capabilities).\n */\n fetch?: (resource: URL, init: HttpServiceRequestInit | undefined) => Promise<Response>;\n\n /**\n * Passed to the open layers map constructor.\n */\n advanced?: OlMapOptions;\n\n /**\n * Disables the initial view when set to true.\n */\n noInitialView?: boolean;\n\n /**\n * Disables the default projection when set to true.\n */\n noProjection?: boolean;\n}\n\n/**\n * Waits until the OpenLayers map has been mounted in the parent with the given id.\n */\nexport async function waitForMapMount(parentTestId = \"base\") {\n return await waitFor(async () => {\n const domElement = await screen.findByTestId(parentTestId);\n const container = domElement.querySelector(\".ol-viewport\");\n if (!container) {\n throw new Error(\"map not mounted\");\n }\n return domElement;\n });\n}\n\n/**\n * Waits until the model has an initial extent.\n */\nexport async function waitForInitialExtent(model: MapModel) {\n if (model.initialExtent) {\n return;\n }\n\n await new Promise<void>((resolve, reject) => {\n model?.once(\"changed:initialExtent\", () => {\n if (model?.initialExtent) {\n resolve();\n } else {\n reject(new Error(\"expected a valid extent\"));\n }\n });\n });\n}\n\n/**\n * Creates a simple map registry service with exactly one map configuration.\n *\n * The map is configured by using the `options` parameter.\n *\n * Returns the map registry and the id of the configured map.\n */\nexport async function setupMap(options?: SimpleMapOptions) {\n // Always use \"test\" as mapId for unit tests\n const mapId = \"test\";\n\n const getInitialView = (): InitialViewConfig => {\n if (options?.extent) {\n return {\n kind: \"extent\",\n extent: options.extent\n };\n }\n return {\n kind: \"position\",\n center: options?.center ?? { x: 847541, y: 6793584 },\n zoom: options?.zoom ?? 10\n };\n };\n\n const mapConfig: MapConfig = {\n initialView: options?.noInitialView ? undefined : getInitialView(),\n projection: options?.noProjection ? undefined : options?.projection ?? \"EPSG:3857\",\n layers: options?.layers?.map(\n (config) => (\"map\" in config ? config : new SimpleLayer(config))\n // using map as discriminator (no prototype for Layer)\n ) ?? [\n new SimpleLayer({\n title: \"OSM\",\n olLayer: new VectorLayer()\n })\n ],\n advanced: options?.advanced\n };\n\n const httpService = {\n async fetch(resource, init) {\n if (options?.fetch) {\n const url = new URL(resource, \"http://localhost:1234\");\n return options.fetch(url, init);\n }\n throw new Error(\n \"Network requests are not implemented (override fetch via map test utils if your test requires network access).\"\n );\n }\n } satisfies Partial<HttpService> as HttpService;\n\n const registry = await createService(MapRegistryImpl, {\n references: {\n providers: [new MapConfigProviderImpl(mapId, mapConfig)],\n httpService: httpService\n }\n });\n\n return { mapId, registry };\n}\n\n/**\n * Creates (service name, service implementation)-pairs suitable for the `services`\n * option of the `PackageContextProvider`.\n *\n * This helper method can be used to avoid hard-coding service names used in the implementation.\n */\nexport function createServiceOptions(services: { registry: MapRegistry }): Record<string, unknown> {\n return {\n \"map.MapRegistry\": services.registry\n };\n}\n\nclass MapConfigProviderImpl implements MapConfigProvider {\n mapId = \"default\";\n mapConfig: MapConfig;\n\n constructor(mapId: string, mapConfig?: MapConfig | undefined) {\n this.mapId = mapId;\n this.mapConfig = mapConfig ?? {};\n }\n\n getMapConfig(): Promise<MapConfig> {\n return Promise.resolve(this.mapConfig);\n }\n}\n\nfunction mockVectorLayer() {\n // Overwrite render so it doesn't actually do anything during tests.\n // Would otherwise error because <canvas /> is not fully implemented in happy dom.\n const div = document.createElement(\"div\");\n VectorLayer.prototype.render = () => {\n return div;\n };\n}\n\nmockVectorLayer();\n"],"names":[],"mappings":";;;;;;AAoEsB,eAAA,eAAA,CAAgB,eAAe,MAAQ,EAAA;AACzD,EAAO,OAAA,MAAM,QAAQ,YAAY;AAC7B,IAAA,MAAM,UAAa,GAAA,MAAM,MAAO,CAAA,YAAA,CAAa,YAAY,CAAA,CAAA;AACzD,IAAM,MAAA,SAAA,GAAY,UAAW,CAAA,aAAA,CAAc,cAAc,CAAA,CAAA;AACzD,IAAA,IAAI,CAAC,SAAW,EAAA;AACZ,MAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAAA;AAAA,KACrC;AACA,IAAO,OAAA,UAAA,CAAA;AAAA,GACV,CAAA,CAAA;AACL,CAAA;AAKA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AC,CAAA;AAAA,GACnC;AAAA,EAEA,YAAmC,GAAA;AAC/B,IAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,GACzC;AACJ,CAAA;AAEA,SAAS,eAAkB,GAAA;AAGvB,EAAM,MAAA,GAAA,GAAM,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA,CAAA;AACxC,EAAY,WAAA,CAAA,SAAA,CAAU,SAAS,MAAM;AACjC,IAAO,OAAA,GAAA,CAAA;AAAA,GACX,CAAA;AACJ,CAAA;AAEA,eAAgB,EAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/map-test-utils",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"description": "This package is an internal support package for testing map-related UI components.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"open-pioneer-trails"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/open-pioneer",
|
|
5
10
|
"license": "Apache-2.0",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/open-pioneer/trails-openlayers-base-packages",
|
|
14
|
+
"directory": "src/packages/map-test-utils"
|
|
15
|
+
},
|
|
6
16
|
"peerDependencies": {
|
|
7
|
-
"@open-pioneer/test-utils": "^1.
|
|
17
|
+
"@open-pioneer/test-utils": "^1.1.1",
|
|
8
18
|
"@testing-library/react": "^14.1.2",
|
|
9
|
-
"ol": "^
|
|
10
|
-
"@open-pioneer/map": "^0.
|
|
19
|
+
"ol": "^9.0.0",
|
|
20
|
+
"@open-pioneer/map": "^0.4.0"
|
|
11
21
|
},
|
|
12
22
|
"exports": {
|
|
13
23
|
"./package.json": "./package.json",
|