Full code cleanup

This commit is contained in:
Pieter Vander Vennet 2022-01-26 21:40:38 +01:00
parent 3a4a2a2016
commit fa971ffbbf
300 changed files with 16352 additions and 19284 deletions

View file

@ -53,7 +53,7 @@ export default class ActorsSpec extends T {
[
"download latest version",
() => {
const state = new UserRelatedState(new LayoutConfig(bookcaseJson, true, "tests" ))
const state = new UserRelatedState(new LayoutConfig(bookcaseJson, true, "tests"))
const feature = {
"type": "Feature",
"id": "node/5568693115",

View file

@ -4,9 +4,7 @@ import * as bookcases from "../assets/layers/public_bookcase/public_bookcase.jso
import {DesugaringContext} from "../Models/ThemeConfig/Conversion/Conversion";
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
import {PrepareLayer} from "../Models/ThemeConfig/Conversion/PrepareLayer";
import TagRenderingConfigJsonJSC from "../Docs/Schemas/TagRenderingConfigJsonJSC";
import {Utils} from "../Utils";
export default class CreateNoteImportLayerSpec extends T {
@ -20,12 +18,12 @@ export default class CreateNoteImportLayerSpec extends T {
}
const layerPrepare = new PrepareLayer()
const layer =layerPrepare.convertStrict(desugaringState, bookcases, "ImportLayerGeneratorTest:Parse bookcases")
const layer = layerPrepare.convertStrict(desugaringState, bookcases, "ImportLayerGeneratorTest:Parse bookcases")
const generator = new CreateNoteImportLayer()
const generatedLayer : LayerConfigJson = generator.convertStrict(desugaringState, layer, "ImportLayerGeneratorTest: convert")
const generatedLayer: LayerConfigJson = generator.convertStrict(desugaringState, layer, "ImportLayerGeneratorTest: convert")
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
.map(tr => (<TagRenderingConfigJson> tr).render))
.map(tr => (<TagRenderingConfigJson>tr).render))
.map(render => render["en"]))
T.equals(true, renderings.some(r => r.indexOf("import_button") > 0))
}]

View file

@ -355,7 +355,7 @@ export default class GeoOperationsSpec extends T {
Assert.notEqual(p0, null)
const p1 = turf.polygon(polyHouse.geometry.coordinates)
Assert.notEqual(p1, null)
const overlaps = GeoOperations.calculateOverlap(polyGrb, [polyHouse])
Assert.equal(overlaps.length, 0)
const overlapsRev = GeoOperations.calculateOverlap(polyHouse, [polyGrb])
@ -364,50 +364,52 @@ export default class GeoOperationsSpec extends T {
}],
["Overnode removal test", () => {
const feature = { "geometry": {
"type": "Polygon",
const feature = {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
4.477944199999975,
51.02783550000022
],
[
4.477987899999996,
51.027818800000034
],
[
4.478004500000021,
51.02783399999988
],
[
4.478025499999962,
51.02782489999994
],
[
4.478079099999993,
51.027873899999896
],
[
4.47801040000006,
51.027903799999955
],
[
4.477964799999972,
51.02785709999982
],
[
4.477964699999964,
51.02785690000006
],
[
4.477944199999975,
51.02783550000022
[
4.477944199999975,
51.02783550000022
],
[
4.477987899999996,
51.027818800000034
],
[
4.478004500000021,
51.02783399999988
],
[
4.478025499999962,
51.02782489999994
],
[
4.478079099999993,
51.027873899999896
],
[
4.47801040000006,
51.027903799999955
],
[
4.477964799999972,
51.02785709999982
],
[
4.477964699999964,
51.02785690000006
],
[
4.477944199999975,
51.02783550000022
]
]
]
]
}}
}
}
const copy = GeoOperations.removeOvernoding(feature)
Assert.equal(copy.geometry.coordinates[0].length, 7)
T.listIdentical([

View file

@ -7,38 +7,38 @@ import LayerConfig from "../Models/ThemeConfig/LayerConfig";
export default class ImageAttributionSpec extends T {
constructor() {
super([
[
"Should find all the images",
() => {
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',
'./assets/layers/bike_repair_station/broken_pump_2.svg',
'./assets/layers/bike_repair_station/pump.svg',
'./assets/themes/cyclofix/fietsambassade_gent_logo_small.svg',
'./assets/layers/bike_repair_station/pump_example_manual.jpg',
'./assets/layers/bike_repair_station/pump_example.png',
'./assets/layers/bike_repair_station/pump_example_round.jpg',
'./assets/layers/bike_repair_station/repair_station_example.jpg']
for (const expected of expectedValues) {
T.isTrue(images.has(expected), expected + " not found")
}
[
"Should find all the images",
() => {
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',
'./assets/layers/bike_repair_station/broken_pump_2.svg',
'./assets/layers/bike_repair_station/pump.svg',
'./assets/themes/cyclofix/fietsambassade_gent_logo_small.svg',
'./assets/layers/bike_repair_station/pump_example_manual.jpg',
'./assets/layers/bike_repair_station/pump_example.png',
'./assets/layers/bike_repair_station/pump_example_round.jpg',
'./assets/layers/bike_repair_station/repair_station_example.jpg']
for (const expected of expectedValues) {
T.isTrue(images.has(expected), expected + " not found")
}
],
[
"Test image discovery regex",
() => {
const tr = new Translation({en: "XYZ <img src='a.svg'/> XYZ <img src=\"some image.svg\"></img> XYZ <img src=b.svg/>"})
const images = new Set<string>(tr.ExtractImages(false));
equal(3, images.size)
T.isTrue(images.has("a.svg"), "a.svg not found")
T.isTrue(images.has("b.svg"), "b.svg not found")
T.isTrue(images.has("some image.svg"), "some image.svg not found")
}
],
[
"Test image discovery regex",
() => {
const tr = new Translation({en: "XYZ <img src='a.svg'/> XYZ <img src=\"some image.svg\"></img> XYZ <img src=b.svg/>"})
const images = new Set<string>(tr.ExtractImages(false));
equal(3, images.size)
T.isTrue(images.has("a.svg"), "a.svg not found")
T.isTrue(images.has("b.svg"), "b.svg not found")
T.isTrue(images.has("some image.svg"), "some image.svg not found")
}
]
}
]
]);
]);
}
}

View file

@ -169,17 +169,17 @@ export default class LegacyThemeLoaderSpec extends T {
shouldHave({
render: "{minimap()}"
});
shouldHave({
render: {en:"{minimap()}"}
});
shouldHave({
render: {en:"{minimap()}",nl:"{minimap()}"}
render: {en: "{minimap()}"}
});
shouldHave({
render: {en:"{minimap()}",nl:"No map for the dutch!"}
render: {en: "{minimap()}", nl: "{minimap()}"}
});
shouldHave({
render: {en: "{minimap()}", nl: "No map for the dutch!"}
});
shouldHave({
render: "{minimap()}"
})

View file

@ -3,7 +3,7 @@ import {OsmObject} from "../Logic/Osm/OsmObject";
export default class OsmObjectSpec extends T {
constructor() {
super( [
super([
[
"Download referencing ways",
() => {

View file

@ -548,7 +548,7 @@ export default class RelationSplitHandlerSpec extends T {
)
super( [
super([
["split 295132739",
async () => {
// Lets mimick a split action of https://www.openstreetmap.org/way/295132739

File diff suppressed because one or more lines are too long

View file

@ -13,7 +13,7 @@ import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
export default class TagSpec extends T {
constructor() {
super( [
super([
["Tag replacement works in translation", () => {
const tr = new Translation({
"en": "Test {key} abc"
@ -523,13 +523,13 @@ export default class TagSpec extends T {
T.isTrue(filter.matchesProperties(properties), "Lazy value not matched")
}
],
["test date comparison",() => {
const filter = TagUtils.Tag("date_created<2022-01-07")
T.isFalse(filter.matchesProperties({"date_created":"2022-01-08"}), "Date comparison: expected a match")
T.isTrue(filter.matchesProperties({"date_created":"2022-01-01"}), "Date comparison: didn't expect a match")
["test date comparison", () => {
}]]);
const filter = TagUtils.Tag("date_created<2022-01-07")
T.isFalse(filter.matchesProperties({"date_created": "2022-01-08"}), "Date comparison: expected a match")
T.isTrue(filter.matchesProperties({"date_created": "2022-01-01"}), "Date comparison: didn't expect a match")
}]]);
}
}

View file

@ -22,7 +22,7 @@ import CreateNoteImportLayerSpec from "./CreateNoteImportLayer.spec";
async function main() {
ScriptUtils.fixUtils()
const allTests : T[] = [
const allTests: T[] = [
new OsmObjectSpec(),
new TagSpec(),
new ImageAttributionSpec(),
@ -58,9 +58,9 @@ async function main() {
let testsToRun = allTests
if (args.length > 0) {
args = args.map(a => a.toLowerCase()).map(a => {
if(!a.endsWith("spec")){
if (!a.endsWith("spec")) {
return a + "spec"
}else{
} else {
return a;
}
})
@ -76,7 +76,7 @@ async function main() {
for (let i = 0; i < testsToRun.length; i++) {
const test = testsToRun[i];
console.log(" Running test", i, "/", testsToRun.length, test.name)
allFailures.push(...(await test.Run() ?? []))
console.log("OK!")
}

View file

@ -45,9 +45,9 @@ export default class T {
throw `ListIdentical failed: expected a list of length ${expected.length} but got a list of length ${actual.length}`
}
for (let i = 0; i < expected.length; i++) {
if(expected[i] !== undefined && expected[i]["length"] !== undefined ){
T.listIdentical(<any> expected[i], <any> actual[i])
}else if (expected[i] !== actual[i]) {
if (expected[i] !== undefined && expected[i]["length"] !== undefined) {
T.listIdentical(<any>expected[i], <any>actual[i])
} else if (expected[i] !== actual[i]) {
throw `ListIdentical failed at index ${i}: expected ${expected[i]} but got ${actual[i]}`
}
}

View file

@ -10,46 +10,46 @@ import {PrepareTheme} from "../Models/ThemeConfig/Conversion/PrepareTheme";
export default class ThemeSpec extends T {
constructor() {
super( [
["Nested overrides work", () => {
super([
["Nested overrides work", () => {
let themeConfigJson: LayoutConfigJson = {
description: "Descr",
icon: "",
language: ["en"],
layers: [
{
builtin: "public_bookcase",
override: {
source: {
geoJson: "xyz"
}
let themeConfigJson: LayoutConfigJson = {
description: "Descr",
icon: "",
language: ["en"],
layers: [
{
builtin: "public_bookcase",
override: {
source: {
geoJson: "xyz"
}
}
],
maintainer: "",
startLat: 0,
startLon: 0,
startZoom: 0,
title: {
en: "Title"
},
version: "",
id: "test"
}
// TOtal cheat: disable the default layers:
Constants.added_by_default.splice(0, Constants.added_by_default.length)
const sharedLayers = new Map<string, LayerConfigJson>()
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
themeConfigJson = new PrepareTheme().convertStrict({
tagRenderings: new Map<string, TagRenderingConfigJson>(),
sharedLayers: sharedLayers
}, themeConfigJson, "test")
const themeConfig = new LayoutConfig(themeConfigJson);
assert.equal("xyz", themeConfig.layers[0].source.geojsonSource)
}
],
maintainer: "",
startLat: 0,
startLon: 0,
startZoom: 0,
title: {
en: "Title"
},
version: "",
id: "test"
}
// TOtal cheat: disable the default layers:
Constants.added_by_default.splice(0, Constants.added_by_default.length)
const sharedLayers = new Map<string, LayerConfigJson>()
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
themeConfigJson = new PrepareTheme().convertStrict({
tagRenderings: new Map<string, TagRenderingConfigJson>(),
sharedLayers: sharedLayers
}, themeConfigJson, "test")
const themeConfig = new LayoutConfig(themeConfigJson);
assert.equal("xyz", themeConfig.layers[0].source.geojsonSource)
}]
]);
}]
]);
}
}

View file

@ -6,7 +6,7 @@ import {equal} from "assert";
export default class TileFreshnessCalculatorSpec extends T {
constructor() {
super( [
super([
[
"TileFresnessTests",
() => {

View file

@ -6,7 +6,7 @@ import {Denomination} from "../Models/Denomination";
export default class UnitsSpec extends T {
constructor() {
super( [
super([
["Simple canonicalize", () => {
const unit = new Denomination({

View file

@ -39,7 +39,7 @@ export default class UtilsSpec extends T {
}
constructor() {
super( [
super([
["Sort object keys", () => {
const o = {
x: 'x',

File diff suppressed because it is too large Load diff