From 3de8c9eb81afb455cc712817a8a570c27e14473e Mon Sep 17 00:00:00 2001 From: Mathias Boeck Date: Fri, 15 Mar 2024 12:50:01 +0100 Subject: [PATCH] test: add test for updateLayers with updateStyleLayerProperties --- .../src/lib/maplibre-layers.helpers.spec.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/projects/map-maplibre/src/lib/maplibre-layers.helpers.spec.ts b/projects/map-maplibre/src/lib/maplibre-layers.helpers.spec.ts index 382630ed..58333d03 100644 --- a/projects/map-maplibre/src/lib/maplibre-layers.helpers.spec.ts +++ b/projects/map-maplibre/src/lib/maplibre-layers.helpers.spec.ts @@ -384,5 +384,27 @@ describe('MaplibreLayerHelpers - use mapservice', () => { }); }); + it('should update as StyleLayer', () => { + const filtertype = 'Layers'; + const waterId = 'water'; + const waterIdStyledObj = `${waterId}:${ukisCustom.id}`; + service.setUkisLayers([ukisCustom], filtertype, map); + const layerBeforUpdate = service.getLayersForId(ukisCustom.id, filtertype, map).styleLayers + const waterLayerBefor = layerBeforUpdate.find(l => l.id === waterIdStyledObj); + + ukisCustom.visible = true; + const paintProp = 'fill-color' + const newColor = 'hsl(200, 100%, 30%)'; + // TODO: service.setUkisLayers changes the id on the original object???? + const waterLayer = ukisCustom.custom_layer.layers.find(l => l.id === waterId); + waterLayer.paint[paintProp] = newColor; + updateStyleLayerProperties(map, waterLayerBefor as TypedStyleLayer, ukisCustom) + + const layerAfterUpdate = service.getLayersForId(ukisCustom.id, filtertype, map).styleLayers; + const waterLayerAfter = layerAfterUpdate.find(l => l.id === waterIdStyledObj); + + expect(waterLayerAfter.visibility).toBe("visible"); + expect(waterLayerAfter.getPaintProperty(paintProp)).toBe(newColor); + }); }); \ No newline at end of file