@open-pioneer/map-test-utils 1.4.0 → 1.5.0-dev.20260910103330
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 +47 -5
- package/index.d.ts +8 -0
- package/index.js +6 -4
- package/index.js.map +1 -1
- package/package.json +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @open-pioneer/map-test-utils
|
|
2
2
|
|
|
3
|
+
## 1.5.0-dev.20260910103330
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f790fda: Update to Chakra 3.37.0
|
|
8
|
+
- ebda251: Add new properties for topmost layers and base layers in `MapConfig`.
|
|
9
|
+
|
|
10
|
+
- With `MapConfig.topmostLayers` topmost layers can now be defined in the initial map setup.
|
|
11
|
+
- Base layers can now be defined in the initial map setup with the `MapConfig.baseLayers` property
|
|
12
|
+
|
|
13
|
+
We recommend using the `baseLayers` property instead of `isBaseLayer: true` for new apps.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
export class MapConfigProviderImpl implements MapConfigProvider {
|
|
17
|
+
mapId = MAP_ID;
|
|
18
|
+
|
|
19
|
+
async getMapConfig({ layerFactory }: MapConfigProviderOptions): Promise<MapConfig> {
|
|
20
|
+
return {
|
|
21
|
+
initialView: {...},
|
|
22
|
+
projection: "EPSG:25832",
|
|
23
|
+
baseLayers: [
|
|
24
|
+
//all base layers
|
|
25
|
+
layerFactory.create(...)
|
|
26
|
+
],
|
|
27
|
+
layers: [
|
|
28
|
+
//all other operational layers
|
|
29
|
+
layerFactory.create(...),
|
|
30
|
+
layerFactory.create(...)
|
|
31
|
+
],
|
|
32
|
+
topmostLayers: [
|
|
33
|
+
//all operational highlight layers
|
|
34
|
+
layerFactory.create(...)
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- 09ec7c7: Updated dependencies
|
|
44
|
+
|
|
3
45
|
## 1.4.0
|
|
4
46
|
|
|
5
47
|
### Minor Changes
|
|
@@ -41,8 +83,8 @@
|
|
|
41
83
|
|
|
42
84
|
- 14c484e: Deprecate `createServiceOptions()` function.
|
|
43
85
|
|
|
44
|
-
|
|
45
|
-
|
|
86
|
+
This function was previously used in tests to mock the map registry for a react component under test.
|
|
87
|
+
This is no longer necessary because our react components now receive the map model directly (no lookup is done anymore).
|
|
46
88
|
|
|
47
89
|
### Minor Changes
|
|
48
90
|
|
|
@@ -84,9 +126,9 @@
|
|
|
84
126
|
### Minor Changes
|
|
85
127
|
|
|
86
128
|
- 2fa8020: Update trails core package dependencies.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
129
|
+
- Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
|
|
130
|
+
- Removes any obsolete references to `@chakra-ui/system`.
|
|
131
|
+
This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
|
|
90
132
|
|
|
91
133
|
### Patch Changes
|
|
92
134
|
|
package/index.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export interface SimpleMapOptions {
|
|
|
25
25
|
* Layers used by the map.
|
|
26
26
|
*/
|
|
27
27
|
layers?: LayerConfig[];
|
|
28
|
+
/**
|
|
29
|
+
* Base layers for the map.
|
|
30
|
+
*/
|
|
31
|
+
baseLayers?: LayerConfig[];
|
|
32
|
+
/**
|
|
33
|
+
* Layers that are displayed on top of all other layers.
|
|
34
|
+
*/
|
|
35
|
+
topmostLayers?: LayerConfig[];
|
|
28
36
|
/** See {@link MapConfig.showAttributions} */
|
|
29
37
|
showAttributions?: boolean;
|
|
30
38
|
/**
|
package/index.js
CHANGED
|
@@ -47,10 +47,9 @@ async function setupMap(options) {
|
|
|
47
47
|
const mapConfig = {
|
|
48
48
|
initialView: options?.noInitialView ? void 0 : getInitialView(options),
|
|
49
49
|
projection: options?.noProjection ? void 0 : options?.projection ?? "EPSG:3857",
|
|
50
|
-
layers: options?.layers?.map(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
) ?? [createTestLayer()],
|
|
50
|
+
layers: options?.layers?.map((config) => useOrCreateLayer(config)) ?? [createTestLayer()],
|
|
51
|
+
baseLayers: options?.baseLayers?.map((config) => useOrCreateLayer(config)) ?? [],
|
|
52
|
+
topmostLayers: options?.topmostLayers?.map((config) => useOrCreateLayer(config)) ?? [],
|
|
54
53
|
showAttributions: options?.showAttributions,
|
|
55
54
|
advanced: options?.advanced
|
|
56
55
|
};
|
|
@@ -136,6 +135,9 @@ function mockVectorLayer() {
|
|
|
136
135
|
return div;
|
|
137
136
|
};
|
|
138
137
|
}
|
|
138
|
+
function useOrCreateLayer(config) {
|
|
139
|
+
return "map" in config ? config : createTestLayer({ type: SimpleLayer, ...config });
|
|
140
|
+
}
|
|
139
141
|
mockVectorLayer();
|
|
140
142
|
|
|
141
143
|
export { createServiceOptions, createTestLayer, createTestOlLayer, setupMap, waitForInitialExtent, waitForMapMount };
|
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\n\nimport { constant, watch } from \"@conterra/reactivity-core\";\nimport { HttpService, HttpServiceRequestInit } from \"@open-pioneer/http\";\nimport {\n ExtentConfig,\n InitialViewConfig,\n Layer,\n LayerCreateOptions,\n LayerFactory,\n MapConfig,\n MapModel,\n LayerConfig as MapPackageLayerConfig,\n MapRegistry,\n OlMapOptions,\n SimpleLayer,\n SimpleLayerConfig\n} from \"@open-pioneer/map\";\nimport {\n LayerFactory as LayerFactoryImpl,\n MapRegistry as MapRegistryImpl\n} from \"@open-pioneer/map/internalTestSupport\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport TileLayer from \"ol/layer/Tile\";\nimport VectorLayer from \"ol/layer/Vector\";\n\nexport type LayerConfig = SimpleLayerConfig | Layer;\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?: LayerConfig[];\n\n /** See {@link MapConfig.showAttributions} */\n showAttributions?: boolean;\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}\nconst DUMMY_HTTP_SERVICE = {\n async fetch() {\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;\nconst DUMMY_LAYER_FACTORY = createLayerFactory();\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 layerFactory: LayerFactory;\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 const mapConfig: MapConfig = {\n initialView: options?.noInitialView ? undefined : getInitialView(options),\n projection: options?.noProjection ? undefined : (options?.projection ?? \"EPSG:3857\"),\n layers: options?.layers?.map(\n (config) =>\n \"map\" in config\n ? config\n : createTestLayer({ type: SimpleLayer, ...(config as SimpleLayerConfig) })\n // using map as discriminator (no prototype for Layer)\n ) ?? [createTestLayer()],\n showAttributions: options?.showAttributions,\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 layerFactory = await createService(LayerFactoryImpl, {\n references: {\n httpService\n }\n });\n\n const registry = await createService(MapRegistryImpl, {\n references: {\n providers: [],\n httpService,\n layerFactory\n }\n });\n\n let map: MapModel | undefined;\n const promise = registry.createMapModel(mapId, mapConfig);\n if (options?.returnMap !== false) {\n map = await promise;\n } else {\n // Ignore error on this promise (prevents unhandled error in tests)\n promise.catch(() => undefined);\n }\n return { mapId, registry, layerFactory, map };\n}\n\nfunction getInitialView(options: SimpleMapOptions | undefined): 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/** Creates an new layer of the specified type for testing. */\nexport function createTestLayer<LayerType extends Layer, Config extends MapPackageLayerConfig>(\n config: LayerCreateOptions<LayerType, Config>,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): LayerType;\n\n/** Creates a new, basic SimpleLayer for testing. */\nexport function createTestLayer(\n config?: SimpleLayerConfig,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): SimpleLayer;\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTestLayer(config?: any, mapOptions?: Pick<SimpleMapOptions, \"fetch\">): Layer {\n // Basic case: If no config is given, use SimpleLayer\n if (!config) {\n config = {\n type: SimpleLayer,\n title: \"Test layer\",\n olLayer: new VectorLayer()\n } as LayerCreateOptions<SimpleLayer, SimpleLayerConfig>;\n } else if (!config.type) {\n config.type = SimpleLayer;\n }\n\n const factory = mapOptions?.fetch\n ? createLayerFactory({ fetch: mapOptions.fetch })\n : DUMMY_LAYER_FACTORY;\n return factory.create(config);\n}\n\n/**\n * Returns a simple, empty OpenLayers layer object.\n *\n * Use this if you need any kind of `olLayer` in your test.\n */\nexport function createTestOlLayer(): TileLayer {\n return new TileLayer();\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 *\n * @deprecated This function is no longer needed, since most widgets no longer depend on the registry\n * and accept the `map` directly.\n */\nexport function createServiceOptions(services: { registry: MapRegistry }): Record<string, unknown> {\n return {\n \"map.MapRegistry\": services.registry\n };\n}\n\nfunction createLayerFactory(httpService?: HttpService): LayerFactory {\n const intl = {} satisfies Partial<PackageIntl> as PackageIntl;\n return new LayerFactoryImpl({\n intl,\n currentIntl: constant(intl),\n references: { httpService: httpService ?? DUMMY_HTTP_SERVICE },\n properties: {},\n referencesMeta: { httpService: { serviceId: \"http.HttpService\" } }\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":["LayerFactoryImpl","MapRegistryImpl"],"mappings":";;;;;;;;AAwFA,MAAM,kBAAA,GAAqB;AAAA,EACvB,MAAM,KAAA,GAAQ;AACV,IAAA,MAAM,IAAI,KAAA;AAAA,MACN;AAAA,KACJ;AAAA,EACJ;AACJ,CAAA;AACA,MAAM,sBAAsB,kBAAA,EAAmB;AAK/C,eAAsB,eAAA,CAAgB,eAAe,MAAA,EAAQ;AACzD,EAAA,OAAO,MAAM,QAAQ,YAAY;AAC7B,IAAA,MAAM,UAAA,GAAa,MAAM,MAAA,CAAO,YAAA,CAAa,YAAY,CAAA;AACzD,IAAA,MAAM,SAAA,GAAY,UAAA,CAAW,aAAA,CAAc,cAAc,CAAA;AACzD,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AAAA,IACrC;AACA,IAAA,OAAO,UAAA;AAAA,EACX,CAAC,CAAA;AACL;AAKA,eAAsB,qBAAqB,KAAA,EAAiB;AACxD,EAAA,IAAI,MAAM,aAAA,EAAe;AACrB,IAAA;AAAA,EACJ;AAEA,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AACzC,IAAA,MAAM,QAAA,GAAW,KAAA;AAAA,MACb,MAAM,CAAC,KAAA,CAAM,aAAa,CAAA;AAAA,MAC1B,CAAC,CAAC,MAAM,CAAA,KAAM;AACV,QAAA,QAAA,CAAS,OAAA,EAAQ;AACjB,QAAA,IAAI,MAAA,EAAQ;AACR,UAAA,OAAA,EAAQ;AAAA,QACZ,CAAA,MAAO;AACH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E,KAAA,EAAO,UAAA,CAAW,KAAA,EAAO,CAAA,GAC9C,mBAAA;AACN,EAAA,OAAO,OAAA,CAAQ,OAAO,MAAM,CAAA;AAChC;AAOO,SAAS,iBAAA,GAA+B;AAC3C,EAAA,OAAO,IAAI,SAAA,EAAU;AACzB;AAWO,SAAS,qBAAqB,QAAA,EAA8D;AAC/F,EAAA,OAAO;AAAA,IACH,mBAAmB,QAAA,CAAS;AAAA,GAChC;AACJ;AAEA,SAAS,mBAAmB,WAAA,EAAyC;AACjE,EAAA,MAAM,OAAO,EAAC;AACd,EAAA,OAAO,IAAID,YAAA,CAAiB;AAAA,IACxB,IAAA;AAAA,IACA,WAAA,EAAa,SAAS,IAAI,CAAA;AAAA,IAC1B,UAAA,EAAY,EAAE,WAAA,EAAa,WAAA,IAAe,kBAAA,EAAmB;AAAA,IAC7D,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAE,WAAA,EAAa,EAAE,SAAA,EAAW,oBAAmB;AAAE,GACpE,CAAA;AACL;AAEA,SAAS,eAAA,GAAkB;AAGvB,EAAA,MAAM,GAAA,GAAM,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,SAAS,MAAM;AACjC,IAAA,OAAO,GAAA;AAAA,EACX,CAAA;AACJ;AAEA,eAAA,EAAgB;;;;"}
|
|
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\n\nimport { constant, watch } from \"@conterra/reactivity-core\";\nimport { HttpService, HttpServiceRequestInit } from \"@open-pioneer/http\";\nimport {\n ExtentConfig,\n InitialViewConfig,\n Layer,\n LayerCreateOptions,\n LayerFactory,\n MapConfig,\n MapModel,\n LayerConfig as MapPackageLayerConfig,\n MapRegistry,\n OlMapOptions,\n SimpleLayer,\n SimpleLayerConfig\n} from \"@open-pioneer/map\";\nimport {\n LayerFactory as LayerFactoryImpl,\n MapRegistry as MapRegistryImpl\n} from \"@open-pioneer/map/internalTestSupport\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport TileLayer from \"ol/layer/Tile\";\nimport VectorLayer from \"ol/layer/Vector\";\n\nexport type LayerConfig = SimpleLayerConfig | Layer;\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?: LayerConfig[];\n\n /**\n * Base layers for the map.\n */\n baseLayers?: LayerConfig[];\n\n /**\n * Layers that are displayed on top of all other layers.\n */\n topmostLayers?: LayerConfig[];\n\n /** See {@link MapConfig.showAttributions} */\n showAttributions?: boolean;\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}\nconst DUMMY_HTTP_SERVICE = {\n async fetch() {\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;\nconst DUMMY_LAYER_FACTORY = createLayerFactory();\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 layerFactory: LayerFactory;\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 const mapConfig: MapConfig = {\n initialView: options?.noInitialView ? undefined : getInitialView(options),\n projection: options?.noProjection ? undefined : (options?.projection ?? \"EPSG:3857\"),\n layers: options?.layers?.map((config) => useOrCreateLayer(config)) ?? [createTestLayer()],\n baseLayers: options?.baseLayers?.map((config) => useOrCreateLayer(config)) ?? [],\n topmostLayers: options?.topmostLayers?.map((config) => useOrCreateLayer(config)) ?? [],\n showAttributions: options?.showAttributions,\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 layerFactory = await createService(LayerFactoryImpl, {\n references: {\n httpService\n }\n });\n\n const registry = await createService(MapRegistryImpl, {\n references: {\n providers: [],\n httpService,\n layerFactory\n }\n });\n\n let map: MapModel | undefined;\n const promise = registry.createMapModel(mapId, mapConfig);\n if (options?.returnMap !== false) {\n map = await promise;\n } else {\n // Ignore error on this promise (prevents unhandled error in tests)\n promise.catch(() => undefined);\n }\n return { mapId, registry, layerFactory, map };\n}\n\nfunction getInitialView(options: SimpleMapOptions | undefined): 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/** Creates an new layer of the specified type for testing. */\nexport function createTestLayer<LayerType extends Layer, Config extends MapPackageLayerConfig>(\n config: LayerCreateOptions<LayerType, Config>,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): LayerType;\n\n/** Creates a new, basic SimpleLayer for testing. */\nexport function createTestLayer(\n config?: SimpleLayerConfig,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): SimpleLayer;\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTestLayer(config?: any, mapOptions?: Pick<SimpleMapOptions, \"fetch\">): Layer {\n // Basic case: If no config is given, use SimpleLayer\n if (!config) {\n config = {\n type: SimpleLayer,\n title: \"Test layer\",\n olLayer: new VectorLayer()\n } as LayerCreateOptions<SimpleLayer, SimpleLayerConfig>;\n } else if (!config.type) {\n config.type = SimpleLayer;\n }\n\n const factory = mapOptions?.fetch\n ? createLayerFactory({ fetch: mapOptions.fetch })\n : DUMMY_LAYER_FACTORY;\n return factory.create(config);\n}\n\n/**\n * Returns a simple, empty OpenLayers layer object.\n *\n * Use this if you need any kind of `olLayer` in your test.\n */\nexport function createTestOlLayer(): TileLayer {\n return new TileLayer();\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 *\n * @deprecated This function is no longer needed, since most widgets no longer depend on the registry\n * and accept the `map` directly.\n */\nexport function createServiceOptions(services: { registry: MapRegistry }): Record<string, unknown> {\n return {\n \"map.MapRegistry\": services.registry\n };\n}\n\nfunction createLayerFactory(httpService?: HttpService): LayerFactory {\n const intl = {} satisfies Partial<PackageIntl> as PackageIntl;\n return new LayerFactoryImpl({\n intl,\n currentIntl: constant(intl),\n references: { httpService: httpService ?? DUMMY_HTTP_SERVICE },\n properties: {},\n referencesMeta: { httpService: { serviceId: \"http.HttpService\" } }\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\nfunction useOrCreateLayer(config: LayerConfig): Layer {\n return \"map\" in config\n ? config\n : createTestLayer({ type: SimpleLayer, ...(config as SimpleLayerConfig) });\n // using map as discriminator (no prototype for Layer)\n}\n\nmockVectorLayer();\n"],"names":["LayerFactoryImpl","MapRegistryImpl"],"mappings":";;;;;;;;AAkGA,MAAM,kBAAA,GAAqB;AAAA,EACvB,MAAM,KAAA,GAAQ;AACV,IAAA,MAAM,IAAI,KAAA;AAAA,MACN;AAAA,KACJ;AAAA,EACJ;AACJ,CAAA;AACA,MAAM,sBAAsB,kBAAA,EAAmB;AAK/C,eAAsB,eAAA,CAAgB,eAAe,MAAA,EAAQ;AACzD,EAAA,OAAO,MAAM,QAAQ,YAAY;AAC7B,IAAA,MAAM,UAAA,GAAa,MAAM,MAAA,CAAO,YAAA,CAAa,YAAY,CAAA;AACzD,IAAA,MAAM,SAAA,GAAY,UAAA,CAAW,aAAA,CAAc,cAAc,CAAA;AACzD,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AAAA,IACrC;AACA,IAAA,OAAO,UAAA;AAAA,EACX,CAAC,CAAA;AACL;AAKA,eAAsB,qBAAqB,KAAA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A,CAAc,KAAK,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,SAAS,MAAM;AACjC,IAAA,OAAO,GAAA;AAAA,EACX,CAAA;AACJ;AAEA,SAAS,iBAAiB,MAAA,EAA4B;AAClD,EAAA,OAAO,KAAA,IAAS,SACV,MAAA,GACA,eAAA,CAAgB,EAAE,IAAA,EAAM,WAAA,EAAa,GAAI,MAAA,EAA8B,CAAA;AAEjF;AAEA,eAAA,EAAgB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/map-test-utils",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0-dev.20260910103330",
|
|
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,15 @@
|
|
|
14
14
|
"directory": "src/packages/map-test-utils"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@conterra/reactivity-core": "^0.8.
|
|
18
|
-
"@open-pioneer/
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
21
|
-
"
|
|
17
|
+
"@conterra/reactivity-core": "^0.8.8",
|
|
18
|
+
"@open-pioneer/map": "1.5.0-dev.20260910103330",
|
|
19
|
+
"@open-pioneer/test-utils": "4.8.0-dev.20260910101405",
|
|
20
|
+
"@testing-library/react": "^16.3.3",
|
|
21
|
+
"ol": "^10.10.0"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"directory": "dist",
|
|
25
|
+
"linkDirectory": false
|
|
22
26
|
},
|
|
23
27
|
"exports": {
|
|
24
28
|
"./package.json": "./package.json",
|