import T from "./TestHelper"; import {FixLegacyTheme} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson"; import {AddMiniMap} from "../Models/ThemeConfig/Conversion/PrepareTheme"; export default class LegacyThemeLoaderSpec extends T { private static readonly 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 {ref}" } } ] }, "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!" } ] } ] }, { "id": "node", "name": { "en": "nodes" }, "source": { "osmTags": "rwn_ref~*" }, "minzoom": 12, "title": { "render": { "en": "walking node {rwn_ref}" } }, "label": { "mappings": [ { "if": "rwn_ref~*", "then": "
{rwn_ref}
" } ] }, "tagRenderings": [ { "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!" } ] }, { "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" ] } ] } constructor() { super([ ["Walking_node_theme", () => { const config = LegacyThemeLoaderSpec.walking_node_theme const fixed = new FixLegacyTheme().convert({ tagRenderings: new Map(), sharedLayers: new Map() }, // @ts-ignore config, "While testing") T.isTrue(fixed.errors.length === 0, "Could not fix the legacy theme") const theme = new LayoutConfig(fixed.result) }], ["Detect minimaps", () => { function shouldHave(config: TagRenderingConfigJson) { T.equals(AddMiniMap.hasMinimap(config), true, "Did _not_ dected a minimap, even though there is one in " + JSON.stringify(config)) } function shouldNot(config: TagRenderingConfigJson) { T.equals(AddMiniMap.hasMinimap(config), false, "Did erronously dected a minimap, even though there is none in " + JSON.stringify(config)) } shouldHave({ render: "{minimap()}" }); shouldHave({ render: {en: "{minimap()}"} }); shouldHave({ render: {en: "{minimap()}", nl: "{minimap()}"} }); shouldHave({ render: {en: "{minimap()}", nl: "No map for the dutch!"} }); shouldHave({ render: "{minimap()}" }) shouldHave({ render: "{minimap(18,featurelist)}" }) shouldHave({ mappings: [ { if: "xyz=abc", then: "{minimap(18,featurelist)}" } ] }) shouldNot({ render: "Some random value {key}" }) shouldNot({ render: "Some random value {minimap}" }) } ] ] ); } }