| 
									
										
										
										
											2023-07-15 18:55:03 +02:00
										 |  |  | import { LayoutConfigJson } from "../../../../src/Models/ThemeConfig/Json/LayoutConfigJson" | 
					
						
							|  |  |  | import { LayerConfigJson } from "../../../../src/Models/ThemeConfig/Json/LayerConfigJson" | 
					
						
							|  |  |  | import { PrepareTheme } from "../../../../src/Models/ThemeConfig/Conversion/PrepareTheme" | 
					
						
							|  |  |  | import LayoutConfig from "../../../../src/Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  | import bookcaseLayer from "../../../../src/assets/generated/layers/public_bookcase.json" | 
					
						
							|  |  |  | import LayerConfig from "../../../../src/Models/ThemeConfig/LayerConfig" | 
					
						
							|  |  |  | import { ExtractImages } from "../../../../src/Models/ThemeConfig/Conversion/FixImages" | 
					
						
							|  |  |  | import cyclofix from "../../../../src/assets/generated/themes/cyclofix.json" | 
					
						
							|  |  |  | import { Tag } from "../../../../src/Logic/Tags/Tag" | 
					
						
							| 
									
										
										
										
											2023-11-02 04:35:32 +01:00
										 |  |  | import { DesugaringContext } from "../../../../src/Models/ThemeConfig/Conversion/Conversion" | 
					
						
							| 
									
										
										
										
											2023-07-15 18:55:03 +02:00
										 |  |  | import { And } from "../../../../src/Logic/Tags/And" | 
					
						
							| 
									
										
										
										
											2023-02-03 04:48:32 +01:00
										 |  |  | import { describe, expect, it } from "vitest" | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  | import { QuestionableTagRenderingConfigJson } from "../../../../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson" | 
					
						
							|  |  |  | import Constants from "../../../../src/Models/Constants" | 
					
						
							| 
									
										
										
										
											2023-11-02 04:35:32 +01:00
										 |  |  | import { ConversionContext } from "../../../../src/Models/ThemeConfig/Conversion/ConversionContext" | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const themeConfigJson: LayoutConfigJson = { | 
					
						
							|  |  |  |     description: "Descr", | 
					
						
							|  |  |  |     icon: "", | 
					
						
							|  |  |  |     layers: [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             builtin: "public_bookcase", | 
					
						
							|  |  |  |             override: { | 
					
						
							|  |  |  |                 source: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     geoJson: "xyz", | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  |     ], | 
					
						
							|  |  |  |     startLat: 0, | 
					
						
							|  |  |  |     startLon: 0, | 
					
						
							|  |  |  |     startZoom: 0, | 
					
						
							|  |  |  |     title: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         en: "Title", | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     id: "test", | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  | function constructSharedLayers(): Map<string, LayerConfigJson> { | 
					
						
							|  |  |  |     const sharedLayers = new Map<string, LayerConfigJson>() | 
					
						
							|  |  |  |     sharedLayers.set("selected_element", <LayerConfigJson>{ | 
					
						
							|  |  |  |         id: "selected_element", | 
					
						
							|  |  |  |         pointRendering: null, | 
					
						
							|  |  |  |         tagRenderings: null, | 
					
						
							|  |  |  |         lineRendering: null, | 
					
						
							|  |  |  |         title: null, | 
					
						
							|  |  |  |         source: "special", | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     for (const defaultLayer of Constants.added_by_default) { | 
					
						
							|  |  |  |         sharedLayers.set(defaultLayer, <LayerConfigJson>{ | 
					
						
							|  |  |  |             id: defaultLayer, | 
					
						
							|  |  |  |             pointRendering: null, | 
					
						
							|  |  |  |             tagRenderings: null, | 
					
						
							|  |  |  |             lineRendering: null, | 
					
						
							|  |  |  |             title: null, | 
					
						
							|  |  |  |             source: "special", | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return sharedLayers | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  | describe("PrepareTheme", () => { | 
					
						
							| 
									
										
										
										
											2022-04-06 03:06:28 +02:00
										 |  |  |     it("should substitute layers", () => { | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         const sharedLayers = constructSharedLayers() | 
					
						
							|  |  |  |         sharedLayers.set("public_bookcase", <any>bookcaseLayer) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const theme = { ...themeConfigJson, layers: ["public_bookcase"] } | 
					
						
							|  |  |  |         const prepareStep = new PrepareTheme({ | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             tagRenderings: new Map<string, QuestionableTagRenderingConfigJson>(), | 
					
						
							|  |  |  |             sharedLayers, | 
					
						
							| 
									
										
										
										
											2023-06-20 10:40:27 +02:00
										 |  |  |             publicLayers: new Set<string>(), | 
					
						
							| 
									
										
										
										
											2022-04-06 03:06:28 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         let themeConfigJsonPrepared = prepareStep.convertStrict(theme, ConversionContext.test()) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const themeConfig = new LayoutConfig(themeConfigJsonPrepared) | 
					
						
							|  |  |  |         const layerUnderTest = <LayerConfig>( | 
					
						
							|  |  |  |             themeConfig.layers.find((l) => l.id === "public_bookcase") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-02-03 04:48:32 +01:00
										 |  |  |         expect(layerUnderTest.source.osmTags).toEqual( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             new And([new Tag("amenity", "public_bookcase")]) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-04-06 03:06:28 +02:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     it("should apply override", () => { | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         const sharedLayers = constructSharedLayers() | 
					
						
							|  |  |  |         sharedLayers.set("public_bookcase", <any>bookcaseLayer) | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  |         let themeConfigJsonPrepared = new PrepareTheme({ | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             tagRenderings: new Map<string, QuestionableTagRenderingConfigJson>(), | 
					
						
							|  |  |  |             sharedLayers, | 
					
						
							| 
									
										
										
										
											2023-06-20 10:40:27 +02:00
										 |  |  |             publicLayers: new Set<string>(), | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         }).convertStrict(themeConfigJson, ConversionContext.test()) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const themeConfig = new LayoutConfig(themeConfigJsonPrepared) | 
					
						
							|  |  |  |         const layerUnderTest = <LayerConfig>( | 
					
						
							|  |  |  |             themeConfig.layers.find((l) => l.id === "public_bookcase") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-02-03 04:48:32 +01:00
										 |  |  |         expect(layerUnderTest.source.geojsonSource).toBe("xyz") | 
					
						
							| 
									
										
										
										
											2022-03-18 13:04:12 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2022-04-06 03:06:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it("should apply override", () => { | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         const sharedLayers = constructSharedLayers() | 
					
						
							|  |  |  |         sharedLayers.set("public_bookcase", <any>bookcaseLayer) | 
					
						
							| 
									
										
										
										
											2022-04-06 03:06:28 +02:00
										 |  |  |         let themeConfigJsonPrepared = new PrepareTheme({ | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             tagRenderings: new Map<string, QuestionableTagRenderingConfigJson>(), | 
					
						
							|  |  |  |             sharedLayers, | 
					
						
							| 
									
										
										
										
											2023-06-20 10:40:27 +02:00
										 |  |  |             publicLayers: new Set<string>(), | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         }).convertStrict( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             { | 
					
						
							|  |  |  |                 ...themeConfigJson, | 
					
						
							|  |  |  |                 overrideAll: { source: { geoJson: "https://example.com/data.geojson" } }, | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             ConversionContext.test() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const themeConfig = new LayoutConfig(themeConfigJsonPrepared) | 
					
						
							|  |  |  |         const layerUnderTest = <LayerConfig>( | 
					
						
							|  |  |  |             themeConfig.layers.find((l) => l.id === "public_bookcase") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-02-03 04:48:32 +01:00
										 |  |  |         expect(layerUnderTest.source.geojsonSource).toBe("https://example.com/data.geojson") | 
					
						
							| 
									
										
										
										
											2022-04-06 03:06:28 +02:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |     it("should remove names which are overriden with null", () => { | 
					
						
							|  |  |  |         const testLayer: LayerConfigJson = { | 
					
						
							|  |  |  |             source: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 osmTags: "x=y", | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             id: "layer-example", | 
					
						
							|  |  |  |             name: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 en: "Test layer - please ignore", | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             titleIcons: [], | 
					
						
							| 
									
										
										
										
											2023-11-23 17:06:30 +01:00
										 |  |  |             pointRendering: [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     location: ["point"], | 
					
						
							|  |  |  |                     label: "xyz", | 
					
						
							|  |  |  |                     iconBadges: [ | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                             if: "_favourite=yes", | 
					
						
							|  |  |  |                             then: <any>{ | 
					
						
							|  |  |  |                                 id: "circlewhiteheartred", | 
					
						
							|  |  |  |                                 render: "circle:white;heart:red", | 
					
						
							|  |  |  |                             }, | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     ], | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             lineRendering: [{ width: 1 }], | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         const sharedLayers = constructSharedLayers() | 
					
						
							|  |  |  |         sharedLayers.set("layer-example", testLayer) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const ctx: DesugaringContext = { | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             sharedLayers, | 
					
						
							|  |  |  |             tagRenderings: new Map<string, QuestionableTagRenderingConfigJson>(), | 
					
						
							| 
									
										
										
										
											2023-06-20 10:40:27 +02:00
										 |  |  |             publicLayers: new Set<string>(), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         const layout: LayoutConfigJson = { | 
					
						
							|  |  |  |             description: "A testing theme", | 
					
						
							|  |  |  |             icon: "", | 
					
						
							|  |  |  |             id: "", | 
					
						
							|  |  |  |             layers: [ | 
					
						
							|  |  |  |                 "layer-example", | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     builtin: "layer-example", | 
					
						
							|  |  |  |                     override: { | 
					
						
							|  |  |  |                         name: null, | 
					
						
							|  |  |  |                         minzoom: 18, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             startLat: 0, | 
					
						
							|  |  |  |             startLon: 0, | 
					
						
							|  |  |  |             startZoom: 0, | 
					
						
							|  |  |  |             title: "Test theme", | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         const rewritten = new PrepareTheme(ctx, { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             skipDefaultLayers: true, | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |         }).convertStrict(layout, ConversionContext.test()) | 
					
						
							| 
									
										
										
										
											2023-02-03 04:48:32 +01:00
										 |  |  |         expect(rewritten.layers[0]).toEqual(testLayer) | 
					
						
							|  |  |  |         expect(rewritten.layers[1]).toEqual({ | 
					
						
							| 
									
										
										
										
											2024-02-20 13:33:38 +01:00
										 |  |  |             _basedOn: "layer-example", | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |             source: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 osmTags: "x=y", | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             id: "layer-example", | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             name: null, | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |             minzoom: 18, | 
					
						
							| 
									
										
										
										
											2023-11-30 00:39:55 +01:00
										 |  |  |             pointRendering: [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     location: ["point"], | 
					
						
							|  |  |  |                     label: "xyz", | 
					
						
							|  |  |  |                     iconBadges: [ | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                             if: "_favourite=yes", | 
					
						
							|  |  |  |                             then: { | 
					
						
							|  |  |  |                                 id: "circlewhiteheartred", | 
					
						
							|  |  |  |                                 render: "circle:white;heart:red", | 
					
						
							|  |  |  |                             }, | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     ], | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |             lineRendering: [{ width: 1 }], | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             titleIcons: [], | 
					
						
							| 
									
										
										
										
											2022-04-13 00:31:13 +02:00
										 |  |  |         }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2022-03-21 02:00:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe("ExtractImages", () => { | 
					
						
							|  |  |  |     it("should find all images in a themefile", () => { | 
					
						
							| 
									
										
										
										
											2023-02-09 00:10:59 +01:00
										 |  |  |         const images = new Set<string>( | 
					
						
							|  |  |  |             new ExtractImages(true, new Set<string>()) | 
					
						
							| 
									
										
										
										
											2023-10-12 16:55:26 +02:00
										 |  |  |                 .convertStrict(<any>cyclofix, ConversionContext.test()) | 
					
						
							| 
									
										
										
										
											2023-02-09 00:10:59 +01:00
										 |  |  |                 .map((x) => x.path) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  |         const expectedValues = [ | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/repair_station.svg", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/repair_station_pump.svg", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/broken_pump.svg", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/pump.svg", | 
					
						
							|  |  |  |             "./assets/themes/cyclofix/fietsambassade_gent_logo_small.svg", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/pump_example_manual.jpg", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/pump_example.png", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/pump_example_round.jpg", | 
					
						
							|  |  |  |             "./assets/layers/bike_repair_station/repair_station_example_2.jpg", | 
					
						
							|  |  |  |             "close", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |         for (const expected of expectedValues) { | 
					
						
							| 
									
										
										
										
											2023-02-09 00:10:59 +01:00
										 |  |  |             if (!images.has(expected)) { | 
					
						
							|  |  |  |                 expect.fail( | 
					
						
							|  |  |  |                     "Image " + expected + " not found (has:" + Array.from(images).join(",") + ")" | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-21 02:00:50 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | }) |