@open-pioneer/map-test-utils 0.9.0 → 0.10.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 +15 -0
- package/index.d.ts +20 -4
- package/index.js +9 -2
- package/index.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @open-pioneer/map-test-utils
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cd1435b: Update ol to 10.5.0
|
|
8
|
+
- 032eed7: Bump dependencies.
|
|
9
|
+
- cd1435b: Update to react 19.1.0
|
|
10
|
+
- Updated dependencies [2bafdad]
|
|
11
|
+
- Updated dependencies [cd1435b]
|
|
12
|
+
- Updated dependencies [193068a]
|
|
13
|
+
- Updated dependencies [032eed7]
|
|
14
|
+
- Updated dependencies [cd1435b]
|
|
15
|
+
- Updated dependencies [7558df4]
|
|
16
|
+
- @open-pioneer/map@0.10.0
|
|
17
|
+
|
|
3
18
|
## 0.9.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { HttpServiceRequestInit } from "@open-pioneer/http";
|
|
2
2
|
import { ExtentConfig, Layer, MapModel, MapRegistry, OlMapOptions, SimpleLayerConfig } from "@open-pioneer/map";
|
|
3
|
-
import { MapRegistryImpl } from "@open-pioneer/map/internalTestSupport";
|
|
4
3
|
export interface SimpleMapOptions {
|
|
4
|
+
/** ID of the map.
|
|
5
|
+
* Defaults to "test". */
|
|
6
|
+
mapId?: string;
|
|
5
7
|
/** Center coordinates for the map. */
|
|
6
8
|
center?: {
|
|
7
9
|
x: number;
|
|
@@ -37,6 +39,13 @@ export interface SimpleMapOptions {
|
|
|
37
39
|
* Disables the default projection when set to true.
|
|
38
40
|
*/
|
|
39
41
|
noProjection?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Also returns the map object in the return value.
|
|
44
|
+
* True by default.
|
|
45
|
+
*
|
|
46
|
+
* Use `false` to test the async loading behavior of the registry.
|
|
47
|
+
*/
|
|
48
|
+
returnMap?: boolean;
|
|
40
49
|
}
|
|
41
50
|
/**
|
|
42
51
|
* Waits until the OpenLayers map has been mounted in the parent with the given id.
|
|
@@ -46,17 +55,24 @@ export declare function waitForMapMount(parentTestId?: string): Promise<HTMLElem
|
|
|
46
55
|
* Waits until the model has an initial extent.
|
|
47
56
|
*/
|
|
48
57
|
export declare function waitForInitialExtent(model: MapModel): Promise<void>;
|
|
58
|
+
export interface SetupMapResult {
|
|
59
|
+
mapId: string;
|
|
60
|
+
registry: MapRegistry;
|
|
61
|
+
}
|
|
49
62
|
/**
|
|
50
63
|
* Creates a simple map registry service with exactly one map configuration.
|
|
51
64
|
*
|
|
52
65
|
* The map is configured by using the `options` parameter.
|
|
66
|
+
* If `options.returnMap` is `true` (the default), the map model is also returned.
|
|
53
67
|
*
|
|
54
68
|
* Returns the map registry and the id of the configured map.
|
|
55
69
|
*/
|
|
56
|
-
export declare function setupMap(options?: SimpleMapOptions
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
export declare function setupMap(options?: SimpleMapOptions & {
|
|
71
|
+
returnMap?: true;
|
|
72
|
+
}): Promise<SetupMapResult & {
|
|
73
|
+
map: MapModel;
|
|
59
74
|
}>;
|
|
75
|
+
export declare function setupMap(options?: SimpleMapOptions): Promise<SetupMapResult>;
|
|
60
76
|
/**
|
|
61
77
|
* Creates (service name, service implementation)-pairs suitable for the `services`
|
|
62
78
|
* option of the `PackageContextProvider`.
|
package/index.js
CHANGED
|
@@ -34,7 +34,7 @@ async function waitForInitialExtent(model) {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
async function setupMap(options) {
|
|
37
|
-
const mapId = "test";
|
|
37
|
+
const mapId = options?.mapId ?? "test";
|
|
38
38
|
const getInitialView = () => {
|
|
39
39
|
if (options?.extent) {
|
|
40
40
|
return {
|
|
@@ -79,7 +79,11 @@ async function setupMap(options) {
|
|
|
79
79
|
httpService
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
let map;
|
|
83
|
+
if (options?.returnMap !== false) {
|
|
84
|
+
map = await registry.expectMapModel(mapId);
|
|
85
|
+
}
|
|
86
|
+
return { mapId, registry, map };
|
|
83
87
|
}
|
|
84
88
|
function createServiceOptions(services) {
|
|
85
89
|
return {
|
|
@@ -102,6 +106,9 @@ function mockVectorLayer() {
|
|
|
102
106
|
VectorLayer.prototype.render = () => {
|
|
103
107
|
return div;
|
|
104
108
|
};
|
|
109
|
+
VectorLayer.prototype.setStyle = () => {
|
|
110
|
+
};
|
|
111
|
+
VectorLayer.prototype.getStyleFunction = () => () => [];
|
|
105
112
|
}
|
|
106
113
|
mockVectorLayer();
|
|
107
114
|
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { watch } from \"@conterra/reactivity-core\";\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 { MapRegistryImpl } from \"@open-pioneer/map/internalTestSupport\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport VectorLayer from \"ol/layer/Vector\";\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 const resource = watch(\n () => [model.initialExtent],\n ([extent]) => {\n resource.destroy();\n if (extent) {\n resolve();\n } else {\n reject(new Error(\"Expected a valid initial extent\"));\n }\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
|
|
1
|
+
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { watch } from \"@conterra/reactivity-core\";\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 { MapRegistryImpl } from \"@open-pioneer/map/internalTestSupport\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport VectorLayer from \"ol/layer/Vector\";\n\nexport interface SimpleMapOptions {\n /** ID of the map.\n * Defaults to \"test\". */\n mapId?: string;\n\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 * Also returns the map object in the return value.\n * True by default.\n *\n * Use `false` to test the async loading behavior of the registry.\n */\n returnMap?: 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 const resource = watch(\n () => [model.initialExtent],\n ([extent]) => {\n resource.destroy();\n if (extent) {\n resolve();\n } else {\n reject(new Error(\"Expected a valid initial extent\"));\n }\n }\n );\n });\n}\n\nexport interface SetupMapResult {\n mapId: string;\n registry: MapRegistry;\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 * If `options.returnMap` is `true` (the default), the map model is also returned.\n *\n * Returns the map registry and the id of the configured map.\n */\nexport async function setupMap(\n options?: SimpleMapOptions & { returnMap?: true }\n): Promise<SetupMapResult & { map: MapModel }>;\nexport async function setupMap(options?: SimpleMapOptions): Promise<SetupMapResult>;\nexport async function setupMap(\n options?: SimpleMapOptions\n): Promise<SetupMapResult & { map: MapModel | undefined }> {\n const mapId = options?.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 let map: MapModel | undefined;\n if (options?.returnMap !== false) {\n map = await registry.expectMapModel(mapId);\n }\n return { mapId, registry, map };\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 // Needed by tests in editing package\n VectorLayer.prototype.setStyle = () => {};\n VectorLayer.prototype.getStyleFunction = () => () => [];\n}\n\nmockVectorLayer();\n"],"names":[],"mappings":";;;;;;;AA+EsB,eAAA,eAAA,CAAgB,eAAe,MAAQ,EAAA;AACzD,EAAO,OAAA,MAAM,QAAQ,YAAY;AAC7B,IAAA,MAAM,UAAa,GAAA,MAAM,MAAO,CAAA,YAAA,CAAa,YAAY,CAAA;AACzD,IAAM,MAAA,SAAA,GAAY,UAAW,CAAA,aAAA,CAAc,cAAc,CAAA;AACzD,IAAA,IAAI,CAAC,SAAW,EAAA;AACZ,MAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA;AAAA;AAErC,IAAO,OAAA,UAAA;AAAA,GACV,CAAA;AACL;AAKA,eAAsB,qBAAqB,KAAiB,EAAA;AACxD,EAAA,IAAI,MAAM,aAAe,EAAA;AACrB,IAAA;AAAA;AAGJ,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAW,KAAA;AACzC,IAAA,MAAM,QAAW,GAAA,KAAA;AAAA,MACb,MAAM,CAAC,KAAA,CAAM,aAAa,CAAA;AAAA,MAC1B,CAAC,CAAC,MAAM,CAAM,KAAA;AACV,QAAA,QAAA,CAAS,OAAQ,EAAA;AACjB,QAAA,IAAI,MAAQ,EAAA;AACR,UAAQ,OAAA,EAAA;AAAA,SACL,MAAA;AACH,UAAO,MAAA,CAAA,IAAI,KAAM,CAAA,iCAAiC,CAAC,CAAA;AAAA;AACvD;AACJ,K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EAAC;AAC1D;AAEA,eAAgB,EAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/map-test-utils",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "This package is an internal support package for testing map-related UI components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"directory": "src/packages/map-test-utils"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@open-pioneer/test-utils": "^3.
|
|
18
|
-
"@testing-library/react": "^16.
|
|
19
|
-
"ol": "^10.
|
|
20
|
-
"@conterra/reactivity-core": "^0.
|
|
21
|
-
"@open-pioneer/map": "^0.
|
|
17
|
+
"@open-pioneer/test-utils": "^3.1.0",
|
|
18
|
+
"@testing-library/react": "^16.3.0",
|
|
19
|
+
"ol": "^10.5.0",
|
|
20
|
+
"@conterra/reactivity-core": "^0.5.0",
|
|
21
|
+
"@open-pioneer/map": "^0.10.0"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
"./package.json": "./package.json",
|