Merge branch 'develop' of github.com:pietervdvn/MapComplete into develop
This commit is contained in:
commit
f9e4c9ecea
5 changed files with 175 additions and 195 deletions
|
@ -52,6 +52,8 @@ export class ChangesetHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new list which contains every key at most once
|
* Creates a new list which contains every key at most once
|
||||||
|
*
|
||||||
|
* ChangesetHandler.removeDuplicateMetaTags([{key: "k", value: "v"}, {key: "k0", value: "v0"}, {key: "k", value:"v"}] // => [{key: "k", value: "v"}, {key: "k0", value: "v0"}]
|
||||||
*/
|
*/
|
||||||
public static removeDuplicateMetaTags(extraMetaTags: ChangesetTag[]): ChangesetTag[]{
|
public static removeDuplicateMetaTags(extraMetaTags: ChangesetTag[]): ChangesetTag[]{
|
||||||
const r : ChangesetTag[] = []
|
const r : ChangesetTag[] = []
|
||||||
|
@ -271,8 +273,8 @@ export class ChangesetHandler {
|
||||||
private parseUploadChangesetResponse(response: XMLDocument): Map<string, string> {
|
private parseUploadChangesetResponse(response: XMLDocument): Map<string, string> {
|
||||||
const nodes = response.getElementsByTagName("node");
|
const nodes = response.getElementsByTagName("node");
|
||||||
const mappings = new Map<string, string>()
|
const mappings = new Map<string, string>()
|
||||||
// @ts-ignore
|
|
||||||
for (const node of nodes) {
|
for (const node of Array.from(nodes)) {
|
||||||
const mapping = this.handleIdRewrite(node, "node")
|
const mapping = this.handleIdRewrite(node, "node")
|
||||||
if (mapping !== undefined) {
|
if (mapping !== undefined) {
|
||||||
mappings.set(mapping[0], mapping[1])
|
mappings.set(mapping[0], mapping[1])
|
||||||
|
@ -280,8 +282,7 @@ export class ChangesetHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ways = response.getElementsByTagName("way");
|
const ways = response.getElementsByTagName("way");
|
||||||
// @ts-ignore
|
for (const way of Array.from(ways)) {
|
||||||
for (const way of ways) {
|
|
||||||
const mapping = this.handleIdRewrite(way, "way")
|
const mapping = this.handleIdRewrite(way, "way")
|
||||||
if (mapping !== undefined) {
|
if (mapping !== undefined) {
|
||||||
mappings.set(mapping[0], mapping[1])
|
mappings.set(mapping[0], mapping[1])
|
||||||
|
|
|
@ -1,140 +0,0 @@
|
||||||
import T from "./TestHelper";
|
|
||||||
import SelectedElementTagsUpdater from "../Logic/Actors/SelectedElementTagsUpdater";
|
|
||||||
import UserRelatedState from "../Logic/State/UserRelatedState";
|
|
||||||
import {Utils} from "../Utils";
|
|
||||||
import SelectedFeatureHandler from "../Logic/Actors/SelectedFeatureHandler";
|
|
||||||
import {UIEventSource} from "../Logic/UIEventSource";
|
|
||||||
import {ElementStorage} from "../Logic/ElementStorage";
|
|
||||||
import Loc from "../Models/Loc";
|
|
||||||
import * as bookcaseJson from "../assets/generated/themes/bookcases.json"
|
|
||||||
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
|
|
||||||
|
|
||||||
export default class ActorsSpec extends T {
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
|
|
||||||
const latestTags = {
|
|
||||||
"amenity": "public_bookcase",
|
|
||||||
"books": "children;adults",
|
|
||||||
"capacity": "25",
|
|
||||||
"description": "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
|
||||||
"image:0": "https://i.imgur.com/Z8a69UG.jpg",
|
|
||||||
"name": "Stubbekwartier-buurtbibliotheek",
|
|
||||||
"nobrand": "yes",
|
|
||||||
"opening_hours": "24/7",
|
|
||||||
"operator": "Huisbewoner",
|
|
||||||
"public_bookcase:type": "reading_box"
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.injectJsonDownloadForTests(
|
|
||||||
"https://www.openstreetmap.org/api/0.6/node/5568693115",
|
|
||||||
{
|
|
||||||
"version": "0.6",
|
|
||||||
"generator": "CGImap 0.8.5 (1815943 spike-06.openstreetmap.org)",
|
|
||||||
"copyright": "OpenStreetMap and contributors",
|
|
||||||
"attribution": "http://www.openstreetmap.org/copyright",
|
|
||||||
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
|
|
||||||
"elements": [{
|
|
||||||
"type": "node",
|
|
||||||
"id": 5568693115,
|
|
||||||
"lat": 51.2179199,
|
|
||||||
"lon": 3.2154662,
|
|
||||||
"timestamp": "2021-08-21T16:22:55Z",
|
|
||||||
"version": 6,
|
|
||||||
"changeset": 110034454,
|
|
||||||
"user": "Pieter Vander Vennet",
|
|
||||||
"uid": 3818858,
|
|
||||||
"tags": latestTags
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
super([
|
|
||||||
[
|
|
||||||
"download latest version",
|
|
||||||
() => {
|
|
||||||
const state = new UserRelatedState(new LayoutConfig(<any> bookcaseJson, true, "tests"))
|
|
||||||
const feature = {
|
|
||||||
"type": "Feature",
|
|
||||||
"id": "node/5568693115",
|
|
||||||
"properties": {
|
|
||||||
"amenity": "public_bookcase",
|
|
||||||
"books": "children;adults",
|
|
||||||
"capacity": "25",
|
|
||||||
"description": "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
|
||||||
"image:0": "https://i.imgur.com/Z8a69UG.jpg",
|
|
||||||
"name": "OUTDATED NAME",
|
|
||||||
"nobrand": "yes",
|
|
||||||
"opening_hours": "24/7",
|
|
||||||
"operator": "Huisbewoner",
|
|
||||||
"public_bookcase:type": "reading_box",
|
|
||||||
"id": "node/5568693115",
|
|
||||||
"_lat": "51.2179199",
|
|
||||||
"_lon": "3.2154662",
|
|
||||||
"fixme": "SOME FIXME"
|
|
||||||
},
|
|
||||||
"geometry": {
|
|
||||||
"type": "Point",
|
|
||||||
"coordinates": [
|
|
||||||
3.2154662,
|
|
||||||
51.2179199
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"bbox": {
|
|
||||||
"maxLat": 51.2179199,
|
|
||||||
"maxLon": 3.2154662,
|
|
||||||
"minLat": 51.2179199,
|
|
||||||
"minLon": 3.2154662
|
|
||||||
},
|
|
||||||
"_lon": 3.2154662,
|
|
||||||
"_lat": 51.2179199
|
|
||||||
}
|
|
||||||
state.allElements.addOrGetElement(feature)
|
|
||||||
SelectedElementTagsUpdater.installCallback(state)
|
|
||||||
|
|
||||||
// THis should trigger a download of the latest feaures and update the tags
|
|
||||||
// However, this doesn't work with ts-node for some reason
|
|
||||||
state.selectedElement.setData(feature)
|
|
||||||
|
|
||||||
SelectedElementTagsUpdater.applyUpdate(state, latestTags, feature.properties.id)
|
|
||||||
|
|
||||||
// The name should be updated
|
|
||||||
T.equals("Stubbekwartier-buurtbibliotheek", feature.properties.name)
|
|
||||||
// The fixme should be removed
|
|
||||||
T.equals(undefined, feature.properties.fixme)
|
|
||||||
|
|
||||||
}],
|
|
||||||
["Hash without selected element should download geojson from OSM-API", async () => {
|
|
||||||
const hash = new UIEventSource("node/5568693115")
|
|
||||||
const selected = new UIEventSource(undefined)
|
|
||||||
const loc = new UIEventSource<Loc>({
|
|
||||||
lat: 0,
|
|
||||||
lon: 0,
|
|
||||||
zoom: 0
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
loc.addCallback(_ => {
|
|
||||||
T.equals("node/5568693115", selected.data.properties.id)
|
|
||||||
T.equals(14, loc.data.zoom)
|
|
||||||
T.equals(51.2179199, loc.data.lat)
|
|
||||||
})
|
|
||||||
|
|
||||||
new SelectedFeatureHandler(hash, {
|
|
||||||
selectedElement: selected,
|
|
||||||
allElements: new ElementStorage(),
|
|
||||||
featurePipeline: undefined,
|
|
||||||
locationControl: loc,
|
|
||||||
layoutToUse: undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
}]
|
|
||||||
|
|
||||||
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
import T from "./TestHelper";
|
|
||||||
import {Changes} from "../Logic/Osm/Changes";
|
|
||||||
import {ChangeDescription, ChangeDescriptionTools} from "../Logic/Osm/Actions/ChangeDescription";
|
|
||||||
|
|
||||||
export default class ChangesSpec extends T {
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super([
|
|
||||||
["Generate preXML from changeDescriptions", () => {
|
|
||||||
const changeDescrs: ChangeDescription[] = [
|
|
||||||
{
|
|
||||||
type: "node",
|
|
||||||
id: -1,
|
|
||||||
changes: {
|
|
||||||
lat: 42,
|
|
||||||
lon: -8
|
|
||||||
},
|
|
||||||
tags: [{k: "someKey", v: "someValue"}],
|
|
||||||
meta: {
|
|
||||||
changeType: "create",
|
|
||||||
theme: "test"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "node",
|
|
||||||
id: -1,
|
|
||||||
tags: [{k: 'foo', v: 'bar'}],
|
|
||||||
meta: {
|
|
||||||
changeType: "answer",
|
|
||||||
theme: "test"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const c = new Changes()
|
|
||||||
const descr = c.CreateChangesetObjects(
|
|
||||||
changeDescrs,
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
T.equals(0, descr.modifiedObjects.length)
|
|
||||||
T.equals(0, descr.deletedObjects.length)
|
|
||||||
T.equals(1, descr.newObjects.length)
|
|
||||||
const ch = descr.newObjects[0]
|
|
||||||
T.equals("bar", ch.tags["foo"])
|
|
||||||
T.equals("someValue", ch.tags["someKey"])
|
|
||||||
}]
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
128
tests/Logic/Actors/Actors.spec.ts
Normal file
128
tests/Logic/Actors/Actors.spec.ts
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
import {describe} from 'mocha'
|
||||||
|
import {expect} from 'chai'
|
||||||
|
import {Utils} from "../../../Utils";
|
||||||
|
import UserRelatedState from "../../../Logic/State/UserRelatedState";
|
||||||
|
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig";
|
||||||
|
import SelectedElementTagsUpdater from "../../../Logic/Actors/SelectedElementTagsUpdater";
|
||||||
|
import T from "../../../testLegacy/TestHelper";
|
||||||
|
|
||||||
|
import * as bookcaseJson from "../../../assets/generated/themes/bookcases.json"
|
||||||
|
import {UIEventSource} from "../../../Logic/UIEventSource";
|
||||||
|
import Loc from "../../../Models/Loc";
|
||||||
|
import SelectedFeatureHandler from "../../../Logic/Actors/SelectedFeatureHandler";
|
||||||
|
import {ElementStorage} from "../../../Logic/ElementStorage";
|
||||||
|
|
||||||
|
const latestTags = {
|
||||||
|
"amenity": "public_bookcase",
|
||||||
|
"books": "children;adults",
|
||||||
|
"capacity": "25",
|
||||||
|
"description": "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
||||||
|
"image:0": "https://i.imgur.com/Z8a69UG.jpg",
|
||||||
|
"name": "Stubbekwartier-buurtbibliotheek",
|
||||||
|
"nobrand": "yes",
|
||||||
|
"opening_hours": "24/7",
|
||||||
|
"operator": "Huisbewoner",
|
||||||
|
"public_bookcase:type": "reading_box"
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils.injectJsonDownloadForTests(
|
||||||
|
"https://www.openstreetmap.org/api/0.6/node/5568693115",
|
||||||
|
{
|
||||||
|
"version": "0.6",
|
||||||
|
"generator": "CGImap 0.8.5 (1815943 spike-06.openstreetmap.org)",
|
||||||
|
"copyright": "OpenStreetMap and contributors",
|
||||||
|
"attribution": "http://www.openstreetmap.org/copyright",
|
||||||
|
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
|
||||||
|
"elements": [{
|
||||||
|
"type": "node",
|
||||||
|
"id": 5568693115,
|
||||||
|
"lat": 51.2179199,
|
||||||
|
"lon": 3.2154662,
|
||||||
|
"timestamp": "2021-08-21T16:22:55Z",
|
||||||
|
"version": 6,
|
||||||
|
"changeset": 110034454,
|
||||||
|
"user": "Pieter Vander Vennet",
|
||||||
|
"uid": 3818858,
|
||||||
|
"tags": latestTags
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
it("should download the latest version", () => {
|
||||||
|
const state = new UserRelatedState(new LayoutConfig(<any> bookcaseJson, true, "tests"))
|
||||||
|
const feature = {
|
||||||
|
"type": "Feature",
|
||||||
|
"id": "node/5568693115",
|
||||||
|
"properties": {
|
||||||
|
"amenity": "public_bookcase",
|
||||||
|
"books": "children;adults",
|
||||||
|
"capacity": "25",
|
||||||
|
"description": "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
||||||
|
"image:0": "https://i.imgur.com/Z8a69UG.jpg",
|
||||||
|
"name": "OUTDATED NAME",
|
||||||
|
"nobrand": "yes",
|
||||||
|
"opening_hours": "24/7",
|
||||||
|
"operator": "Huisbewoner",
|
||||||
|
"public_bookcase:type": "reading_box",
|
||||||
|
"id": "node/5568693115",
|
||||||
|
"_lat": "51.2179199",
|
||||||
|
"_lon": "3.2154662",
|
||||||
|
"fixme": "SOME FIXME"
|
||||||
|
},
|
||||||
|
"geometry": {
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [
|
||||||
|
3.2154662,
|
||||||
|
51.2179199
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"bbox": {
|
||||||
|
"maxLat": 51.2179199,
|
||||||
|
"maxLon": 3.2154662,
|
||||||
|
"minLat": 51.2179199,
|
||||||
|
"minLon": 3.2154662
|
||||||
|
},
|
||||||
|
"_lon": 3.2154662,
|
||||||
|
"_lat": 51.2179199
|
||||||
|
}
|
||||||
|
state.allElements.addOrGetElement(feature)
|
||||||
|
SelectedElementTagsUpdater.installCallback(state)
|
||||||
|
|
||||||
|
// THis should trigger a download of the latest feaures and update the tags
|
||||||
|
// However, this doesn't work with ts-node for some reason
|
||||||
|
state.selectedElement.setData(feature)
|
||||||
|
|
||||||
|
SelectedElementTagsUpdater.applyUpdate(state, latestTags, feature.properties.id)
|
||||||
|
|
||||||
|
// The name should be updated
|
||||||
|
T.equals("Stubbekwartier-buurtbibliotheek", feature.properties.name)
|
||||||
|
// The fixme should be removed
|
||||||
|
T.equals(undefined, feature.properties.fixme)
|
||||||
|
|
||||||
|
})
|
||||||
|
it("Hash without selected element should download geojson from OSM-API", async () => {
|
||||||
|
const hash = new UIEventSource("node/5568693115")
|
||||||
|
const selected = new UIEventSource(undefined)
|
||||||
|
const loc = new UIEventSource<Loc>({
|
||||||
|
lat: 0,
|
||||||
|
lon: 0,
|
||||||
|
zoom: 0
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
loc.addCallback(_ => {
|
||||||
|
T.equals("node/5568693115", selected.data.properties.id)
|
||||||
|
T.equals(14, loc.data.zoom)
|
||||||
|
T.equals(51.2179199, loc.data.lat)
|
||||||
|
})
|
||||||
|
|
||||||
|
new SelectedFeatureHandler(hash, {
|
||||||
|
selectedElement: selected,
|
||||||
|
allElements: new ElementStorage(),
|
||||||
|
featurePipeline: undefined,
|
||||||
|
locationControl: loc,
|
||||||
|
layoutToUse: undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
})
|
42
tests/Logic/OSM/Changes.spec.ts
Normal file
42
tests/Logic/OSM/Changes.spec.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import {expect} from 'chai'
|
||||||
|
import {ChangeDescription} from "../../../Logic/Osm/Actions/ChangeDescription";
|
||||||
|
import {Changes} from "../../../Logic/Osm/Changes";
|
||||||
|
|
||||||
|
it("Generate preXML from changeDescriptions", () => {
|
||||||
|
const changeDescrs: ChangeDescription[] = [
|
||||||
|
{
|
||||||
|
type: "node",
|
||||||
|
id: -1,
|
||||||
|
changes: {
|
||||||
|
lat: 42,
|
||||||
|
lon: -8
|
||||||
|
},
|
||||||
|
tags: [{k: "someKey", v: "someValue"}],
|
||||||
|
meta: {
|
||||||
|
changeType: "create",
|
||||||
|
theme: "test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "node",
|
||||||
|
id: -1,
|
||||||
|
tags: [{k: 'foo', v: 'bar'}],
|
||||||
|
meta: {
|
||||||
|
changeType: "answer",
|
||||||
|
theme: "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const c = new Changes()
|
||||||
|
const descr = c.CreateChangesetObjects(
|
||||||
|
changeDescrs,
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
expect(descr.modifiedObjects).length(0)
|
||||||
|
expect(descr.deletedObjects).length(0)
|
||||||
|
expect(descr.newObjects).length(1)
|
||||||
|
|
||||||
|
const ch = descr.newObjects[0]
|
||||||
|
expect(ch.tags["foo"]).eq("bar")
|
||||||
|
expect(ch.tags["someKey"]).eq("someValue")
|
||||||
|
})
|
Loading…
Reference in a new issue