forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,32 +1,41 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import {Utils} from "../../../../Utils";
|
||||
import {DesugaringContext} from "../../../../Models/ThemeConfig/Conversion/Conversion";
|
||||
import {LayerConfigJson} from "../../../../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import {TagRenderingConfigJson} from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||
import {PrepareLayer} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer";
|
||||
import * as bookcases from "../../../../assets/layers/public_bookcase/public_bookcase.json";
|
||||
import CreateNoteImportLayer from "../../../../Models/ThemeConfig/Conversion/CreateNoteImportLayer";
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { Utils } from "../../../../Utils"
|
||||
import { DesugaringContext } from "../../../../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import { PrepareLayer } from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import * as bookcases from "../../../../assets/layers/public_bookcase/public_bookcase.json"
|
||||
import CreateNoteImportLayer from "../../../../Models/ThemeConfig/Conversion/CreateNoteImportLayer"
|
||||
|
||||
describe("CreateNoteImportLayer", () => {
|
||||
|
||||
it("should generate a layerconfig", () => {
|
||||
const desugaringState: DesugaringContext = {
|
||||
sharedLayers: new Map<string, LayerConfigJson>(),
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>()
|
||||
|
||||
}
|
||||
const layerPrepare = new PrepareLayer(desugaringState)
|
||||
const layer = layerPrepare.convertStrict(bookcases, "ImportLayerGeneratorTest:Parse bookcases")
|
||||
const generator = new CreateNoteImportLayer()
|
||||
const generatedLayer: LayerConfigJson = generator.convertStrict(layer, "ImportLayerGeneratorTest: convert")
|
||||
expect(generatedLayer.isShown["and"][1].or[0].and[0]).deep.equal("_tags~(^|.*;)amenity=public_bookcase($|;.*)")
|
||||
expect(generatedLayer.minzoom <= layer.minzoom, "Zoomlevel is to high").true
|
||||
let renderings = Utils.NoNull(Utils.NoNull(generatedLayer.tagRenderings
|
||||
.map(tr => (<TagRenderingConfigJson>tr).render))
|
||||
.map(render => render["en"]))
|
||||
expect(renderings.some(r => r.indexOf("import_button") > 0), "no import button found").true
|
||||
|
||||
|
||||
})
|
||||
it("should generate a layerconfig", () => {
|
||||
const desugaringState: DesugaringContext = {
|
||||
sharedLayers: new Map<string, LayerConfigJson>(),
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
}
|
||||
const layerPrepare = new PrepareLayer(desugaringState)
|
||||
const layer = layerPrepare.convertStrict(
|
||||
bookcases,
|
||||
"ImportLayerGeneratorTest:Parse bookcases"
|
||||
)
|
||||
const generator = new CreateNoteImportLayer()
|
||||
const generatedLayer: LayerConfigJson = generator.convertStrict(
|
||||
layer,
|
||||
"ImportLayerGeneratorTest: convert"
|
||||
)
|
||||
expect(generatedLayer.isShown["and"][1].or[0].and[0]).deep.equal(
|
||||
"_tags~(^|.*;)amenity=public_bookcase($|;.*)"
|
||||
)
|
||||
expect(generatedLayer.minzoom <= layer.minzoom, "Zoomlevel is to high").true
|
||||
let renderings = Utils.NoNull(
|
||||
Utils.NoNull(
|
||||
generatedLayer.tagRenderings.map((tr) => (<TagRenderingConfigJson>tr).render)
|
||||
).map((render) => render["en"])
|
||||
)
|
||||
expect(
|
||||
renderings.some((r) => r.indexOf("import_button") > 0),
|
||||
"no import button found"
|
||||
).true
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,153 +1,142 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig";
|
||||
import {FixLegacyTheme} from "../../../../Models/ThemeConfig/Conversion/LegacyJsonConvert";
|
||||
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"
|
||||
import { FixLegacyTheme } from "../../../../Models/ThemeConfig/Conversion/LegacyJsonConvert"
|
||||
|
||||
describe("FixLegacyTheme", () => {
|
||||
|
||||
it("should create a working theme config", () => {
|
||||
const walking_node_theme = {
|
||||
"id": "walkingnodenetworks",
|
||||
"title": {
|
||||
"en": "Walking node networks"
|
||||
},
|
||||
"maintainer": "L'imaginaire",
|
||||
"icon": "https://upload.wikimedia.org/wikipedia/commons/3/30/Man_walking_icon_1410105361.svg",
|
||||
"description": {
|
||||
"en": "This map shows walking node networks"
|
||||
},
|
||||
"language": [
|
||||
"en"
|
||||
],
|
||||
socialImage: "img.jpg",
|
||||
"version": "2021-10-02",
|
||||
"startLat": 51.1599,
|
||||
"startLon": 3.34750,
|
||||
"startZoom": 12,
|
||||
"clustering": {
|
||||
"maxZoom": 12
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "node2node",
|
||||
"name": {
|
||||
"en": "node to node links"
|
||||
},
|
||||
"source": {
|
||||
"osmTags": {
|
||||
"and": [
|
||||
"network=rwn",
|
||||
"network:type=node_network"
|
||||
]
|
||||
}
|
||||
},
|
||||
"minzoom": 12,
|
||||
"title": {
|
||||
"render": {
|
||||
"en": "node to node link"
|
||||
},
|
||||
"mappings": [
|
||||
{
|
||||
"if": "ref~*",
|
||||
"then": {
|
||||
"en": "node to node link <strong>{ref}</strong>"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"width": {
|
||||
"render": "4"
|
||||
},
|
||||
"color": {
|
||||
"render": "#8b1e20"
|
||||
},
|
||||
"tagRenderings": [
|
||||
{
|
||||
"question": {
|
||||
"en": "When was this node to node link last surveyed?"
|
||||
},
|
||||
"render": {
|
||||
"en": "This node to node link was last surveyed on {survey:date}"
|
||||
},
|
||||
"freeform": {
|
||||
"key": "survey:date",
|
||||
"type": "date"
|
||||
},
|
||||
"mappings": [
|
||||
{
|
||||
"if": "survey:date:={_now:date}",
|
||||
"then": "Surveyed today!"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
const walking_node_theme = {
|
||||
id: "walkingnodenetworks",
|
||||
title: {
|
||||
en: "Walking node networks",
|
||||
},
|
||||
maintainer: "L'imaginaire",
|
||||
icon: "https://upload.wikimedia.org/wikipedia/commons/3/30/Man_walking_icon_1410105361.svg",
|
||||
description: {
|
||||
en: "This map shows walking node networks",
|
||||
},
|
||||
language: ["en"],
|
||||
socialImage: "img.jpg",
|
||||
version: "2021-10-02",
|
||||
startLat: 51.1599,
|
||||
startLon: 3.3475,
|
||||
startZoom: 12,
|
||||
clustering: {
|
||||
maxZoom: 12,
|
||||
},
|
||||
layers: [
|
||||
{
|
||||
id: "node2node",
|
||||
name: {
|
||||
en: "node to node links",
|
||||
},
|
||||
{
|
||||
"id": "node",
|
||||
"name": {
|
||||
"en": "nodes"
|
||||
source: {
|
||||
osmTags: {
|
||||
and: ["network=rwn", "network:type=node_network"],
|
||||
},
|
||||
"source": {
|
||||
"osmTags": "rwn_ref~*"
|
||||
},
|
||||
minzoom: 12,
|
||||
title: {
|
||||
render: {
|
||||
en: "node to node link",
|
||||
},
|
||||
"minzoom": 12,
|
||||
"title": {
|
||||
"render": {
|
||||
"en": "walking node <strong>{rwn_ref}</strong>"
|
||||
}
|
||||
},
|
||||
"label": {
|
||||
"mappings": [
|
||||
mappings: [
|
||||
{
|
||||
if: "ref~*",
|
||||
then: {
|
||||
en: "node to node link <strong>{ref}</strong>",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
width: {
|
||||
render: "4",
|
||||
},
|
||||
color: {
|
||||
render: "#8b1e20",
|
||||
},
|
||||
tagRenderings: [
|
||||
{
|
||||
question: {
|
||||
en: "When was this node to node link last surveyed?",
|
||||
},
|
||||
render: {
|
||||
en: "This node to node link was last surveyed on {survey:date}",
|
||||
},
|
||||
freeform: {
|
||||
key: "survey:date",
|
||||
type: "date",
|
||||
},
|
||||
mappings: [
|
||||
{
|
||||
"if": "rwn_ref~*",
|
||||
"then": "<div style='position: absolute; top: 10px; right: 10px; color: white; background-color: #8b1e20; width: 20px; height: 20px; border-radius: 100%'>{rwn_ref}</div>"
|
||||
}
|
||||
]
|
||||
if: "survey:date:={_now:date}",
|
||||
then: "Surveyed today!",
|
||||
},
|
||||
],
|
||||
},
|
||||
"tagRenderings": [
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "node",
|
||||
name: {
|
||||
en: "nodes",
|
||||
},
|
||||
source: {
|
||||
osmTags: "rwn_ref~*",
|
||||
},
|
||||
minzoom: 12,
|
||||
title: {
|
||||
render: {
|
||||
en: "walking node <strong>{rwn_ref}</strong>",
|
||||
},
|
||||
},
|
||||
label: {
|
||||
mappings: [
|
||||
{
|
||||
"question": {
|
||||
"en": "When was this walking node last surveyed?"
|
||||
},
|
||||
"render": {
|
||||
"en": "This walking node was last surveyed on {survey:date}"
|
||||
},
|
||||
"freeform": {
|
||||
"key": "survey:date",
|
||||
"type": "date"
|
||||
},
|
||||
"mappings": [
|
||||
{
|
||||
"if": "survey:date:={_now:date}",
|
||||
"then": "Surveyed today!"
|
||||
}
|
||||
]
|
||||
if: "rwn_ref~*",
|
||||
then: "<div style='position: absolute; top: 10px; right: 10px; color: white; background-color: #8b1e20; width: 20px; height: 20px; border-radius: 100%'>{rwn_ref}</div>",
|
||||
},
|
||||
{
|
||||
"question": {
|
||||
"en": "How many other walking nodes does this node link to?"
|
||||
},
|
||||
"render": {
|
||||
"en": "This node links to {expected_rwn_route_relations} other walking nodes."
|
||||
},
|
||||
"freeform": {
|
||||
"key": "expected_rwn_route_relations",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
},
|
||||
tagRenderings: [
|
||||
{
|
||||
question: {
|
||||
en: "When was this walking node last surveyed?",
|
||||
},
|
||||
"images"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
const fixed = new FixLegacyTheme().convert(
|
||||
<any> walking_node_theme,
|
||||
"While testing")
|
||||
expect(fixed.errors, "Could not fix the legacy theme").empty
|
||||
const theme = new LayoutConfig(fixed.result, false)
|
||||
expect(theme).not.undefined
|
||||
|
||||
render: {
|
||||
en: "This walking node was last surveyed on {survey:date}",
|
||||
},
|
||||
freeform: {
|
||||
key: "survey:date",
|
||||
type: "date",
|
||||
},
|
||||
mappings: [
|
||||
{
|
||||
if: "survey:date:={_now:date}",
|
||||
then: "Surveyed today!",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
question: {
|
||||
en: "How many other walking nodes does this node link to?",
|
||||
},
|
||||
render: {
|
||||
en: "This node links to {expected_rwn_route_relations} other walking nodes.",
|
||||
},
|
||||
freeform: {
|
||||
key: "expected_rwn_route_relations",
|
||||
type: "int",
|
||||
},
|
||||
},
|
||||
"images",
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
const fixed = new FixLegacyTheme().convert(<any>walking_node_theme, "While testing")
|
||||
expect(fixed.errors, "Could not fix the legacy theme").empty
|
||||
const theme = new LayoutConfig(fixed.result, false)
|
||||
expect(theme).not.undefined
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import {LayerConfigJson} from "../../../../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import {TagRenderingConfigJson} from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||
import LineRenderingConfigJson from "../../../../Models/ThemeConfig/Json/LineRenderingConfigJson";
|
||||
import {ExpandRewrite, PrepareLayer, RewriteSpecial} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer";
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import LineRenderingConfigJson from "../../../../Models/ThemeConfig/Json/LineRenderingConfigJson"
|
||||
import {
|
||||
QuestionableTagRenderingConfigJson
|
||||
} from "../../../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson";
|
||||
import RewritableConfigJson from "../../../../Models/ThemeConfig/Json/RewritableConfigJson";
|
||||
|
||||
ExpandRewrite,
|
||||
PrepareLayer,
|
||||
RewriteSpecial,
|
||||
} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import { QuestionableTagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||
import RewritableConfigJson from "../../../../Models/ThemeConfig/Json/RewritableConfigJson"
|
||||
|
||||
describe("ExpandRewrite", () => {
|
||||
|
||||
it("should not allow overlapping keys", () => {
|
||||
const spec = <RewritableConfigJson<string>>{
|
||||
rewrite: {
|
||||
sourceString: ["xyz", "longer_xyz"],
|
||||
into: [["a", "b"], ["A, B"]],
|
||||
},
|
||||
renderings: "The value of xyz is longer_xyz"
|
||||
renderings: "The value of xyz is longer_xyz",
|
||||
}
|
||||
const rewrite = new ExpandRewrite()
|
||||
expect(() => rewrite.convert(spec, "test")).to.throw
|
||||
|
@ -26,105 +26,111 @@ describe("ExpandRewrite", () => {
|
|||
})
|
||||
|
||||
describe("PrepareLayer", () => {
|
||||
|
||||
it("should expand rewrites in map renderings", () => {
|
||||
const exampleLayer: LayerConfigJson = {
|
||||
id: "testlayer",
|
||||
source: {
|
||||
osmTags: "key=value"
|
||||
osmTags: "key=value",
|
||||
},
|
||||
mapRendering: [
|
||||
{
|
||||
"rewrite": {
|
||||
rewrite: {
|
||||
sourceString: ["left|right", "lr_offset"],
|
||||
into: [
|
||||
["left", -6],
|
||||
[ "right", +6],
|
||||
]
|
||||
["right", +6],
|
||||
],
|
||||
},
|
||||
renderings: <LineRenderingConfigJson>{
|
||||
"color": {
|
||||
"render": "#888",
|
||||
"mappings": [
|
||||
color: {
|
||||
render: "#888",
|
||||
mappings: [
|
||||
{
|
||||
"if": "parking:condition:left|right=free",
|
||||
"then": "#299921"
|
||||
if: "parking:condition:left|right=free",
|
||||
then: "#299921",
|
||||
},
|
||||
{
|
||||
"if": "parking:condition:left|right=disc",
|
||||
"then": "#219991"
|
||||
}
|
||||
]
|
||||
if: "parking:condition:left|right=disc",
|
||||
then: "#219991",
|
||||
},
|
||||
],
|
||||
},
|
||||
"offset": "lr_offset"
|
||||
}
|
||||
}
|
||||
]
|
||||
offset: "lr_offset",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
const prep = new PrepareLayer({
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
sharedLayers: new Map<string, LayerConfigJson>()
|
||||
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"
|
||||
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",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"if": "parking:condition:left=disc",
|
||||
"then": "#219991"
|
||||
}]
|
||||
offset: -6,
|
||||
},
|
||||
"offset": -6
|
||||
}, {
|
||||
"color": {
|
||||
"render": "#888",
|
||||
"mappings": [{
|
||||
"if": "parking:condition:right=free",
|
||||
"then": "#299921"
|
||||
{
|
||||
color: {
|
||||
render: "#888",
|
||||
mappings: [
|
||||
{
|
||||
if: "parking:condition:right=free",
|
||||
then: "#299921",
|
||||
},
|
||||
{
|
||||
if: "parking:condition:right=disc",
|
||||
then: "#219991",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"if": "parking:condition:right=disc",
|
||||
"then": "#219991"
|
||||
}]
|
||||
offset: 6,
|
||||
},
|
||||
"offset": 6
|
||||
}],
|
||||
"titleIcons": [{"render": "defaults", "id": "defaults"}]
|
||||
],
|
||||
titleIcons: [{ render: "defaults", id: "defaults" }],
|
||||
}
|
||||
|
||||
|
||||
expect(result).deep.eq(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('RewriteSpecial', function () {
|
||||
describe("RewriteSpecial", function () {
|
||||
it("should rewrite the UK import button", () => {
|
||||
const tr = <QuestionableTagRenderingConfigJson>{
|
||||
"id": "uk_addresses_import_button",
|
||||
"render": {
|
||||
"special": {
|
||||
"type": "import_button",
|
||||
"targetLayer": "address",
|
||||
"tags": "urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$",
|
||||
"text": "Add this address",
|
||||
"icon": "./assets/themes/uk_addresses/housenumber_add.svg",
|
||||
"location_picker": "none"
|
||||
}
|
||||
}
|
||||
id: "uk_addresses_import_button",
|
||||
render: {
|
||||
special: {
|
||||
type: "import_button",
|
||||
targetLayer: "address",
|
||||
tags: "urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$",
|
||||
text: "Add this address",
|
||||
icon: "./assets/themes/uk_addresses/housenumber_add.svg",
|
||||
location_picker: "none",
|
||||
},
|
||||
},
|
||||
}
|
||||
const r = new RewriteSpecial().convert(tr, "test").result
|
||||
expect(r).to.deep.eq({
|
||||
"id": "uk_addresses_import_button",
|
||||
"render": {'*': "{import_button(address,urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$,Add this address,./assets/themes/uk_addresses/housenumber_add.svg,,,,none,)}"}
|
||||
id: "uk_addresses_import_button",
|
||||
render: {
|
||||
"*": "{import_button(address,urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$,Add this address,./assets/themes/uk_addresses/housenumber_add.svg,,,,none,)}",
|
||||
},
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
})
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import {LayoutConfigJson} from "../../../../Models/ThemeConfig/Json/LayoutConfigJson";
|
||||
import {LayerConfigJson} from "../../../../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import {PrepareTheme} from "../../../../Models/ThemeConfig/Conversion/PrepareTheme";
|
||||
import {TagRenderingConfigJson} from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig";
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { LayoutConfigJson } from "../../../../Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { PrepareTheme } from "../../../../Models/ThemeConfig/Conversion/PrepareTheme"
|
||||
import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"
|
||||
import * as bookcaseLayer from "../../../../assets/generated/layers/public_bookcase.json"
|
||||
import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig";
|
||||
import {ExtractImages} from "../../../../Models/ThemeConfig/Conversion/FixImages";
|
||||
import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig"
|
||||
import { ExtractImages } from "../../../../Models/ThemeConfig/Conversion/FixImages"
|
||||
import * as cyclofix from "../../../../assets/generated/themes/cyclofix.json"
|
||||
import {Tag} from "../../../../Logic/Tags/Tag";
|
||||
import {DesugaringContext} from "../../../../Models/ThemeConfig/Conversion/Conversion";
|
||||
import {And} from "../../../../Logic/Tags/And";
|
||||
|
||||
import { Tag } from "../../../../Logic/Tags/Tag"
|
||||
import { DesugaringContext } from "../../../../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { And } from "../../../../Logic/Tags/And"
|
||||
|
||||
const themeConfigJson: LayoutConfigJson = {
|
||||
|
||||
description: "Descr",
|
||||
icon: "",
|
||||
layers: [
|
||||
|
@ -23,137 +21,144 @@ const themeConfigJson: LayoutConfigJson = {
|
|||
builtin: "public_bookcase",
|
||||
override: {
|
||||
source: {
|
||||
geoJson: "xyz"
|
||||
}
|
||||
}
|
||||
}
|
||||
geoJson: "xyz",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
startLat: 0,
|
||||
startLon: 0,
|
||||
startZoom: 0,
|
||||
title: {
|
||||
en: "Title"
|
||||
en: "Title",
|
||||
},
|
||||
id: "test"
|
||||
id: "test",
|
||||
}
|
||||
|
||||
describe("PrepareTheme", () => {
|
||||
|
||||
it("should substitute layers", () => {
|
||||
|
||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
|
||||
const theme ={...themeConfigJson, layers: ["public_bookcase"]}
|
||||
const prepareStep = new PrepareTheme({
|
||||
const theme = { ...themeConfigJson, layers: ["public_bookcase"] }
|
||||
const prepareStep = new PrepareTheme({
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
sharedLayers: sharedLayers
|
||||
sharedLayers: sharedLayers,
|
||||
})
|
||||
let themeConfigJsonPrepared = prepareStep.convert(theme, "test").result
|
||||
const themeConfig = new LayoutConfig(themeConfigJsonPrepared);
|
||||
const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase")
|
||||
expect(layerUnderTest.source.osmTags).deep.eq(new And([new Tag("amenity","public_bookcase")]))
|
||||
|
||||
const themeConfig = new LayoutConfig(themeConfigJsonPrepared)
|
||||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.osmTags).deep.eq(
|
||||
new And([new Tag("amenity", "public_bookcase")])
|
||||
)
|
||||
})
|
||||
|
||||
it("should apply override", () => {
|
||||
|
||||
it("should apply override", () => {
|
||||
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")
|
||||
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")
|
||||
|
||||
})
|
||||
|
||||
it("should apply override", () => {
|
||||
|
||||
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, overrideAll: {source: {geoJson: "https://example.com/data.geojson"}}}, "test").result
|
||||
const themeConfig = new LayoutConfig(themeConfigJsonPrepared);
|
||||
const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase")
|
||||
sharedLayers: sharedLayers,
|
||||
}).convert(
|
||||
{
|
||||
...themeConfigJson,
|
||||
overrideAll: { source: { geoJson: "https://example.com/data.geojson" } },
|
||||
},
|
||||
"test"
|
||||
).result
|
||||
const themeConfig = new LayoutConfig(themeConfigJsonPrepared)
|
||||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.geojsonSource).eq("https://example.com/data.geojson")
|
||||
})
|
||||
|
||||
|
||||
it("should remove names which are overriden with null", () => {
|
||||
const testLayer: LayerConfigJson = {
|
||||
source: {
|
||||
osmTags: "x=y"
|
||||
osmTags: "x=y",
|
||||
},
|
||||
id: "layer-example",
|
||||
name: {
|
||||
en: "Test layer - please ignore"
|
||||
en: "Test layer - please ignore",
|
||||
},
|
||||
titleIcons : [],
|
||||
mapRendering: null
|
||||
titleIcons: [],
|
||||
mapRendering: null,
|
||||
}
|
||||
const ctx: DesugaringContext = {
|
||||
sharedLayers: new Map<string, LayerConfigJson>([["layer-example", testLayer]]),
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
}
|
||||
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",
|
||||
}
|
||||
const ctx: DesugaringContext = {
|
||||
sharedLayers: new Map<string, LayerConfigJson>([[
|
||||
"layer-example", testLayer
|
||||
]]),
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>()
|
||||
|
||||
}
|
||||
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",
|
||||
}
|
||||
const rewritten = new PrepareTheme(ctx, {
|
||||
skipDefaultLayers: true
|
||||
skipDefaultLayers: true,
|
||||
}).convertStrict(layout, "test")
|
||||
expect(rewritten.layers[0]).deep.eq(testLayer)
|
||||
expect(rewritten.layers[1]).deep.eq({
|
||||
source: {
|
||||
osmTags: "x=y"
|
||||
osmTags: "x=y",
|
||||
},
|
||||
id: "layer-example",
|
||||
name:null,
|
||||
name: null,
|
||||
minzoom: 18,
|
||||
mapRendering: null,
|
||||
titleIcons: []
|
||||
titleIcons: [],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import SourceConfig from "../../../Models/ThemeConfig/SourceConfig";
|
||||
import {TagUtils} from "../../../Logic/Tags/TagUtils";
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import SourceConfig from "../../../Models/ThemeConfig/SourceConfig"
|
||||
import { TagUtils } from "../../../Logic/Tags/TagUtils"
|
||||
|
||||
describe("SourceConfig", () => {
|
||||
|
||||
it("should throw an error on conflicting tags", () => {
|
||||
expect(() => {
|
||||
new SourceConfig(
|
||||
{
|
||||
osmTags: TagUtils.Tag({
|
||||
and: ["x=y", "a=b", "x!=y"]
|
||||
})
|
||||
}, false
|
||||
and: ["x=y", "a=b", "x!=y"],
|
||||
}),
|
||||
},
|
||||
false
|
||||
)
|
||||
}).to.throw(/tags are conflicting/)
|
||||
})
|
||||
|
|
|
@ -1,71 +1,70 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig";
|
||||
import Locale from "../../../UI/i18n/Locale";
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import Locale from "../../../UI/i18n/Locale"
|
||||
|
||||
describe("TagRenderingConfig", () => {
|
||||
|
||||
describe("isKnown", () => {
|
||||
|
||||
it("should give correct render values", () => {
|
||||
Locale.language.setData("nl");
|
||||
const tr = new TagRenderingConfig({
|
||||
render: ({"en": "Name is {name}", "nl": "Ook een {name}"} as any),
|
||||
question: "Wat is de naam van dit object?",
|
||||
freeform: {
|
||||
key: "name",
|
||||
Locale.language.setData("nl")
|
||||
const tr = new TagRenderingConfig(
|
||||
{
|
||||
render: { en: "Name is {name}", nl: "Ook een {name}" } as any,
|
||||
question: "Wat is de naam van dit object?",
|
||||
freeform: {
|
||||
key: "name",
|
||||
},
|
||||
|
||||
mappings: [
|
||||
{
|
||||
if: "noname=yes",
|
||||
then: "Has no name",
|
||||
},
|
||||
],
|
||||
condition: "x=",
|
||||
},
|
||||
"Tests"
|
||||
)
|
||||
|
||||
mappings: [
|
||||
{
|
||||
if: "noname=yes",
|
||||
"then": "Has no name"
|
||||
}
|
||||
],
|
||||
condition: "x="
|
||||
}, "Tests");
|
||||
|
||||
expect(tr.GetRenderValue({"foo": "bar"})).undefined
|
||||
|
||||
expect (tr.GetRenderValue({"noname": "yes"})?.textFor("nl")).eq("Has no name")
|
||||
expect( tr.GetRenderValue({"name": "xyz"})?.textFor("nl")).eq("Ook een {name}")
|
||||
expect( tr.GetRenderValue({"foo": "bar"})).undefined
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).undefined
|
||||
|
||||
expect(tr.GetRenderValue({ noname: "yes" })?.textFor("nl")).eq("Has no name")
|
||||
expect(tr.GetRenderValue({ name: "xyz" })?.textFor("nl")).eq("Ook een {name}")
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).undefined
|
||||
})
|
||||
|
||||
|
||||
it("should give a correct indication", () => {
|
||||
// tests a regression in parsing
|
||||
const config = {
|
||||
"#": "Bottle refill",
|
||||
"question": {
|
||||
"en": "How easy is it to fill water bottles?",
|
||||
"nl": "Hoe gemakkelijk is het om drinkbussen bij te vullen?",
|
||||
"de": "Wie einfach ist es, Wasserflaschen zu füllen?"
|
||||
question: {
|
||||
en: "How easy is it to fill water bottles?",
|
||||
nl: "Hoe gemakkelijk is het om drinkbussen bij te vullen?",
|
||||
de: "Wie einfach ist es, Wasserflaschen zu füllen?",
|
||||
},
|
||||
"mappings": [
|
||||
mappings: [
|
||||
{
|
||||
"if": "bottle=yes",
|
||||
"then": {
|
||||
"en": "It is easy to refill water bottles",
|
||||
"nl": "Een drinkbus bijvullen gaat makkelijk",
|
||||
"de": "Es ist einfach, Wasserflaschen nachzufüllen"
|
||||
}
|
||||
if: "bottle=yes",
|
||||
then: {
|
||||
en: "It is easy to refill water bottles",
|
||||
nl: "Een drinkbus bijvullen gaat makkelijk",
|
||||
de: "Es ist einfach, Wasserflaschen nachzufüllen",
|
||||
},
|
||||
},
|
||||
{
|
||||
"if": "bottle=no",
|
||||
"then": {
|
||||
"en": "Water bottles may not fit",
|
||||
"nl": "Een drinkbus past moeilijk",
|
||||
"de": "Wasserflaschen passen möglicherweise nicht"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
if: "bottle=no",
|
||||
then: {
|
||||
en: "Water bottles may not fit",
|
||||
nl: "Een drinkbus past moeilijk",
|
||||
de: "Wasserflaschen passen möglicherweise nicht",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const tagRendering = new TagRenderingConfig(config, "test");
|
||||
expect(tagRendering.IsKnown({bottle: "yes"})).true
|
||||
const tagRendering = new TagRenderingConfig(config, "test")
|
||||
expect(tagRendering.IsKnown({ bottle: "yes" })).true
|
||||
expect(tagRendering.IsKnown({})).false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue