diff --git a/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts b/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts index df9408a8e..f256fcfd3 100644 --- a/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts +++ b/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts @@ -10,6 +10,7 @@ import {LayerConfigJson} from "../Json/LayerConfigJson"; import Constants from "../../Constants"; import {AllKnownLayouts} from "../../../Customizations/AllKnownLayouts"; import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation"; +import Translations from "../../../UI/i18n/Translations"; export interface DesugaringContext { tagRenderings: Map @@ -154,7 +155,7 @@ class Fuse extends DesugaringStep { } -class AddMiniMap extends DesugaringStep { +export class AddMiniMap extends DesugaringStep { constructor() { super("Adds a default 'minimap'-element to the tagrenderings if none of the elements define such a minimap", ["tagRenderings"]); } @@ -163,8 +164,10 @@ class AddMiniMap extends DesugaringStep { * Returns true if this tag rendering has a minimap in some language. * Note: this minimap can be hidden by conditions */ - private static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean { - const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]); + public static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean { + const translations: any[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]) + .map(Translations.T); + for (const translation of translations) { for (const key in translation.translations) { if (!translation.translations.hasOwnProperty(key)) { diff --git a/test/LegacyThemeLoader.spec.ts b/test/LegacyThemeLoader.spec.ts index f29e9c6e1..b53826622 100644 --- a/test/LegacyThemeLoader.spec.ts +++ b/test/LegacyThemeLoader.spec.ts @@ -1,5 +1,5 @@ import T from "./TestHelper"; -import {FixLegacyTheme} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert"; +import {AddMiniMap, 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"; @@ -146,14 +146,62 @@ export default class LegacyThemeLoaderSpec extends T { ["Walking_node_theme", () => { const config = LegacyThemeLoaderSpec.walking_node_theme - const fixed = new FixLegacyTheme().convert({tagRenderings: new Map(), sharedLayers: new Map()}, + 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}" + }) + + } + ] ] ); }