forked from MapComplete/MapComplete
More test refactoring
This commit is contained in:
parent
9617dbc34d
commit
712806c682
5 changed files with 5063 additions and 66 deletions
|
@ -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[] } {
|
||||
|
|
|
@ -366,6 +366,8 @@ class ExpandRewriteWithFlatten<T> extends Conversion<T | RewritableConfigJson<T
|
|||
}
|
||||
|
||||
export class PrepareLayer extends Fuse<LayerConfigJson> {
|
||||
|
||||
|
||||
constructor(state: DesugaringContext) {
|
||||
super(
|
||||
"Fully prepares and expands a layer for the LayerConfig.",
|
||||
|
|
File diff suppressed because it is too large
Load diff
26
package-lock.json
generated
26
package-lock.json
generated
|
@ -4414,13 +4414,19 @@
|
|||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001259",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001259.tgz",
|
||||
"integrity": "sha512-V7mQTFhjITxuk9zBpI6nYsiTXhcPe05l+364nZjK7MFK/E7ibvYBSAXr4YcA6oPR8j3ZLM/LN+lUqUVAQEUZFg==",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/browserslist"
|
||||
}
|
||||
"version": "1.0.30001319",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001319.tgz",
|
||||
"integrity": "sha512-xjlIAFHucBRSMUo1kb5D4LYgcN1M45qdKP++lhqowDpwJwGkpIRTt5qQqnhxjj1vHcI7nrJxWhCC1ATrCEBTcw==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/browserslist"
|
||||
},
|
||||
{
|
||||
"type": "tidelift",
|
||||
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/canvg": {
|
||||
"version": "3.0.7",
|
||||
|
@ -20424,9 +20430,9 @@
|
|||
}
|
||||
},
|
||||
"caniuse-lite": {
|
||||
"version": "1.0.30001259",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001259.tgz",
|
||||
"integrity": "sha512-V7mQTFhjITxuk9zBpI6nYsiTXhcPe05l+364nZjK7MFK/E7ibvYBSAXr4YcA6oPR8j3ZLM/LN+lUqUVAQEUZFg=="
|
||||
"version": "1.0.30001319",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001319.tgz",
|
||||
"integrity": "sha512-xjlIAFHucBRSMUo1kb5D4LYgcN1M45qdKP++lhqowDpwJwGkpIRTt5qQqnhxjj1vHcI7nrJxWhCC1ATrCEBTcw=="
|
||||
},
|
||||
"canvg": {
|
||||
"version": "3.0.7",
|
||||
|
|
|
@ -9,67 +9,85 @@ import * as bookcaseLayer from "../../../../assets/generated/layers/public_bookc
|
|||
import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig";
|
||||
import {ExtractImages} from "../../../../Models/ThemeConfig/Conversion/FixImages";
|
||||
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 = {
|
||||
|
||||
describe("PrepareLayer", () => {
|
||||
|
||||
description: "Descr",
|
||||
icon: "",
|
||||
layers: [
|
||||
{
|
||||
builtin: "public_bookcase",
|
||||
override: {
|
||||
it("should expand mappings in map renderings", () => {
|
||||
const exampleLayer: LayerConfigJson = {
|
||||
id: "testlayer",
|
||||
source: {
|
||||
geoJson: "xyz"
|
||||
}
|
||||
osmTags: "key=value"
|
||||
},
|
||||
mapRendering: [
|
||||
{
|
||||
"rewrite": {
|
||||
sourceString: ["left|right", "lr_offset"],
|
||||
into: [
|
||||
["left", "right"],
|
||||
[-6, +6]
|
||||
]
|
||||
},
|
||||
renderings: <LineRenderingConfigJson>{
|
||||
"color": {
|
||||
"render": "#888",
|
||||
"mappings": [
|
||||
{
|
||||
"if": "parking:condition:left|right=free",
|
||||
"then": "#299921"
|
||||
},
|
||||
{
|
||||
"if": "parking:condition:left|right=disc",
|
||||
"then": "#219991"
|
||||
}
|
||||
]
|
||||
},
|
||||
"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)
|
||||
}
|
||||
],
|
||||
maintainer: "",
|
||||
startLat: 0,
|
||||
startLon: 0,
|
||||
startZoom: 0,
|
||||
title: {
|
||||
en: "Title"
|
||||
},
|
||||
version: "",
|
||||
id: "test"
|
||||
}
|
||||
|
||||
describe("PrepareTheme", () => {
|
||||
|
||||
it("should apply overrideAll", () => {
|
||||
|
||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
|
||||
let themeConfigJsonPrepared = new PrepareTheme({
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
sharedLayers: sharedLayers
|
||||
}).convert( themeConfigJson, "test").result
|
||||
const themeConfig = new LayoutConfig(themeConfigJsonPrepared);
|
||||
const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase")
|
||||
expect(layerUnderTest.source.geojsonSource).eq("xyz")
|
||||
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue