mapcomplete/test/CreateNoteImportLayer.spec.ts

34 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-01-14 13:58:15 +01:00
import T from "./TestHelper";
import CreateNoteImportLayer from "../Models/ThemeConfig/Conversion/CreateNoteImportLayer";
import * as bookcases from "../assets/layers/public_bookcase/public_bookcase.json"
import {DesugaringContext} from "../Models/ThemeConfig/Conversion/Conversion";
2022-01-14 13:58:15 +01:00
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
import {PrepareLayer} from "../Models/ThemeConfig/Conversion/PrepareLayer";
2022-01-26 21:28:22 +01:00
import {Utils} from "../Utils";
2022-01-14 13:58:15 +01:00
export default class CreateNoteImportLayerSpec extends T {
constructor() {
super([
["Bookcase", () => {
const desugaringState: DesugaringContext = {
sharedLayers: new Map<string, LayerConfigJson>(),
tagRenderings: new Map<string, TagRenderingConfigJson>()
}
const layerPrepare = new PrepareLayer()
2022-01-26 21:40:38 +01:00
const layer = layerPrepare.convertStrict(desugaringState, bookcases, "ImportLayerGeneratorTest:Parse bookcases")
2022-01-14 13:58:15 +01:00
const generator = new CreateNoteImportLayer()
2022-01-26 21:40:38 +01:00
const generatedLayer: LayerConfigJson = generator.convertStrict(desugaringState, layer, "ImportLayerGeneratorTest: convert")
2022-01-26 21:28:22 +01:00
T.equals("_tags~(^|.*;)amenity=public_bookcase($|;.*)", generatedLayer.isShown.mappings[1].if["and"][1].or[0].and[0])
let renderings = Utils.NoNull(Utils.NoNull(generatedLayer.tagRenderings
2022-01-26 21:40:38 +01:00
.map(tr => (<TagRenderingConfigJson>tr).render))
2022-01-26 21:28:22 +01:00
.map(render => render["en"]))
T.equals(true, renderings.some(r => r.indexOf("import_button") > 0))
2022-01-14 13:58:15 +01:00
}]
]);
}
}