mapcomplete/test/Logic/Actors/Actors.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-06-02 08:42:08 +02:00
import {Utils} from "../../../Utils"
2022-03-17 21:51:53 +01:00
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
import * as bookcaseJson from "../../../assets/generated/themes/bookcases.json"
2023-06-02 08:42:08 +02:00
import {OsmTags} from "../../../Models/OsmFeature"
import {Feature, Geometry} from "geojson"
import {expect, it} from "vitest"
import ThemeViewState from "../../../Models/ThemeViewState"
2023-05-17 13:16:43 +02:00
import ScriptUtils from "../../../scripts/ScriptUtils";
2022-03-17 21:51:53 +01:00
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,
},
2022-09-08 21:40:48 +02:00
],
2022-03-17 21:51:53 +01:00
})
2023-05-17 13:16:43 +02:00
it("should download the latest version", async () => {
2023-04-07 03:54:11 +02:00
const state = new ThemeViewState(new LayoutConfig(<any>bookcaseJson, true))
2023-01-22 01:09:16 +01:00
const feature: Feature<Geometry, OsmTags> = {
2022-03-17 21:51:53 +01:00
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],
},
}
2023-04-07 03:54:11 +02:00
state.newFeatures.features.data.push(feature)
state.newFeatures.features.ping()
2023-05-17 13:16:43 +02:00
// The 'selectedElementsTagsUpdater' is the functionality which is tested here
// However, one is initialized in the 'ThemeViewState' as well; and I'm to lazy to partially construct one here
// new SelectedElementTagsUpdater()
2022-03-17 21:51:53 +01:00
// 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)
2023-05-17 13:16:43 +02:00
await ScriptUtils.sleep(50)
2022-03-17 21:51:53 +01:00
// The name should be updated
2023-02-03 04:48:32 +01:00
expect(feature.properties.name).toEqual("Stubbekwartier-buurtbibliotheek")
2022-03-17 21:51:53 +01:00
// The fixme should be removed
2023-02-03 04:48:32 +01:00
expect(feature.properties.fixme).toBeUndefined()
2022-03-17 21:51:53 +01:00
})