From 6af3d418861286136548bf294ebc8166c7ea29c3 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 27 Jun 2021 20:35:38 +0200 Subject: [PATCH] Fix tests --- Customizations/JSON/LayerConfig.ts | 15 +++++++++------ Customizations/SharedTagRenderings.ts | 6 +++++- test/ImageAttribution.spec.ts | 16 ++-------------- test/TestAll.ts | 1 - 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Customizations/JSON/LayerConfig.ts b/Customizations/JSON/LayerConfig.ts index 09edf71af8..142fc2fdef 100644 --- a/Customizations/JSON/LayerConfig.ts +++ b/Customizations/JSON/LayerConfig.ts @@ -15,9 +15,8 @@ import {FixedUiElement} from "../../UI/Base/FixedUiElement"; import SourceConfig from "./SourceConfig"; import {TagsFilter} from "../../Logic/Tags/TagsFilter"; import {Tag} from "../../Logic/Tags/Tag"; -import SubstitutingTag from "../../Logic/Tags/SubstitutingTag"; import BaseUIElement from "../../UI/BaseUIElement"; -import {Denomination, Unit} from "./Denomination"; +import {Unit} from "./Denomination"; export default class LayerConfig { @@ -58,10 +57,10 @@ export default class LayerConfig { tagRenderings: TagRenderingConfig []; constructor(json: LayerConfigJson, - units:Unit[], + units?:Unit[], context?: string, official: boolean = true,) { - this.units = units; + this.units = units ?? []; context = context + "." + json.id; const self = this; this.id = json.id; @@ -167,7 +166,7 @@ export default class LayerConfig { return []; } - return tagRenderings.map( + return Utils.NoNull(tagRenderings.map( (renderingJson, i) => { if (typeof renderingJson === "string") { @@ -187,10 +186,14 @@ export default class LayerConfig { const keys = Array.from(SharedTagRenderings.SharedTagRendering.keys()) + if(Utils.runningFromConsole){ + return undefined; + } + throw `Predefined tagRendering ${renderingJson} not found in ${context}.\n Try one of ${(keys.join(", "))}\n If you intent to output this text literally, use {\"render\": } instead"}`; } return new TagRenderingConfig(renderingJson, self.source.osmTags, `${context}.tagrendering[${i}]`); - }); + })); } this.tagRenderings = trs(json.tagRenderings, false); diff --git a/Customizations/SharedTagRenderings.ts b/Customizations/SharedTagRenderings.ts index 3d3a05208b..a75a65d90b 100644 --- a/Customizations/SharedTagRenderings.ts +++ b/Customizations/SharedTagRenderings.ts @@ -1,6 +1,7 @@ import TagRenderingConfig from "./JSON/TagRenderingConfig"; import * as questions from "../assets/tagRenderings/questions.json"; import * as icons from "../assets/tagRenderings/icons.json"; +import {Utils} from "../Utils"; export default class SharedTagRenderings { @@ -11,8 +12,11 @@ export default class SharedTagRenderings { const dict = new Map(); function add(key, store) { + if(Utils.runningFromConsole){ + return; + } try { - dict.set(key, new TagRenderingConfig(store[key], key)) + dict.set(key, new TagRenderingConfig(store[key], undefined, `SharedTagRenderings.${key}`)) } catch (e) { console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e) } diff --git a/test/ImageAttribution.spec.ts b/test/ImageAttribution.spec.ts index 02d1ebd30a..8a80efa00e 100644 --- a/test/ImageAttribution.spec.ts +++ b/test/ImageAttribution.spec.ts @@ -3,22 +3,10 @@ import {Utils} from "../Utils"; Utils.runningFromConsole = true; import {equal} from "assert"; import T from "./TestHelper"; -import {FromJSON} from "../Customizations/JSON/FromJSON"; -import Locale from "../UI/i18n/Locale"; -import Translations from "../UI/i18n/Translations"; -import {UIEventSource} from "../Logic/UIEventSource"; -import TagRenderingConfig from "../Customizations/JSON/TagRenderingConfig"; -import EditableTagRendering from "../UI/Popup/EditableTagRendering"; import {Translation} from "../UI/i18n/Translation"; -import {OH, OpeningHour} from "../UI/OpeningHours/OpeningHours"; -import PublicHolidayInput from "../UI/OpeningHours/PublicHolidayInput"; -import {SubstitutedTranslation} from "../UI/SubstitutedTranslation"; -import {Tag} from "../Logic/Tags/Tag"; -import {And} from "../Logic/Tags/And"; -import {ImageSearcher} from "../Logic/Actors/ImageSearcher"; -import {AllKnownLayouts} from "../Customizations/AllKnownLayouts"; import AllKnownLayers from "../Customizations/AllKnownLayers"; import LayerConfig from "../Customizations/JSON/LayerConfig"; +import * as bike_repair_station from "../assets/layers/bike_repair_station/bike_repair_station.json" export default class ImageAttributionSpec extends T { constructor() { @@ -27,7 +15,7 @@ export default class ImageAttributionSpec extends T { [ "Should find all the images", () => { - const pumps: LayerConfig = AllKnownLayers.sharedLayers["bike_repair_station"] + const pumps: LayerConfig = new LayerConfig(bike_repair_station ) const images = pumps.ExtractImages(); const expectedValues = ['./assets/layers/bike_repair_station/repair_station.svg', './assets/layers/bike_repair_station/repair_station_pump.svg', diff --git a/test/TestAll.ts b/test/TestAll.ts index f6f5461293..d34d4c5e66 100644 --- a/test/TestAll.ts +++ b/test/TestAll.ts @@ -33,7 +33,6 @@ const allTests = [ new GeoOperationsSpec(), new ImageSearcherSpec(), new ThemeSpec(), - new UtilsSpec(), new UtilsSpec() ]