More test refactoring

This commit is contained in:
Pieter Vander Vennet 2022-03-24 03:11:52 +01:00
parent 9617dbc34d
commit 712806c682
5 changed files with 5063 additions and 66 deletions

View file

@ -29,6 +29,44 @@ export class ExtractImages extends Conversion<LayoutConfigJson, string[]> {
} }
/** /**
* const images = new ExtractImages(true, new Map<string, any>()).convert(<any>{
* "layers": [
* {
* tagRenderings: [
* {
* "mappings": [
* {
* "if": "bicycle_parking=stands",
* "then": {
* "en": "Staple racks",
* },
* "icon": {
* path: "./assets/layers/bike_parking/staple.svg",
* class: "small"
* }
* },
* {
* "if": "bicycle_parking=stands",
* "then": {
* "en": "Bollard",
* },
* "icon": "./assets/layers/bike_parking/bollard.svg",
* }
* ]
* }
* ]
* }
* ]
* }, "test").result;
* images.length // => 2
* images.findIndex(img => img == "./assets/layers/bike_parking/staple.svg") // => 0
* images.findIndex(img => img == "./assets/layers/bike_parking/bollard.svg") // => 1
*
* // should not pickup rotation, should drop color
* const images = new ExtractImages(true, new Map<string, any>()).convert(<any>{"layers": [{mapRendering: [{"location": ["point", "centroid"],"icon": "pin:black",rotation: 180,iconSize: "40,40,center"}]}]
* }, "test").result
* images.length // => 1
* images[0] // => "pin"
* *
*/ */
convert(json: LayoutConfigJson, context: string): { result: string[], errors: string[], warnings: string[] } { convert(json: LayoutConfigJson, context: string): { result: string[], errors: string[], warnings: string[] } {

View file

@ -366,6 +366,8 @@ class ExpandRewriteWithFlatten<T> extends Conversion<T | RewritableConfigJson<T
} }
export class PrepareLayer extends Fuse<LayerConfigJson> { export class PrepareLayer extends Fuse<LayerConfigJson> {
constructor(state: DesugaringContext) { constructor(state: DesugaringContext) {
super( super(
"Fully prepares and expands a layer for the LayerConfig.", "Fully prepares and expands a layer for the LayerConfig.",

File diff suppressed because it is too large Load diff

20
package-lock.json generated
View file

@ -4414,13 +4414,19 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001259", "version": "1.0.30001319",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001259.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001319.tgz",
"integrity": "sha512-V7mQTFhjITxuk9zBpI6nYsiTXhcPe05l+364nZjK7MFK/E7ibvYBSAXr4YcA6oPR8j3ZLM/LN+lUqUVAQEUZFg==", "integrity": "sha512-xjlIAFHucBRSMUo1kb5D4LYgcN1M45qdKP++lhqowDpwJwGkpIRTt5qQqnhxjj1vHcI7nrJxWhCC1ATrCEBTcw==",
"funding": { "funding": [
{
"type": "opencollective", "type": "opencollective",
"url": "https://opencollective.com/browserslist" "url": "https://opencollective.com/browserslist"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
} }
]
}, },
"node_modules/canvg": { "node_modules/canvg": {
"version": "3.0.7", "version": "3.0.7",
@ -20424,9 +20430,9 @@
} }
}, },
"caniuse-lite": { "caniuse-lite": {
"version": "1.0.30001259", "version": "1.0.30001319",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001259.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001319.tgz",
"integrity": "sha512-V7mQTFhjITxuk9zBpI6nYsiTXhcPe05l+364nZjK7MFK/E7ibvYBSAXr4YcA6oPR8j3ZLM/LN+lUqUVAQEUZFg==" "integrity": "sha512-xjlIAFHucBRSMUo1kb5D4LYgcN1M45qdKP++lhqowDpwJwGkpIRTt5qQqnhxjj1vHcI7nrJxWhCC1ATrCEBTcw=="
}, },
"canvg": { "canvg": {
"version": "3.0.7", "version": "3.0.7",

View file

@ -9,67 +9,85 @@ import * as bookcaseLayer from "../../../../assets/generated/layers/public_bookc
import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig"; import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig";
import {ExtractImages} from "../../../../Models/ThemeConfig/Conversion/FixImages"; import {ExtractImages} from "../../../../Models/ThemeConfig/Conversion/FixImages";
import * as cyclofix from "../../../../assets/generated/themes/cyclofix.json" import * as cyclofix from "../../../../assets/generated/themes/cyclofix.json"
import LineRenderingConfigJson from "../../../../Models/ThemeConfig/Json/LineRenderingConfigJson";
import {PrepareLayer} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer";
const themeConfigJson: LayoutConfigJson = {
description: "Descr", describe("PrepareLayer", () => {
icon: "",
layers: [ it("should expand mappings in map renderings", () => {
{ const exampleLayer: LayerConfigJson = {
builtin: "public_bookcase", id: "testlayer",
override: {
source: { source: {
geoJson: "xyz" osmTags: "key=value"
}
}
}
],
maintainer: "",
startLat: 0,
startLon: 0,
startZoom: 0,
title: {
en: "Title"
}, },
version: "", mapRendering: [
id: "test" {
} "rewrite": {
sourceString: ["left|right", "lr_offset"],
describe("PrepareTheme", () => { into: [
["left", "right"],
it("should apply overrideAll", () => { [-6, +6]
]
const sharedLayers = new Map<string, LayerConfigJson>() },
sharedLayers.set("public_bookcase", bookcaseLayer["default"]) renderings: <LineRenderingConfigJson>{
let themeConfigJsonPrepared = new PrepareTheme({ "color": {
tagRenderings: new Map<string, TagRenderingConfigJson>(), "render": "#888",
sharedLayers: sharedLayers "mappings": [
}).convert( themeConfigJson, "test").result {
const themeConfig = new LayoutConfig(themeConfigJsonPrepared); "if": "parking:condition:left|right=free",
const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase") "then": "#299921"
expect(layerUnderTest.source.geojsonSource).eq("xyz") },
{
}) "if": "parking:condition:left|right=disc",
}) "then": "#219991"
describe("ExtractImages", () => {
it("should find all images in a themefile", () => {
const images = new Set(new ExtractImages(true, new Map<string, any>()).convertStrict(<any> cyclofix, "test"))
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) {
expect(images).contains(expected)
} }
]
},
"offset": "lr_offset"
}
}
]
}
const prep = new PrepareLayer({
tagRenderings: new Map<string, TagRenderingConfigJson>(),
sharedLayers: new Map<string, LayerConfigJson>()
}) })
const result = prep.convertStrict(exampleLayer, "test")
const expected = {
"id": "testlayer",
"source": {"osmTags": "key=value"},
"mapRendering": [{
"color": {
"render": "#888",
"mappings": [{
"if": "parking:condition:left=free",
"then": "#299921"
},
{"if": "parking:condition:left=disc",
"then": "#219991"}]
},
"offset": -6
}, {
"color": {
"render": "#888",
"mappings": [{
"if": "parking:condition:right=free",
"then": "#299921"
},
{"if": "parking:condition:right=disc",
"then": "#219991"}]
},
"offset": 6
}],
"titleIcons": [{"render": "defaults", "id": "defaults"}]
}
expect(result).deep.eq(expected)
}
)
}) })