@open-pioneer/map-test-utils 0.2.0 → 0.2.2
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 +27 -11
- package/index.d.ts +2 -2
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
# @open-pioneer/map-test-utils
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [611ddb9]
|
|
8
|
+
- @open-pioneer/map@0.3.1
|
|
9
|
+
|
|
10
|
+
## 0.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [ee7c2d4]
|
|
15
|
+
- Updated dependencies [a582e5e]
|
|
16
|
+
- Updated dependencies [0456500]
|
|
17
|
+
- @open-pioneer/map@0.3.0
|
|
18
|
+
|
|
3
19
|
## 0.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
6
22
|
|
|
7
|
-
-
|
|
23
|
+
- 70349a8: Update to new core packages major versions
|
|
8
24
|
|
|
9
25
|
### Patch Changes
|
|
10
26
|
|
|
11
|
-
-
|
|
12
|
-
|
|
27
|
+
- Updated dependencies [70349a8]
|
|
28
|
+
- @open-pioneer/map@0.2.0
|
|
13
29
|
|
|
14
30
|
## 0.1.1
|
|
15
31
|
|
|
16
32
|
### Patch Changes
|
|
17
33
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
34
|
+
- Updated dependencies [08bffbc]
|
|
35
|
+
- Updated dependencies [a58546b]
|
|
36
|
+
- Updated dependencies [a58546b]
|
|
37
|
+
- Updated dependencies [0c4ce04]
|
|
38
|
+
- @open-pioneer/map@0.1.1
|
|
23
39
|
|
|
24
40
|
## 0.1.0
|
|
25
41
|
|
|
26
42
|
### Minor Changes
|
|
27
43
|
|
|
28
|
-
-
|
|
44
|
+
- 90103b9: Initial release.
|
|
29
45
|
|
|
30
46
|
### Patch Changes
|
|
31
47
|
|
|
32
|
-
-
|
|
33
|
-
|
|
48
|
+
- Updated dependencies [bb2f27a]
|
|
49
|
+
- @open-pioneer/map@0.1.0
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtentConfig, MapModel, MapRegistry, OlMapOptions, SimpleLayerConfig } from "@open-pioneer/map";
|
|
1
|
+
import { ExtentConfig, MapModel, MapRegistry, OlMapOptions, SimpleLayerConfig, Layer } from "@open-pioneer/map";
|
|
2
2
|
import { MapRegistryImpl } from "@open-pioneer/map/services";
|
|
3
3
|
export interface SimpleMapOptions {
|
|
4
4
|
center?: {
|
|
@@ -8,7 +8,7 @@ export interface SimpleMapOptions {
|
|
|
8
8
|
zoom?: number;
|
|
9
9
|
extent?: ExtentConfig;
|
|
10
10
|
projection?: string;
|
|
11
|
-
layers?: SimpleLayerConfig[];
|
|
11
|
+
layers?: (SimpleLayerConfig | Layer)[];
|
|
12
12
|
advanced?: OlMapOptions;
|
|
13
13
|
noInitialView?: boolean;
|
|
14
14
|
noProjection?: boolean;
|
package/index.js
CHANGED
|
@@ -46,7 +46,10 @@ async function setupMap(options) {
|
|
|
46
46
|
const mapConfig = {
|
|
47
47
|
initialView: options?.noInitialView ? void 0 : getInitialView(),
|
|
48
48
|
projection: options?.noProjection ? void 0 : options?.projection ?? "EPSG:3857",
|
|
49
|
-
layers: options?.layers?.map(
|
|
49
|
+
layers: options?.layers?.map(
|
|
50
|
+
(config) => "map" in config ? config : new SimpleLayer(config)
|
|
51
|
+
// using map as discriminator (no prototype for Layer)
|
|
52
|
+
) ?? [
|
|
50
53
|
new SimpleLayer({
|
|
51
54
|
title: "OSM",
|
|
52
55
|
olLayer: new VectorLayer()
|
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\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\";\nimport { HttpService } from \"@open-pioneer/http\";\n\nexport interface SimpleMapOptions {\n center?: { x: number; y: number };\n zoom?: number;\n extent?: ExtentConfig;\n projection?: string;\n layers?: SimpleLayerConfig[];\n advanced?: OlMapOptions;\n\n noInitialView?: boolean;\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((config) => new SimpleLayer(config)) ?? [\n new SimpleLayer({\n title: \"OSM\",\n olLayer: new VectorLayer()\n })\n ],\n advanced: options?.advanced\n };\n\n const httpService: HttpService = {\n async fetch() {\n return new Response(\"mock response from map-test-utils\", {\n status: 200\n });\n }\n };\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"],"names":[],"mappings":";;;;;;
|
|
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,\n Layer\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\";\nimport { HttpService } from \"@open-pioneer/http\";\n\nexport interface SimpleMapOptions {\n center?: { x: number; y: number };\n zoom?: number;\n extent?: ExtentConfig;\n projection?: string;\n layers?: (SimpleLayerConfig | Layer)[];\n advanced?: OlMapOptions;\n\n noInitialView?: boolean;\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: HttpService = {\n async fetch() {\n return new Response(\"mock response from map-test-utils\", {\n status: 200\n });\n }\n };\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"],"names":[],"mappings":";;;;;;AAqCsB,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,eAAsB,qBAAqB,KAAiB,EAAA;AACxD,EAAA,IAAI,MAAM,aAAe,EAAA;AACrB,IAAA,OAAA;AAAA,GACJ;AAEA,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAW,KAAA;AACzC,IAAO,KAAA,EAAA,IAAA,CAAK,yBAAyB,MAAM;AACvC,MAAA,IAAI,OAAO,aAAe,EAAA;AACtB,QAAQ,OAAA,EAAA,C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7B,MAAM,KAAQ,GAAA;AACV,MAAO,OAAA,IAAI,SAAS,mCAAqC,EAAA;AAAA,QACrD,MAAQ,EAAA,GAAA;AAAA,OACX,CAAA,CAAA;AAAA,KACL;AAAA,GACJ,CAAA;AAEA,EAAM,MAAA,QAAA,GAAW,MAAM,aAAA,CAAc,eAAiB,EAAA;AAAA,IAClD,UAAY,EAAA;AAAA,MACR,WAAW,CAAC,IAAI,qBAAsB,CAAA,KAAA,EAAO,SAAS,CAAC,CAAA;AAAA,MACvD,WAAA;AAAA,KACJ;AAAA,GACH,CAAA,CAAA;AAED,EAAO,OAAA,EAAE,OAAO,QAAS,EAAA,CAAA;AAC7B,CAAA;AAQO,SAAS,qBAAqB,QAA8D,EAAA;AAC/F,EAAO,OAAA;AAAA,IACH,mBAAmB,QAAS,CAAA,QAAA;AAAA,GAChC,CAAA;AACJ,CAAA;AAEA,MAAM,qBAAmD,CAAA;AAAA,EACrD,KAAQ,GAAA,SAAA,CAAA;AAAA,EACR,SAAA,CAAA;AAAA,EAEA,WAAA,CAAY,OAAe,SAAmC,EAAA;AAC1D,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AACb,IAAK,IAAA,CAAA,SAAA,GAAY,aAAa,EAAC,CAAA;AAAA,GACnC;AAAA,EAEA,YAAmC,GAAA;AAC/B,IAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,GACzC;AACJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/map-test-utils",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@open-pioneer/test-utils": "^1.0.2",
|
|
8
8
|
"@testing-library/react": "^14.1.2",
|
|
9
9
|
"ol": "^8.2.0",
|
|
10
|
-
"@open-pioneer/map": "^0.
|
|
10
|
+
"@open-pioneer/map": "^0.3.1"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
"./package.json": "./package.json",
|