@open-pioneer/map-test-utils 0.12.0-dev.20250905090001 → 1.0.0-dev.20251020091932

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 CHANGED
@@ -1,22 +1,46 @@
1
1
  # @open-pioneer/map-test-utils
2
2
 
3
- ## 0.12.0-dev.20250905090001
3
+ ## 1.0.0-dev.20251020091932
4
+
5
+ ### Major Changes
6
+
7
+ - 14c484e: Deprecate `createServiceOptions()` function.
8
+
9
+ This function was previously used in tests to mock the map registry for a react component under test.
10
+ This is no longer necessary because our react components now receive the map model directly (no lookup is done anymore).
11
+
12
+ ### Minor Changes
13
+
14
+ - 14c484e: Create a new test helper `createTestOlLayer()` that returns a simple, empty (tile) layer.
15
+ - 2abcaaf: Update to chakra-ui 3.27.1
4
16
 
5
17
  ### Patch Changes
6
18
 
7
19
  - 10d2fe7: Update dependencies
20
+ - 138d85b: Update core packages to 4.1.0
8
21
  - da6a410: Update dependencies
22
+ - Updated dependencies [c6180c6]
9
23
  - Updated dependencies [29a10df]
10
24
  - Updated dependencies [10d2fe7]
11
25
  - Updated dependencies [2702df4]
12
26
  - Updated dependencies [12561fe]
13
27
  - Updated dependencies [5df900f]
14
28
  - Updated dependencies [8986b3b]
29
+ - Updated dependencies [b3709f1]
30
+ - Updated dependencies [dfd7c7e]
31
+ - Updated dependencies [14c484e]
32
+ - Updated dependencies [138d85b]
15
33
  - Updated dependencies [aeb9000]
34
+ - Updated dependencies [9e9bc6e]
35
+ - Updated dependencies [b3709f1]
36
+ - Updated dependencies [2c8b617]
37
+ - Updated dependencies [b3709f1]
16
38
  - Updated dependencies [5df900f]
17
39
  - Updated dependencies [f1f69f2]
40
+ - Updated dependencies [773fa2d]
41
+ - Updated dependencies [2abcaaf]
18
42
  - Updated dependencies [da6a410]
19
- - @open-pioneer/map@0.12.0-dev.20250905090001
43
+ - @open-pioneer/map@1.0.0-dev.20251020091932
20
44
 
21
45
  ## 0.11.0
22
46
 
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HttpServiceRequestInit } from "@open-pioneer/http";
2
- import { ExtentConfig, Layer, MapModel, MapRegistry, OlMapOptions, SimpleLayerConfig } from "@open-pioneer/map";
2
+ import { ExtentConfig, Layer, LayerCreateOptions, MapModel, LayerConfig as MapPackageLayerConfig, MapRegistry, OlMapOptions, SimpleLayer, SimpleLayerConfig } from "@open-pioneer/map";
3
+ import TileLayer from "ol/layer/Tile";
3
4
  export type LayerConfig = SimpleLayerConfig | Layer;
4
5
  export interface SimpleMapOptions {
5
6
  /** ID of the map.
@@ -74,11 +75,24 @@ export declare function setupMap(options?: SimpleMapOptions & {
74
75
  map: MapModel;
75
76
  }>;
76
77
  export declare function setupMap(options?: SimpleMapOptions): Promise<SetupMapResult>;
78
+ /** Creates an new layer of the specified type for testing. */
79
+ export declare function createTestLayer<LayerType extends Layer, Config extends MapPackageLayerConfig>(config: LayerCreateOptions<LayerType, Config>, mapOptions?: Pick<SimpleMapOptions, "fetch">): LayerType;
80
+ /** Creates a new, basic SimpleLayer for testing. */
81
+ export declare function createTestLayer(config?: SimpleLayerConfig, mapOptions?: Pick<SimpleMapOptions, "fetch">): SimpleLayer;
82
+ /**
83
+ * Returns a simple, empty OpenLayers layer object.
84
+ *
85
+ * Use this if you need any kind of `olLayer` in your test.
86
+ */
87
+ export declare function createTestOlLayer(): TileLayer;
77
88
  /**
78
89
  * Creates (service name, service implementation)-pairs suitable for the `services`
79
90
  * option of the `PackageContextProvider`.
80
91
  *
81
92
  * This helper method can be used to avoid hard-coding service names used in the implementation.
93
+ *
94
+ * @deprecated This function is no longer needed, since most widgets no longer depend on the registry
95
+ * and accept the `map` directly.
82
96
  */
83
97
  export declare function createServiceOptions(services: {
84
98
  registry: MapRegistry;
package/index.js CHANGED
@@ -1,10 +1,19 @@
1
1
  import { watch } from '@conterra/reactivity-core';
2
2
  import { SimpleLayer } from '@open-pioneer/map';
3
- import { MapRegistryImpl } from '@open-pioneer/map/internalTestSupport';
3
+ import { LayerFactory, MapRegistry } from '@open-pioneer/map/internalTestSupport';
4
4
  import { createService } from '@open-pioneer/test-utils/services';
5
5
  import { waitFor, screen } from '@testing-library/react';
6
+ import TileLayer from 'ol/layer/Tile.js';
6
7
  import VectorLayer from 'ol/layer/Vector.js';
7
8
 
9
+ const DUMMY_HTTP_SERVICE = {
10
+ async fetch() {
11
+ throw new Error(
12
+ "Network requests are not implemented (override fetch via map test utils if your test requires network access)."
13
+ );
14
+ }
15
+ };
16
+ const DUMMY_LAYER_FACTORY = createLayerFactory();
8
17
  async function waitForMapMount(parentTestId = "base") {
9
18
  return await waitFor(async () => {
10
19
  const domElement = await screen.findByTestId(parentTestId);
@@ -35,31 +44,13 @@ async function waitForInitialExtent(model) {
35
44
  }
36
45
  async function setupMap(options) {
37
46
  const mapId = options?.mapId ?? "test";
38
- const getInitialView = () => {
39
- if (options?.extent) {
40
- return {
41
- kind: "extent",
42
- extent: options.extent
43
- };
44
- }
45
- return {
46
- kind: "position",
47
- center: options?.center ?? { x: 847541, y: 6793584 },
48
- zoom: options?.zoom ?? 10
49
- };
50
- };
51
47
  const mapConfig = {
52
- initialView: options?.noInitialView ? void 0 : getInitialView(),
48
+ initialView: options?.noInitialView ? void 0 : getInitialView(options),
53
49
  projection: options?.noProjection ? void 0 : options?.projection ?? "EPSG:3857",
54
50
  layers: options?.layers?.map(
55
- (config) => "map" in config ? config : new SimpleLayer(config)
51
+ (config) => "map" in config ? config : createTestLayer({ type: SimpleLayer, ...config })
56
52
  // using map as discriminator (no prototype for Layer)
57
- ) ?? [
58
- new SimpleLayer({
59
- title: "OSM",
60
- olLayer: new VectorLayer()
61
- })
62
- ],
53
+ ) ?? [createTestLayer()],
63
54
  advanced: options?.advanced
64
55
  };
65
56
  const httpService = {
@@ -73,33 +64,68 @@ async function setupMap(options) {
73
64
  );
74
65
  }
75
66
  };
76
- const registry = await createService(MapRegistryImpl, {
67
+ const layerFactory = await createService(LayerFactory, {
77
68
  references: {
78
- providers: [new MapConfigProviderImpl(mapId, mapConfig)],
79
69
  httpService
80
70
  }
81
71
  });
72
+ const registry = await createService(MapRegistry, {
73
+ references: {
74
+ providers: [],
75
+ httpService,
76
+ layerFactory
77
+ }
78
+ });
82
79
  let map;
80
+ const promise = registry.createMapModel(mapId, mapConfig);
83
81
  if (options?.returnMap !== false) {
84
- map = await registry.expectMapModel(mapId);
82
+ map = await promise;
83
+ } else {
84
+ promise.catch(() => void 0);
85
85
  }
86
86
  return { mapId, registry, map };
87
87
  }
88
+ function getInitialView(options) {
89
+ if (options?.extent) {
90
+ return {
91
+ kind: "extent",
92
+ extent: options.extent
93
+ };
94
+ }
95
+ return {
96
+ kind: "position",
97
+ center: options?.center ?? { x: 847541, y: 6793584 },
98
+ zoom: options?.zoom ?? 10
99
+ };
100
+ }
101
+ function createTestLayer(config, mapOptions) {
102
+ if (!config) {
103
+ config = {
104
+ type: SimpleLayer,
105
+ title: "Test layer",
106
+ olLayer: new VectorLayer()
107
+ };
108
+ } else if (!config.type) {
109
+ config.type = SimpleLayer;
110
+ }
111
+ const factory = mapOptions?.fetch ? createLayerFactory({ fetch: mapOptions.fetch }) : DUMMY_LAYER_FACTORY;
112
+ return factory.create(config);
113
+ }
114
+ function createTestOlLayer() {
115
+ return new TileLayer();
116
+ }
88
117
  function createServiceOptions(services) {
89
118
  return {
90
119
  "map.MapRegistry": services.registry
91
120
  };
92
121
  }
93
- class MapConfigProviderImpl {
94
- mapId = "default";
95
- mapConfig;
96
- constructor(mapId, mapConfig) {
97
- this.mapId = mapId;
98
- this.mapConfig = mapConfig ?? {};
99
- }
100
- getMapConfig() {
101
- return Promise.resolve(this.mapConfig);
102
- }
122
+ function createLayerFactory(httpService) {
123
+ return new LayerFactory({
124
+ intl: {},
125
+ references: { httpService: httpService ?? DUMMY_HTTP_SERVICE },
126
+ properties: {},
127
+ referencesMeta: { httpService: { serviceId: "http.HttpService" } }
128
+ });
103
129
  }
104
130
  function mockVectorLayer() {
105
131
  const div = document.createElement("div");
@@ -112,5 +138,5 @@ function mockVectorLayer() {
112
138
  }
113
139
  mockVectorLayer();
114
140
 
115
- export { createServiceOptions, setupMap, waitForInitialExtent, waitForMapMount };
141
+ export { createServiceOptions, createTestLayer, createTestOlLayer, setupMap, waitForInitialExtent, waitForMapMount };
116
142
  //# sourceMappingURL=index.js.map
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 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 * 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":";;;;;;;AAiFA,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,M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AQO,SAAS,qBAAqB,QAAA,EAA8D;AAC/F,EAAA,OAAO;AAAA,IACH,mBAAmB,QAAA,CAAS;AAAA,GAChC;AACJ;AAEA,MAAM,qBAAA,CAAmD;AAAA,EACrD,KAAA,GAAQ,SAAA;AAAA,EACR,SAAA;AAAA,EAEA,WAAA,CAAY,OAAe,SAAA,EAAmC;AAC1D,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,SAAA,GAAY,aAAa,EAAC;AAAA,EACnC;AAAA,EAEA,YAAA,GAAmC;AAC/B,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,CAAK,SAAS,CAAA;AAAA,EACzC;AACJ;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;AAGA,EAAA,WAAA,CAAY,SAAA,CAAU,WAAW,MAAM;AAAA,EAAC,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,gBAAA,GAAmB,MAAM,MAAM,EAAC;AAC1D;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\nimport { 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 * 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}\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 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, 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// eslint-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 return new LayerFactoryImpl({\n intl: {} satisfies Partial<PackageIntl> as PackageIntl,\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 // Needed by tests in editing package\n VectorLayer.prototype.setStyle = () => {};\n VectorLayer.prototype.getStyleFunction = () => () => [];\n}\n\nmockVectorLayer();\n"],"names":["LayerFactoryImpl","MapRegistryImpl"],"mappings":";;;;;;;;AAoFA,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;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,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,OAAO,IAAID,YAAA,CAAiB;AAAA,IACxB,MAAM,EAAC;AAAA,IACP,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;AAGA,EAAA,WAAA,CAAY,SAAA,CAAU,WAAW,MAAM;AAAA,EAAC,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,gBAAA,GAAmB,MAAM,MAAM,EAAC;AAC1D;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": "0.12.0-dev.20250905090001",
4
+ "version": "1.0.0-dev.20251020091932",
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": "^4.0.0",
17
+ "@open-pioneer/test-utils": "4.2.0-dev.20251017113502",
18
18
  "@testing-library/react": "^16.3.0",
19
19
  "ol": "^10.6.1",
20
- "@conterra/reactivity-core": "^0.7.0",
21
- "@open-pioneer/map": "0.12.0-dev.20250905090001"
20
+ "@conterra/reactivity-core": "^0.8.0",
21
+ "@open-pioneer/map": "1.0.0-dev.20251020091932"
22
22
  },
23
23
  "exports": {
24
24
  "./package.json": "./package.json",