From bc1590fd08fb855b7df388e55585771998bebd59 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 6 Jan 2022 15:33:25 +0100 Subject: [PATCH] Fix tests --- assets/themes/grb_import/grb.json | 20 +- test/ReplaceGeometry.spec.ts | 441 +++++++++++++++++++++--------- test/TestHelper.ts | 2 +- 3 files changed, 319 insertions(+), 144 deletions(-) diff --git a/assets/themes/grb_import/grb.json b/assets/themes/grb_import/grb.json index 26ca25ecc5..e2ad53409e 100644 --- a/assets/themes/grb_import/grb.json +++ b/assets/themes/grb_import/grb.json @@ -43,28 +43,10 @@ "iconSize": "15,15,center" } ], - "calculatedTags": [ - "_embedded_crab_addresses= Number(feat.properties.zoom) >= 18 ? feat.overlapWith('crab_address').length : undefined" - ], - "minZoom": 18, "tagRenderings": [ { "id": "hw", - "render": "There are {_embedded_crab_addresses} adresses in view", - "mappings": [ - { - "if": "zoom<18", - "then": "Zoom in more..." - }, - { - "if": "_embedded_crab_addresses=", - "then": "Loading..." - }, - { - "if": "_embedded_crab_addresses=0", - "then": "No CRAB addresses in view. Zoom in more to see them" - } - ] + "render": "Beep boop! I'm a bot!" } ] } diff --git a/test/ReplaceGeometry.spec.ts b/test/ReplaceGeometry.spec.ts index 7ec8af6e02..acc87d2164 100644 --- a/test/ReplaceGeometry.spec.ts +++ b/test/ReplaceGeometry.spec.ts @@ -10,12 +10,323 @@ import {AllKnownLayouts} from "../Customizations/AllKnownLayouts"; import State from "../State"; import {BBox} from "../Logic/BBox"; import Minimap from "../UI/Base/Minimap"; -import * as Assert from "assert"; export default class ReplaceGeometrySpec extends T { + + private static readonly grbStripped = { + "id": "grb", + "title": { + "nl": "GRB import helper" + }, + "description":"Smaller version of the GRB theme", + "language": [ + "nl", + "en" + ], + "version": "0", + "startLat": 51.0249, + "startLon": 4.026489, + "startZoom": 9, + "clustering":false, + "overrideAll": { + "minzoom": 19 + }, + "layers": [ + { + "builtin": "type_node", + "override": { + "calculatedTags": [ + "_is_part_of_building=feat.get('parent_ways')?.some(p => p.building !== undefined && p.building !== '') ?? false", + "_is_part_of_grb_building=feat.get('parent_ways')?.some(p => p['source:geometry:ref'] !== undefined) ?? false", + "_is_part_of_building_passage=feat.get('parent_ways')?.some(p => p.tunnel === 'building_passage') ?? false", + "_is_part_of_highway=!feat.get('is_part_of_building_passage') && (feat.get('parent_ways')?.some(p => p.highway !== undefined && p.highway !== '') ?? false)", + "_is_part_of_landuse=feat.get('parent_ways')?.some(p => (p.landuse !== undefined && p.landuse !== '') || (p.natural !== undefined && p.natural !== '')) ?? false", + "_moveable=feat.get('_is_part_of_building') && !feat.get('_is_part_of_grb_building')" + ], + "mapRendering": [ + { + "icon": "square:#cc0", + "iconSize": "5,5,center", + "location": [ + "point" + ] + } + ], + "passAllFeatures": true + } + }, + { + "id": "osm-buildings", + "name": "All OSM-buildings", + "source": { + "osmTags": "building~*", + "maxCacheAge": 0 + }, + "calculatedTags": [ + "_surface:strict:=feat.get('_surface')" + ], + "mapRendering": [ + { + "width": { + "render": "2", + "mappings": [ + { + "if": "fixme~*", + "then": "5" + } + ] + }, + "color": { + "render": "#00c", + "mappings": [ + { + "if": "fixme~*", + "then": "#ff00ff" + }, + { + "if": "building=house", + "then": "#a00" + }, + { + "if": "building=shed", + "then": "#563e02" + }, + { + "if": { + "or": [ + "building=garage", + "building=garages" + ] + }, + "then": "#f9bfbb" + }, + { + "if": "building=yes", + "then": "#0774f2" + } + ] + } + } + ], + "title": "OSM-gebouw", + "tagRenderings": [ + { + "id": "building type", + "freeform": { + "key": "building" + }, + "render": "The building type is {building}", + "question": { + "en": "What kind of building is this?" + }, + "mappings": [ + { + "if": "building=house", + "then": "A normal house" + }, + { + "if": "building=detached", + "then": "A house detached from other building" + }, + { + "if": "building=semidetached_house", + "then": "A house sharing only one wall with another house" + }, + { + "if": "building=apartments", + "then": "An apartment building - highrise for living" + }, + { + "if": "building=office", + "then": "An office building - highrise for work" + }, + { + "if": "building=apartments", + "then": "An apartment building" + }, + { + "if": "building=shed", + "then": "A small shed, e.g. in a garden" + }, + { + "if": "building=garage", + "then": "A single garage to park a car" + }, + { + "if": "building=garages", + "then": "A building containing only garages; typically they are all identical" + }, + { + "if": "building=yes", + "then": "A building - no specification" + } + ] + }, + { + "id": "grb-housenumber", + "render": { + "nl": "Het huisnummer is {addr:housenumber}" + }, + "question": { + "nl": "Wat is het huisnummer?" + }, + "freeform": { + "key": "addr:housenumber" + }, + "mappings": [ + { + "if": { + "and": [ + "not:addr:housenumber=yes", + "addr:housenumber=" + ] + }, + "then": { + "nl": "Geen huisnummer" + } + } + ] + }, + { + "id": "grb-unit", + "question": "Wat is de wooneenheid-aanduiding?", + "render": { + "nl": "De wooneenheid-aanduiding is {addr:unit} " + }, + "freeform": { + "key": "addr:unit" + }, + "mappings": [ + { + "if": "addr:unit=", + "then": "Geen wooneenheid-nummer" + } + ] + }, + { + "id": "grb-street", + "render": { + "nl": "De straat is {addr:street}" + }, + "freeform": { + "key": "addr:street" + }, + "question": { + "nl": "Wat is de straat?" + } + }, + { + "id": "grb-fixme", + "render": { + "nl": "De fixme is {fixme}" + }, + "question": { + "nl": "Wat zegt de fixme?" + }, + "freeform": { + "key": "fixme" + }, + "mappings": [ + { + "if": { + "and": [ + "fixme=" + ] + }, + "then": { + "nl": "Geen fixme" + } + } + ] + }, + { + "id": "grb-min-level", + "render": { + "nl": "Dit gebouw begint maar op de {building:min_level} verdieping" + }, + "question": { + "nl": "Hoeveel verdiepingen ontbreken?" + }, + "freeform": { + "key": "building:min_level", + "type": "pnat" + } + }, + "all_tags" + ], + "filter": [ + { + "id": "has-fixme", + "options": [ + { + "osmTags": "fixme~*", + "question": "Heeft een FIXME" + } + ] + } + ] + }, + "address", + { + "id": "grb", + "description": "Geometry which comes from GRB with tools to import them", + "source": { + "osmTags": { + "and": [ + "HUISNR~*", + "man_made!=mast" + ] + }, + "geoJson": "https://betadata.grbosm.site/grb?bbox={x_min},{y_min},{x_max},{y_max}", + "geoJsonZoomLevel": 18, + "mercatorCrs": true, + "maxCacheAge": 0 + }, + "name": "GRB geometries", + "title": "GRB outline", + "calculatedTags": [ + "_overlaps_with_buildings=feat.overlapWith('osm-buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)", + "_overlaps_with=feat.get('_overlaps_with_buildings').filter(f => f.overlap > 1 /* square meter */ )[0] ?? ''", + "_osm_obj:source:ref=feat.get('_overlaps_with')?.feat?.properties['source:geometry:ref']", + "_osm_obj:id=feat.get('_overlaps_with')?.feat?.properties?.id", + "_osm_obj:source:date=feat.get('_overlaps_with')?.feat?.properties['source:geometry:date'].replace(/\\//g, '-')", + "_osm_obj:building=feat.get('_overlaps_with')?.feat?.properties?.building", + "_osm_obj:addr:street=(feat.get('_overlaps_with')?.feat?.properties ?? {})['addr:street']", + "_osm_obj:addr:housenumber=(feat.get('_overlaps_with')?.feat?.properties ?? {})['addr:housenumber']", + "_osm_obj:surface=(feat.get('_overlaps_with')?.feat?.properties ?? {})['_surface:strict']", + + "_overlap_absolute=feat.get('_overlaps_with')?.overlap", + "_reverse_overlap_percentage=Math.round(100 * feat.get('_overlap_absolute') / feat.get('_surface'))", + "_overlap_percentage=Math.round(100 * feat.get('_overlap_absolute') / feat.get('_osm_obj:surface'))", + "_grb_ref=feat.properties['source:geometry:entity'] + '/' + feat.properties['source:geometry:oidn']", + "_imported_osm_object_found= feat.properties['_osm_obj:source:ref'] == feat.properties._grb_ref", + "_grb_date=feat.properties['source:geometry:date'].replace(/\\//g,'-')", + "_imported_osm_still_fresh= feat.properties['_osm_obj:source:date'] == feat.properties._grb_date", + "_target_building_type=feat.properties['_osm_obj:building'] === 'yes' ? feat.properties.building : (feat.properties['_osm_obj:building'] ?? feat.properties.building)", + "_building:min_level= feat.properties['fixme']?.startsWith('verdieping, correct the building tag, add building:level and building:min_level before upload in JOSM!') ? '1' : ''", + "_intersects_with_other_features=feat.intersectionsWith('generic_osm_object').map(f => \"\" + f.feat.properties.id + \"\").join(', ')" + ], + "tagRenderings": [], + "mapRendering": [ + { + "iconSize": "50,50,center", + "icon": "./assets/themes/grb_import/housenumber_blank.svg", + "location": [ + "point", + "centroid" + ] + } + ] + } + ] + } + + + + constructor() { super("ReplaceGeometry", [ - ["Simple house replacement", async () => { + ["House replacement with connected node", async () => { Minimap.createMiniMap = () => undefined; @@ -88,7 +399,10 @@ export default class ReplaceGeometrySpec extends T { ) Utils.injectJsonDownloadForTests("https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/latlon2country/0.0.0.json","be") - const layout = AllKnownLayouts.allKnownLayouts.get("grb") + const layout = new LayoutConfig( ReplaceGeometrySpec.grbStripped) + + + const state = new State(layout) State.state = state; const bbox = new BBox( @@ -139,127 +453,6 @@ export default class ReplaceGeometrySpec extends T { changes[11].changes["coordinates"]) }], - ["Advanced merge case with connections and tags", async () => { - return - - Minimap.createMiniMap = () => undefined; - - const osmWay = "way/323230330"; - const grb_data = { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - 4.483118100000016, - 51.028366499999706 - ], - [ - 4.483135099999986, - 51.028325800000005 - ], - [ - 4.483137700000021, - 51.02831960000019 - ], - [ - 4.4831429000000025, - 51.0283205 - ], - [ - 4.483262199999987, - 51.02834059999982 - ], - [ - 4.483276700000019, - 51.028299999999746 - ], - [ - 4.483342100000037, - 51.02830730000009 - ], - [ - 4.483340700000012, - 51.028331299999934 - ], - [ - 4.483346499999953, - 51.02833189999984 - ], - [ - 4.483290600000001, - 51.028500699999846 - ], - [ - 4.4833335999999635, - 51.02851150000015 - ], - [ - 4.4833433000000475, - 51.028513999999944 - ], - [ - 4.483312899999958, - 51.02857759999998 - ], - [ - 4.483141100000033, - 51.02851780000015 - ], - [ - 4.483193100000022, - 51.028409999999894 - ], - [ - 4.483206100000019, - 51.02838310000014 - ], - [ - 4.483118100000016, - 51.028366499999706 - ] - ] - ] - }, - "id": "https://betadata.grbosm.site/grb?bbox=498980.9206456306,6626173.107985358,499133.7947022009,6626325.98204193/30", - "bbox": { - "maxLat": 51.02857759999998, - "maxLon": 4.483346499999953, - "minLat": 51.028299999999746, - "minLon": 4.483118100000016 - }, - "_lon": 4.483232299999985, - "_lat": 51.02843879999986 - } - - const config = new LayoutConfig(grb, true, "ReplaceGeometrySpec.grbtheme") - const state = new MapState( - config, { - attemptLogin: false - } - ) - const featurepipeline = new FeaturePipeline( - _ => { - }, - state - ) - - - const action = new ReplaceGeometryAction({ - osmConnection: undefined, - featurePipeline: featurepipeline - }, grb_data, - osmWay, - { - theme: "test", - newTags: [new Tag("test", "yes")] - }) - - const info = await action.GetClosestIds() - console.log(info) - }] ]); } } \ No newline at end of file diff --git a/test/TestHelper.ts b/test/TestHelper.ts index 1f84cc7812..924c00cd10 100644 --- a/test/TestHelper.ts +++ b/test/TestHelper.ts @@ -45,7 +45,7 @@ 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]["length"] !== undefined ){ + if(expected[i] !== undefined && expected[i]["length"] !== undefined ){ T.listIdentical( expected[i], actual[i]) }else if (expected[i] !== actual[i]) { throw `ListIdentical failed at index ${i}: expected ${expected[i]} but got ${actual[i]}`