Fix various bugs

This commit is contained in:
Pieter Vander Vennet 2022-02-22 14:13:41 +01:00
parent 30f4be183e
commit 5284f198d8
26 changed files with 339 additions and 119 deletions

View file

@ -2,34 +2,48 @@ import T from "./TestHelper";
import {exec} from "child_process";
export default class CodeQualitySpec extends T {
constructor() {
super([
[
"no constructor.name in compiled code", () => {
const excludedDirs = [".git", "node_modules", "dist", ".cache", ".parcel-cache", "assets"]
exec("grep \"constructor.name\" -r . " + excludedDirs.map(d => "--exclude-dir=" + d).join(" "), ((error, stdout, stderr) => {
if (error?.message?.startsWith("Command failed: grep")) {
return;
}
if (error !== null) {
throw error
}
if (stderr !== "") {
throw stderr
}
const found = stdout.split("\n").filter(s => s !== "").filter(s => s.startsWith("test/"));
if (found.length > 0) {
throw "Found a 'constructor.name' at " + found.join(", ") + ". This is not allowed, as minification does erase names."
}
}))
}
]
CodeQualitySpec.detectInCode("constructor\\.name", "This is not allowed, as minification does erase names.")
}],
[
"no reverse in compiled code", () => {
CodeQualitySpec.detectInCode("reverse()", "Reverse is stateful and changes the source list. This often causes subtle bugs")
}]
]);
}
/**
*
* @param forbidden: a GREP-regex. This means that '.' is a wildcard and should be escaped to match a literal dot
* @param reason
* @private
*/
private static detectInCode(forbidden: string, reason: string) {
const excludedDirs = [".git", "node_modules", "dist", ".cache", ".parcel-cache", "assets"]
exec("grep -n \"" + forbidden + "\" -r . " + excludedDirs.map(d => "--exclude-dir=" + d).join(" "), ((error, stdout, stderr) => {
if (error?.message?.startsWith("Command failed: grep")) {
console.warn("Command failed!")
return;
}
if (error !== null) {
throw error
}
if (stderr !== "") {
throw stderr
}
const found = stdout.split("\n").filter(s => s !== "").filter(s => !s.startsWith("./test/"));
if (found.length > 0) {
throw `Found a '${forbidden}' at \n ${found.join("\n ")}.\n ${reason}`
}
}))
}
}

View file

@ -0,0 +1,219 @@
import T from "./TestHelper";
import CreateMultiPolygonWithPointReuseAction from "../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction";
import { Tag } from "../Logic/Tags/Tag";
import FeaturePipelineState from "../Logic/State/FeaturePipelineState";
import { Changes } from "../Logic/Osm/Changes";
import {ChangesetHandler} from "../Logic/Osm/ChangesetHandler";
import * as Assert from "assert";
export default class ImportMultiPolygonSpec extends T {
constructor() {
super([
["Correct changeset",
async () => {
const feature = {
"type": "Feature",
"properties": {
"osm_id": "41097039",
"size_grb_building": "1374.89",
"addr:housenumber": "53",
"addr:street": "Startelstraat",
"building": "house",
"source:geometry:entity": "Gbg",
"source:geometry:date": "2014-04-28",
"source:geometry:oidn": "150044",
"source:geometry:uidn": "5403181",
"H_DTM_MIN": "50.35",
"H_DTM_GEM": "50.97",
"H_DSM_MAX": "59.40",
"H_DSM_P99": "59.09",
"HN_MAX": "8.43",
"HN_P99": "8.12",
"detection_method": "derived from OSM landuse: farmyard",
"auto_target_landuse": "farmyard",
"size_source_landuse": "8246.28",
"auto_building": "farm",
"id": "41097039",
"_lat": "50.84633355000016",
"_lon": "5.262964150000011",
"_layer": "grb",
"_length": "185.06002152312757",
"_length:km": "0.2",
"_now:date": "2022-02-22",
"_now:datetime": "2022-02-22 10:15:51",
"_loaded:date": "2022-02-22",
"_loaded:datetime": "2022-02-22 10:15:51",
"_geometry:type": "Polygon",
"_intersects_with_other_features": "",
"_country": "be",
"_overlaps_with_buildings": "[]",
"_overlap_percentage": "null",
"_grb_date": "2014-04-28",
"_grb_ref": "Gbg/150044",
"_building:min_level": "",
"_surface": "548.1242491529038",
"_surface:ha": "0",
"_reverse_overlap_percentage": "null",
"_imported_osm_object_found": "false",
"_imported_osm_still_fresh": "false",
"_target_building_type": "house"
},
"geometry": {
"type": "Polygon",
"coordinates": <[number, number][][]>[
[
[
5.262684300000043,
50.84624409999995
],
[
5.262777500000024,
50.84620759999988
],
[
5.262798899999998,
50.84621390000019
],
[
5.262999799999994,
50.84619519999999
],
[
5.263107500000007,
50.84618920000014
],
[
5.263115,
50.84620990000026
],
[
5.26310279999998,
50.84623050000014
],
[
5.263117999999977,
50.846247400000166
],
[
5.263174599999989,
50.84631019999971
],
[
5.263166999999989,
50.84631459999995
],
[
5.263243999999979,
50.84640239999989
],
[
5.2631607000000065,
50.84643459999996
],
[
5.26313309999997,
50.84640089999985
],
[
5.262907499999996,
50.84647790000018
],
[
5.2628939999999576,
50.846463699999774
],
[
5.262872100000033,
50.846440700000294
],
[
5.262784699999991,
50.846348899999924
],
[
5.262684300000043,
50.84624409999995
]
],
[
[
5.262801899999976,
50.84623269999982
],
[
5.2629535000000285,
50.84638830000012
],
[
5.263070700000018,
50.84634720000008
],
[
5.262998000000025,
50.84626279999982
],
[
5.263066799999966,
50.84623959999975
],
[
5.263064000000004,
50.84623330000007
],
[
5.263009599999997,
50.84623730000026
],
[
5.263010199999956,
50.84621629999986
],
[
5.262801899999976,
50.84623269999982
]
]
]
},
}
const innerRings = [...feature.geometry.coordinates]
innerRings.splice(0, 1)
const action = new CreateMultiPolygonWithPointReuseAction(
[new Tag("building", "yes")],
feature.geometry.coordinates[0],
innerRings,
undefined,
[],
"import"
)
const descriptions = await action.Perform(new Changes())
function getCoor(id: number): {lat: number, lon:number} {
return <any> descriptions.find(d => d.type === "node" && d.id === id).changes
}
const ways= descriptions.filter(d => d.type === "way")
T.isTrue(ways[0].id == -18, "unexpected id")
T.isTrue(ways[1].id == -27, "unexpected id")
const outer = ways[0].changes["coordinates"]
const outerExpected = [[5.262684300000043,50.84624409999995],[5.262777500000024,50.84620759999988],[5.262798899999998,50.84621390000019],[5.262999799999994,50.84619519999999],[5.263107500000007,50.84618920000014],[5.263115,50.84620990000026],[5.26310279999998,50.84623050000014],[5.263117999999977,50.846247400000166],[5.263174599999989,50.84631019999971],[5.263166999999989,50.84631459999995],[5.263243999999979,50.84640239999989],[5.2631607000000065,50.84643459999996],[5.26313309999997,50.84640089999985],[5.262907499999996,50.84647790000018],[5.2628939999999576,50.846463699999774],[5.262872100000033,50.846440700000294],[5.262784699999991,50.846348899999924],[5.262684300000043,50.84624409999995]]
T.listIdentical(feature.geometry.coordinates[0], outer)
const inner = ways[1].changes["coordinates"]
T.listIdentical(feature.geometry.coordinates[1], inner)
const members = <{type: string, role: string, ref: number}[]> descriptions.find(d => d.type === "relation").changes["members"]
T.isTrue(members[0].role == "outer", "incorrect role")
T.isTrue(members[1].role == "inner", "incorrect role")
T.isTrue(members[0].type == "way", "incorrect type")
T.isTrue(members[1].type == "way", "incorrect type")
T.isTrue(members[0].ref == -18, "incorrect id")
T.isTrue(members[1].ref == -27, "incorrect id")
}]
]);
}
}

View file

@ -20,6 +20,7 @@ import CreateNoteImportLayerSpec from "./CreateNoteImportLayer.spec";
import ValidatedTextFieldTranslationsSpec from "./ValidatedTextFieldTranslations.spec";
import CreateCacheSpec from "./CreateCache.spec";
import CodeQualitySpec from "./CodeQuality.spec";
import ImportMultiPolygonSpec from "./ImportMultiPolygon.spec";
async function main() {
@ -43,7 +44,8 @@ async function main() {
new CreateNoteImportLayerSpec(),
new ValidatedTextFieldTranslationsSpec(),
new CreateCacheSpec(),
new CodeQualitySpec()
new CodeQualitySpec(),
new ImportMultiPolygonSpec()
]
ScriptUtils.fixUtils();
const realDownloadFunc = Utils.externalDownloadFunction;