From e2b30321983a81aad032270c8c2d7804f9865100 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 17 May 2023 13:22:13 +0200 Subject: [PATCH] Tests: tweak validation to be runnable in the tests --- Models/ThemeConfig/Conversion/Conversion.ts | 3 +++ Models/ThemeConfig/Conversion/PrepareLayer.ts | 11 +++++++++- .../ThemeConfig/Conversion/ValidationUtils.ts | 22 +++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Models/ThemeConfig/Conversion/Conversion.ts b/Models/ThemeConfig/Conversion/Conversion.ts index d2a8184e6..66a4135b4 100644 --- a/Models/ThemeConfig/Conversion/Conversion.ts +++ b/Models/ThemeConfig/Conversion/Conversion.ts @@ -297,6 +297,9 @@ export class Fuse extends DesugaringStep { const step = this.steps[i] try { let r = step.convert(json, "While running step " + step.name + ": " + context) + if(r.result["tagRenderings"]?.some(tr => tr === undefined)){ + throw step.name+" introduced an undefined tagRendering" + } errors.push(...(r.errors ?? [])) warnings.push(...(r.warnings ?? [])) information.push(...(r.information ?? [])) diff --git a/Models/ThemeConfig/Conversion/PrepareLayer.ts b/Models/ThemeConfig/Conversion/PrepareLayer.ts index 0d3aaca2c..4e358cf74 100644 --- a/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -593,6 +593,7 @@ export class AddEditingElements extends DesugaringStep { if ( json.tagRenderings && + this._desugaring.tagRenderings.has("just_created") && !json.tagRenderings.some((tr) => tr === "just_created" || tr["id"] === "just_created") ) { json.tagRenderings.unshift(this._desugaring.tagRenderings.get("just_created")) @@ -623,6 +624,7 @@ export class AddEditingElements extends DesugaringStep { json.source !== "special" && json.source !== "special:library" && json.tagRenderings && + this._desugaring.tagRenderings.has("last_edit") && !json.tagRenderings.some((tr) => tr["id"] === "last_edit") ) { json.tagRenderings.push(this._desugaring.tagRenderings.get("last_edit")) @@ -1161,7 +1163,14 @@ export class AddMiniMap extends DesugaringStep { if (!hasMinimap) { layerConfig = { ...layerConfig } layerConfig.tagRenderings = [...layerConfig.tagRenderings] - layerConfig.tagRenderings.push(state.tagRenderings.get("minimap")) + const minimap = state.tagRenderings.get("minimap") + if(minimap === undefined){ + if(state.tagRenderings.size > 0){ + throw "The 'minimap'-builtin tagrendering is not defined. As such, it cannot be added automatically" + } + }else{ + layerConfig.tagRenderings.push() + } } return { diff --git a/Models/ThemeConfig/Conversion/ValidationUtils.ts b/Models/ThemeConfig/Conversion/ValidationUtils.ts index 43cd75c82..248a3a577 100644 --- a/Models/ThemeConfig/Conversion/ValidationUtils.ts +++ b/Models/ThemeConfig/Conversion/ValidationUtils.ts @@ -1,8 +1,8 @@ -import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson" -import { Utils } from "../../../Utils" +import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson" +import {Utils} from "../../../Utils" import SpecialVisualizations from "../../../UI/SpecialVisualizations" -import { RenderingSpecification, SpecialVisualization } from "../../../UI/SpecialVisualization" -import { LayerConfigJson } from "../Json/LayerConfigJson" +import {RenderingSpecification, SpecialVisualization} from "../../../UI/SpecialVisualization" +import {LayerConfigJson} from "../Json/LayerConfigJson" export default class ValidationUtils { public static hasSpecialVisualisation( @@ -10,10 +10,14 @@ export default class ValidationUtils { specialVisualisation: string ): boolean { return ( - layer.tagRenderings?.some((tagRendering) => - ValidationUtils.getSpecialVisualisations(tagRendering).some( - (vis) => vis.funcName === specialVisualisation - ) + layer.tagRenderings?.some((tagRendering) => { + if(tagRendering === undefined){ + return false + } + + const spec = ValidationUtils.getSpecialVisualisations(tagRendering) + return spec.some((vis) => vis.funcName === specialVisualisation); + } ) ?? false ) } @@ -40,7 +44,7 @@ export default class ValidationUtils { const all: RenderingSpecification[] = [] for (let translation of translations) { if (typeof translation == "string") { - translation = { "*": translation } + translation = {"*": translation} } for (const key in translation) {