Port tests to vitest

This commit is contained in:
Pieter Vander Vennet 2023-02-03 04:48:32 +01:00
parent 64a4d7e929
commit 228ceb120d
33 changed files with 673 additions and 326 deletions

View file

@ -1,4 +1,3 @@
import { expect } from "chai"
import { Utils } from "../../../Utils"
import UserRelatedState from "../../../Logic/State/UserRelatedState"
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
@ -11,6 +10,7 @@ import SelectedFeatureHandler from "../../../Logic/Actors/SelectedFeatureHandler
import { ElementStorage } from "../../../Logic/ElementStorage"
import { OsmTags } from "../../../Models/OsmFeature"
import { Feature, Geometry } from "geojson"
import { describe, expect, it } from "vitest"
const latestTags = {
amenity: "public_bookcase",
@ -83,9 +83,9 @@ it("should download the latest version", () => {
SelectedElementTagsUpdater.applyUpdate(state, latestTags, feature.properties.id)
// The name should be updated
expect(feature.properties.name).deep.equal("Stubbekwartier-buurtbibliotheek")
expect(feature.properties.name).toEqual("Stubbekwartier-buurtbibliotheek")
// The fixme should be removed
expect(feature.properties.fixme).deep.equal(undefined)
expect(feature.properties.fixme).toBeUndefined()
})
it("Hash without selected element should download geojson from OSM-API", async () => {
const hash = new UIEventSource("node/5568693115")
@ -97,9 +97,9 @@ it("Hash without selected element should download geojson from OSM-API", async (
})
loc.addCallback((_) => {
expect(selected.data.properties.id).deep.equal("node/5568693115")
expect(loc.data.zoom).deep.equal(14)
expect(loc.data.lat).deep.equal(51.2179199)
expect(selected.data.properties.id).toEqual("node/5568693115")
expect(loc.data.zoom).toEqual(14)
expect(loc.data.lat).toEqual(51.2179199)
})
new SelectedFeatureHandler(hash, {

View file

@ -1,8 +1,7 @@
import { describe } from "mocha"
import { expect } from "chai"
import CreateMultiPolygonWithPointReuseAction from "../../../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction"
import { Tag } from "../../../Logic/Tags/Tag"
import { Changes } from "../../../Logic/Osm/Changes"
import { describe, expect, it } from "vitest"
describe("CreateMultiPolygonWithPointReuseAction", () => {
it("should produce a correct changeset", () => {
@ -106,21 +105,29 @@ describe("CreateMultiPolygonWithPointReuseAction", () => {
const descriptions = await action.Perform(new Changes())
const ways = descriptions.filter((d) => d.type === "way")
expect(ways[0].id == -18, "unexpected id").true
expect(ways[1].id == -27, "unexpected id").true
// "unexpected id"
expect(ways[0].id == -18).toBe(true)
// "unexpected id"
expect(ways[1].id == -27).toBe(true)
const outer = ways[0].changes["coordinates"]
expect(outer).deep.equal(feature.geometry.coordinates[0])
expect(outer).toEqual(feature.geometry.coordinates[0])
const inner = ways[1].changes["coordinates"]
expect(inner).deep.equal(feature.geometry.coordinates[1])
expect(inner).toEqual(feature.geometry.coordinates[1])
const members = <{ type: string; role: string; ref: number }[]>(
descriptions.find((d) => d.type === "relation").changes["members"]
)
expect(members[0].role, "incorrect role").eq("outer")
expect(members[1].role, "incorrect role").eq("inner")
expect(members[0].type, "incorrect type").eq("way")
expect(members[1].type, "incorrect type").eq("way")
expect(members[0].ref, "incorrect id").eq(-18)
expect(members[1].ref, "incorrect id").eq(-27)
// "incorrect role"
expect(members[0].role).toBe("outer")
// "incorrect role"
expect(members[1].role).toBe("inner")
// "incorrect type"
expect(members[0].type).toBe("way")
// "incorrect type"
expect(members[1].type).toBe("way")
// "incorrect id"
expect(members[0].ref).toBe(-18)
// "incorrect id"
expect(members[1].ref).toBe(-27)
}
})
})

View file

@ -1,7 +1,6 @@
import { describe } from "mocha"
import { expect } from "chai"
import { ExtraFuncParams, ExtraFunctions } from "../../Logic/ExtraFunctions"
import { OsmFeature } from "../../Models/OsmFeature"
import { describe, expect, it } from "vitest"
describe("OverlapFunc", () => {
it("should give doors on the edge", () => {
@ -122,6 +121,6 @@ describe("OverlapFunc", () => {
ExtraFunctions.FullPatchFeature(params, hermanTeirlinck)
const overlap = (<any>hermanTeirlinck).overlapWith("*")
console.log(JSON.stringify(overlap))
expect(overlap[0].feat == door).true
expect(overlap[0].feat == door).toBe(true)
})
})

View file

@ -1,4 +1,3 @@
import { describe } from "mocha"
import OsmFeatureSource from "../../../Logic/FeatureSource/TiledFeatureSource/OsmFeatureSource"
import { UIEventSource } from "../../../Logic/UIEventSource"
import ScriptUtils from "../../../scripts/ScriptUtils"
@ -8,7 +7,7 @@ import { readFileSync } from "fs"
import { Utils } from "../../../Utils"
import { Tag } from "../../../Logic/Tags/Tag"
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
import { expect } from "chai"
import { describe, expect, it } from "vitest"
const expected = {
type: "Feature",
@ -92,7 +91,7 @@ function test(done: () => void) {
handleTile: (tile) => {
fetchedTile = tile
const data = tile.features.data[0].feature
expect(data.properties).deep.eq({
expect(data.properties).toEqual({
id: "relation/5759328",
timestamp: "2022-06-10T00:46:55Z",
version: 6,
@ -107,8 +106,8 @@ function test(done: () => void) {
website: "http://ktahalle.be/",
_backend: "https://osm.org",
})
expect(data.geometry.type).eq("MultiPolygon")
expect(data).deep.eq(expected)
expect(data.geometry.type).toBe("MultiPolygon")
expect(data).toEqual(expected)
done()
},
isActive: new UIEventSource<boolean>(true),

View file

@ -1,7 +1,6 @@
import { describe } from "mocha"
import TileFreshnessCalculator from "../../../Logic/FeatureSource/TileFreshnessCalculator"
import { Tiles } from "../../../Models/TileRange"
import { expect } from "chai"
import { describe, expect, it } from "vitest"
describe("TileFreshnessCalculator", () => {
it("should get the freshness for loaded tiles", () => {
@ -11,13 +10,13 @@ describe("TileFreshnessCalculator", () => {
date.setTime(42)
calc.addTileLoad(Tiles.tile_index(19, 266406, 175534), date)
expect(calc.freshnessFor(19, 266406, 175534).getTime()).eq(42)
expect(calc.freshnessFor(20, 266406 * 2, 175534 * 2 + 1).getTime()).eq(42)
expect(calc.freshnessFor(19, 266406, 175535)).undefined
expect(calc.freshnessFor(18, 266406 / 2, 175534 / 2)).undefined
expect(calc.freshnessFor(19, 266406, 175534).getTime()).toBe(42)
expect(calc.freshnessFor(20, 266406 * 2, 175534 * 2 + 1).getTime()).toBe(42)
expect(calc.freshnessFor(19, 266406, 175535)).toBeUndefined()
expect(calc.freshnessFor(18, 266406 / 2, 175534 / 2)).toBeUndefined()
calc.addTileLoad(Tiles.tile_index(19, 266406, 175534 + 1), date)
calc.addTileLoad(Tiles.tile_index(19, 266406 + 1, 175534), date)
calc.addTileLoad(Tiles.tile_index(19, 266406 + 1, 175534 + 1), date)
expect(calc.freshnessFor(18, 266406 / 2, 175534 / 2).getTime()).eq(42)
expect(calc.freshnessFor(18, 266406 / 2, 175534 / 2).getTime()).toBe(42)
})
})

View file

@ -1,7 +1,6 @@
import { describe } from "mocha"
import { expect } from "chai"
import * as turf from "@turf/turf"
import { GeoOperations } from "../../Logic/GeoOperations"
import { describe, expect, it } from "vitest"
describe("GeoOperations", () => {
describe("calculateOverlap", () => {
@ -123,9 +122,9 @@ describe("GeoOperations", () => {
}
const p0 = turf.polygon(polyGrb.geometry.coordinates)
expect(p0).not.null
expect(p0).not.toBeNull()
const p1 = turf.polygon(polyHouse.geometry.coordinates)
expect(p1).not.null
expect(p1).not.toBeNull()
const overlaps = GeoOperations.calculateOverlap(polyGrb, [polyHouse])
expect(overlaps).empty

View file

@ -1,8 +1,7 @@
import { describe } from "mocha"
import { expect } from "chai"
import AllImageProviders from "../../../Logic/ImageProviders/AllImageProviders"
import { UIEventSource } from "../../../Logic/UIEventSource"
import { Utils } from "../../../Utils"
import { describe, expect, it } from "vitest"
describe("ImageProviders", () => {
it("should work on a variaty of inputs", () => {
@ -16,9 +15,9 @@ describe("ImageProviders", () => {
if (img === undefined) {
throw "No image found"
}
expect(img.url).deep.equal(url)
expect(img.url).toEqual(url)
if (providerName) {
expect(providerName).deep.equal(img.provider.constructor.name)
expect(providerName).toEqual(img.provider.constructor.name)
}
console.log("OK")
})

View file

@ -1,5 +1,3 @@
import { describe } from "mocha"
import { expect } from "chai"
import { Utils } from "../../../../Utils"
import { OsmObject, OsmRelation } from "../../../../Logic/Osm/OsmObject"
import {
@ -7,6 +5,7 @@ import {
TurnRestrictionRSH,
} from "../../../../Logic/Osm/Actions/RelationSplitHandler"
import { Changes } from "../../../../Logic/Osm/Changes"
import { describe, expect, it } from "vitest"
describe("RelationSplitHandler", () => {
Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/node/1124134958/ways", {
@ -651,10 +650,8 @@ describe("RelationSplitHandler", () => {
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
const allIds = changeDescription[0].changes["members"].map((m) => m.ref).join(",")
const expected = "687866206,295132739,-1,690497698"
expect(
allIds.indexOf(expected) >= 0,
"didn't find the expected order of ids in the relation to test"
).true
// "didn't find the expected order of ids in the relation to test"
expect(allIds.indexOf(expected) >= 0).toBe(true)
})
it("should split turn restrictions (split of https://www.openstreetmap.org/way/143298912)", async () => {
@ -705,7 +702,7 @@ describe("RelationSplitHandler", () => {
.map((m) => m.type + "/" + m.ref + "-->" + m.role)
.join(",")
const expected = "way/318616190-->from,node/1407529979-->via,way/-1-->to"
expect(allIds).deep.equal(expected)
expect(allIds).toEqual(expected)
// Reversing the ids has no effect
const splitterReverse = new TurnRestrictionRSH(
@ -719,6 +716,6 @@ describe("RelationSplitHandler", () => {
"no-theme"
)
const changesReverse = await splitterReverse.CreateChangeDescriptions(new Changes())
expect(changesReverse.length).deep.equal(0)
expect(changesReverse.length).toEqual(0)
})
})

View file

@ -1,13 +1,11 @@
import { describe } from "mocha"
import { expect } from "chai"
import Minimap from "../../../../UI/Base/Minimap"
import { Utils } from "../../../../Utils"
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"
import State from "../../../../State"
import { BBox } from "../../../../Logic/BBox"
import ReplaceGeometryAction from "../../../../Logic/Osm/Actions/ReplaceGeometryAction"
import ShowDataLayerImplementation from "../../../../UI/ShowDataLayer/ShowDataLayerImplementation"
import ShowDataLayer from "../../../../UI/ShowDataLayer/ShowDataLayer"
import { describe, expect, it } from "vitest"
describe("ReplaceGeometryAction", () => {
const grbStripped = {
@ -896,7 +894,7 @@ describe("ReplaceGeometryAction", () => {
})
const closestIds = await action.GetClosestIds()
expect(closestIds.closestIds).deep.equal([
expect(closestIds.closestIds).toEqual([
9219979643,
1728823481,
4978289383,
@ -910,14 +908,14 @@ describe("ReplaceGeometryAction", () => {
undefined,
])
expect(closestIds.reprojectedNodes.size).deep.equal(1)
expect(closestIds.reprojectedNodes.size).toEqual(1)
const reproj = closestIds.reprojectedNodes.get(1728823549)
expect(reproj.projectAfterIndex).deep.equal(1)
expect(reproj.newLon).deep.equal(3.2168880864669203)
expect(reproj.newLat).deep.equal(51.214739524104694)
expect(closestIds.detachedNodes.size).deep.equal(0)
expect(reproj.projectAfterIndex).toEqual(1)
expect(reproj.newLon).toEqual(3.2168880864669203)
expect(reproj.newLat).toEqual(51.214739524104694)
expect(closestIds.detachedNodes.size).toEqual(0)
const changes = await action.Perform(state.changes)
expect(changes[11].changes["coordinates"]).deep.equal([
expect(changes[11].changes["coordinates"]).toEqual([
[3.216690793633461, 51.21474084112525],
[3.2167256623506546, 51.214696737309964],
[3.2168880864669203, 51.214739524104694],

View file

@ -1,8 +1,7 @@
import { describe } from "mocha"
import { expect } from "chai"
import { Utils } from "../../../../Utils"
import SplitAction from "../../../../Logic/Osm/Actions/SplitAction"
import { Changes } from "../../../../Logic/Osm/Changes"
import { describe, expect, it } from "vitest"
describe("SplitAction", () => {
{
@ -2690,20 +2689,20 @@ describe("SplitAction", () => {
})
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
expect(changeDescription[0].type).eq("node")
expect(changeDescription[0].id).eq(-1)
expect(changeDescription[0].changes["lat"]).eq(51.181710380278176)
expect(changeDescription[0].changes["lon"]).eq(3.246733546257019)
expect(changeDescription[1].type).eq("way")
expect(changeDescription[1].id).eq(-2)
expect(changeDescription[1].changes["coordinates"].length).eq(6)
expect(changeDescription[1].changes["coordinates"][5][0]).eq(splitPoint[0])
expect(changeDescription[1].changes["coordinates"][5][1]).eq(splitPoint[1])
expect(changeDescription[2].type).eq("way")
expect(changeDescription[2].id).eq(295132739)
expect(changeDescription[2].changes["coordinates"].length).eq(10)
expect(changeDescription[2].changes["coordinates"][0][0]).eq(splitPoint[0])
expect(changeDescription[2].changes["coordinates"][0][1]).eq(splitPoint[1])
expect(changeDescription[0].type).toBe("node")
expect(changeDescription[0].id).toBe(-1)
expect(changeDescription[0].changes["lat"]).toBe(51.181710380278176)
expect(changeDescription[0].changes["lon"]).toBe(3.246733546257019)
expect(changeDescription[1].type).toBe("way")
expect(changeDescription[1].id).toBe(-2)
expect(changeDescription[1].changes["coordinates"].length).toBe(6)
expect(changeDescription[1].changes["coordinates"][5][0]).toBe(splitPoint[0])
expect(changeDescription[1].changes["coordinates"][5][1]).toBe(splitPoint[1])
expect(changeDescription[2].type).toBe("way")
expect(changeDescription[2].id).toBe(295132739)
expect(changeDescription[2].changes["coordinates"].length).toBe(10)
expect(changeDescription[2].changes["coordinates"][0][0]).toBe(splitPoint[0])
expect(changeDescription[2].changes["coordinates"][0][1]).toBe(splitPoint[1])
})
it("split 295132739 on already existing node", async () => {
@ -2715,13 +2714,13 @@ describe("SplitAction", () => {
})
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
expect(changeDescription.length).eq(2)
expect(changeDescription[0].type).eq("way")
expect(changeDescription[1].type).eq("way")
expect(changeDescription.length).toBe(2)
expect(changeDescription[0].type).toBe("way")
expect(changeDescription[1].type).toBe("way")
expect(
changeDescription[0].changes["nodes"][changeDescription[0].changes["nodes"].length - 1]
).eq(changeDescription[1].changes["nodes"][0])
expect(changeDescription[1].changes["nodes"][0]).eq(1507524610)
).toBe(changeDescription[1].changes["nodes"][0])
expect(changeDescription[1].changes["nodes"][0]).toBe(1507524610)
})
it("split 61435323 on already existing node", async () => {
@ -2733,8 +2732,8 @@ describe("SplitAction", () => {
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
// Should be a new node
expect(changeDescription[0].type).eq("node")
expect(changeDescription[3].type).eq("relation")
expect(changeDescription[0].type).toBe("node")
expect(changeDescription[3].type).toBe("relation")
})
it("Split test line", async () => {
@ -2764,11 +2763,11 @@ describe("SplitAction", () => {
8715440363
*/
expect(changes[0].changes["nodes"]).deep.equal([
expect(changes[0].changes["nodes"]).toEqual([
6490126559, 8715440375, 8715440374, 8715440373, 8715440372, 8715440371, 8715440370,
8715440369, 8715440368,
])
expect(changes[1].changes["nodes"]).deep.equal([
expect(changes[1].changes["nodes"]).toEqual([
8715440368, 8715440367, 8715440366, 8715440365, 8715440364, 8715440363,
])
})
@ -2784,14 +2783,14 @@ describe("SplitAction", () => {
const changes = await splitAction.Perform(new Changes())
// THe first change is the creation of the new node
expect(changes[0].type).deep.equal("node")
expect(changes[0].id).deep.equal(-1)
expect(changes[0].type).toEqual("node")
expect(changes[0].id).toEqual(-1)
expect(changes[1].changes["nodes"]).deep.equal([
expect(changes[1].changes["nodes"]).toEqual([
6490126559, 8715440375, 8715440374, 8715440373, 8715440372, 8715440371, 8715440370,
8715440369, -1,
])
expect(changes[2].changes["nodes"]).deep.equal([
expect(changes[2].changes["nodes"]).toEqual([
-1, 8715440368, 8715440367, 8715440366, 8715440365, 8715440364, 8715440363,
])
})

View file

@ -1,6 +1,6 @@
import { expect } from "chai"
import { ChangeDescription } from "../../../Logic/Osm/Actions/ChangeDescription"
import { Changes } from "../../../Logic/Osm/Changes"
import { expect, it } from "vitest"
it("Generate preXML from changeDescriptions", () => {
const changeDescrs: ChangeDescription[] = [
@ -29,11 +29,11 @@ it("Generate preXML from changeDescriptions", () => {
]
const c = new Changes()
const descr = c.CreateChangesetObjects(changeDescrs, [])
expect(descr.modifiedObjects).length(0)
expect(descr.deletedObjects).length(0)
expect(descr.newObjects).length(1)
expect(descr.modifiedObjects).toHaveLength(0)
expect(descr.deletedObjects).toHaveLength(0)
expect(descr.newObjects).toHaveLength(1)
const ch = descr.newObjects[0]
expect(ch.tags["foo"]).eq("bar")
expect(ch.tags["someKey"]).eq("someValue")
expect(ch.tags["foo"]).toBe("bar")
expect(ch.tags["someKey"]).toBe("someValue")
})

View file

@ -1,11 +1,10 @@
import { describe } from "mocha"
import { expect } from "chai"
import { Utils } from "../../../Utils"
import { ChangesetHandler, ChangesetTag } from "../../../Logic/Osm/ChangesetHandler"
import { UIEventSource } from "../../../Logic/UIEventSource"
import { OsmConnection } from "../../../Logic/Osm/OsmConnection"
import { ElementStorage } from "../../../Logic/ElementStorage"
import { Changes } from "../../../Logic/Osm/Changes"
import { describe, expect, it } from "vitest"
describe("ChangesetHanlder", () => {
describe("RewriteTagsOf", () => {
@ -56,18 +55,16 @@ describe("ChangesetHanlder", () => {
oldChangesetMeta
)
const d = Utils.asDict(rewritten)
expect(d.size).deep.equal(10)
expect(d.get("answer")).deep.equal("5")
expect(d.get("comment")).deep.equal(
"Adding data with #MapComplete for theme #toerisme_vlaanderen"
)
expect(d.get("created_by")).deep.equal("MapComplete 0.16.6")
expect(d.get("host")).deep.equal("https://mapcomplete.osm.be/toerisme_vlaanderen.html")
expect(d.get("imagery")).deep.equal("osm")
expect(d.get("source")).deep.equal("survey")
expect(d.get("source:node/-1")).deep.equal("note/1234")
expect(d.get("theme")).deep.equal("toerisme_vlaanderen")
expect(d.get("newTag")).deep.equal("newValue")
expect(d.size).toEqual(10)
expect(d.get("answer")).toEqual("5")
expect(d.get("comment")).toEqual("Adding data with #MapComplete for theme #toerisme_vlaanderen")
expect(d.get("created_by")).toEqual("MapComplete 0.16.6")
expect(d.get("host")).toEqual("https://mapcomplete.osm.be/toerisme_vlaanderen.html")
expect(d.get("imagery")).toEqual("osm")
expect(d.get("source")).toEqual("survey")
expect(d.get("source:node/-1")).toEqual("note/1234")
expect(d.get("theme")).toEqual("toerisme_vlaanderen")
expect(d.get("newTag")).toEqual("newValue")
})
it("should aggregate numeric tags", () => {
const changesetHandler = new ChangesetHandler(
@ -116,17 +113,15 @@ describe("ChangesetHanlder", () => {
)
const d = Utils.asDict(rewritten)
expect(d.size).deep.equal(9)
expect(d.get("answer")).deep.equal("42")
expect(d.get("comment")).deep.equal(
"Adding data with #MapComplete for theme #toerisme_vlaanderen"
)
expect(d.get("created_by")).deep.equal("MapComplete 0.16.6")
expect(d.get("host")).deep.equal("https://mapcomplete.osm.be/toerisme_vlaanderen.html")
expect(d.get("imagery")).deep.equal("osm")
expect(d.get("source")).deep.equal("survey")
expect(d.get("source:node/-1")).deep.equal("note/1234")
expect(d.get("theme")).deep.equal("toerisme_vlaanderen")
expect(d.size).toEqual(9)
expect(d.get("answer")).toEqual("42")
expect(d.get("comment")).toEqual("Adding data with #MapComplete for theme #toerisme_vlaanderen")
expect(d.get("created_by")).toEqual("MapComplete 0.16.6")
expect(d.get("host")).toEqual("https://mapcomplete.osm.be/toerisme_vlaanderen.html")
expect(d.get("imagery")).toEqual("osm")
expect(d.get("source")).toEqual("survey")
expect(d.get("source:node/-1")).toEqual("note/1234")
expect(d.get("theme")).toEqual("toerisme_vlaanderen")
})
it("should rewrite special reasons with the correct ID", () => {
const changesetHandler = new ChangesetHandler(
@ -169,17 +164,15 @@ describe("ChangesetHanlder", () => {
)
const d = Utils.asDict(rewritten)
expect(d.size).deep.equal(9)
expect(d.get("answer")).deep.equal("5")
expect(d.get("comment")).deep.equal(
"Adding data with #MapComplete for theme #toerisme_vlaanderen"
)
expect(d.get("created_by")).deep.equal("MapComplete 0.16.6")
expect(d.get("host")).deep.equal("https://mapcomplete.osm.be/toerisme_vlaanderen.html")
expect(d.get("imagery")).deep.equal("osm")
expect(d.get("source")).deep.equal("survey")
expect(d.get("source:node/42")).deep.equal("note/1234")
expect(d.get("theme")).deep.equal("toerisme_vlaanderen")
expect(d.size).toEqual(9)
expect(d.get("answer")).toEqual("5")
expect(d.get("comment")).toEqual("Adding data with #MapComplete for theme #toerisme_vlaanderen")
expect(d.get("created_by")).toEqual("MapComplete 0.16.6")
expect(d.get("host")).toEqual("https://mapcomplete.osm.be/toerisme_vlaanderen.html")
expect(d.get("imagery")).toEqual("osm")
expect(d.get("source")).toEqual("survey")
expect(d.get("source:node/42")).toEqual("note/1234")
expect(d.get("theme")).toEqual("toerisme_vlaanderen")
})
})
@ -200,12 +193,13 @@ describe("ChangesetHanlder", () => {
extraMetaTags,
changes
)
expect(hasSpecialMotivationChanges, "Special rewrite did not trigger").true
// "Special rewrite did not trigger"
expect(hasSpecialMotivationChanges).toBe(true)
// Rewritten inline by rewriteMetaTags
expect(extraMetaTags[1].key).deep.equal("source:node/42")
expect(extraMetaTags[1].value).deep.equal("note/1234")
expect(extraMetaTags[0].key).deep.equal("created_by")
expect(extraMetaTags[0].value).deep.equal("mapcomplete")
expect(extraMetaTags[1].key).toEqual("source:node/42")
expect(extraMetaTags[1].value).toEqual("note/1234")
expect(extraMetaTags[0].key).toEqual("created_by")
expect(extraMetaTags[0].value).toEqual("mapcomplete")
})
})
})

View file

@ -1,9 +1,8 @@
import { describe } from "mocha"
import { expect } from "chai"
import { OsmObject } from "../../../Logic/Osm/OsmObject"
import { Utils } from "../../../Utils"
import ScriptUtils from "../../../scripts/ScriptUtils"
import { readFileSync } from "fs"
import { describe, expect, it } from "vitest"
describe("OsmObject", () => {
describe("download referencing ways", () => {
@ -81,8 +80,8 @@ describe("OsmObject", () => {
it("should download referencing ways", async () => {
const ways = await OsmObject.DownloadReferencingWays("node/1124134958")
expect(ways).not.undefined
expect(ways).length(4)
expect(ways).toBeDefined()
expect(ways).toHaveLength(4)
})
it("should download full OSM-relations", async () => {
@ -93,7 +92,7 @@ describe("OsmObject", () => {
)
const r = await OsmObject.DownloadObjectAsync("relation/5759328").then((x) => x)
const geojson = r.asGeoJson()
expect(geojson.geometry.type).eq("MultiPolygon")
expect(geojson.geometry.type).toBe("MultiPolygon")
})
})
})

View file

@ -1,7 +1,6 @@
import { describe } from "mocha"
import { expect } from "chai"
import { TagUtils } from "../../../Logic/Tags/TagUtils"
import { Tag } from "../../../Logic/Tags/Tag"
import { describe, expect, it } from "vitest"
describe("Lazy object properties", () => {
it("should be matche by a normal tag", () => {
@ -16,7 +15,7 @@ describe("Lazy object properties", () => {
},
})
const filter = new Tag("_key", "yes")
expect(filter.matchesProperties(properties)).true
expect(filter.matchesProperties(properties)).toBe(true)
})
it("should be matched by a RegexTag", () => {
@ -31,6 +30,6 @@ describe("Lazy object properties", () => {
},
})
const filter = TagUtils.Tag("_key~*")
expect(filter.matchesProperties(properties)).true
expect(filter.matchesProperties(properties)).toBe(true)
})
})

View file

@ -1,30 +1,29 @@
import { describe } from "mocha"
import { expect } from "chai"
import { TagsFilter } from "../../../Logic/Tags/TagsFilter"
import { And } from "../../../Logic/Tags/And"
import { Tag } from "../../../Logic/Tags/Tag"
import { TagUtils } from "../../../Logic/Tags/TagUtils"
import { Or } from "../../../Logic/Tags/Or"
import { RegexTag } from "../../../Logic/Tags/RegexTag"
import { describe, expect, it } from "vitest"
describe("Tag optimalization", () => {
describe("And", () => {
it("with condition and nested and should be flattened", () => {
const t = new And([new And([new Tag("x", "y")]), new Tag("a", "b")])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq(`a=b&x=y`)
expect(TagUtils.toString(opt)).toBe(`a=b&x=y`)
})
it("should be 'true' if no conditions are given", () => {
const t = new And([])
const opt = t.optimize()
expect(opt).eq(true)
expect(opt).toBe(true)
})
it("should return false on conflicting tags", () => {
const t = new And([new Tag("key", "a"), new Tag("key", "b")])
const opt = t.optimize()
expect(opt).eq(false)
expect(opt).toBe(false)
})
it("with nested ors and common property should be extracted", () => {
@ -35,7 +34,7 @@ describe("Tag optimalization", () => {
new Or([new Tag("x", "y"), new Tag("c", "d")]),
])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq("foo=bar& (x=y| (a=b&c=d) )")
expect(TagUtils.toString(opt)).toBe("foo=bar& (x=y| (a=b&c=d) )")
})
it("with nested ors and common regextag should be extracted", () => {
@ -46,7 +45,7 @@ describe("Tag optimalization", () => {
new Or([new RegexTag("x", "y"), new RegexTag("c", "d")]),
])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq("foo=bar& ( (a=b&c=d) |x=y)")
expect(TagUtils.toString(opt)).toBe("foo=bar& ( (a=b&c=d) |x=y)")
})
it("with nested ors and inverted regextags should _not_ be extracted", () => {
@ -57,19 +56,19 @@ describe("Tag optimalization", () => {
new Or([new RegexTag("x", "y", true), new RegexTag("c", "d")]),
])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq("foo=bar& (a=b|x=y) & (c=d|x!=y)")
expect(TagUtils.toString(opt)).toBe("foo=bar& (a=b|x=y) & (c=d|x!=y)")
})
it("should move regextag to the end", () => {
const t = new And([new RegexTag("x", "y"), new Tag("a", "b")])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq("a=b&x=y")
expect(TagUtils.toString(opt)).toBe("a=b&x=y")
})
it("should sort tags by their popularity (least popular first)", () => {
const t = new And([new Tag("bicycle", "yes"), new Tag("amenity", "binoculars")])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq("amenity=binoculars&bicycle=yes")
expect(TagUtils.toString(opt)).toBe("amenity=binoculars&bicycle=yes")
})
it("should optimize nested ORs", () => {
@ -163,17 +162,17 @@ describe("Tag optimalization", () => {
"leisure=playground&playground!=forest",
]
expect((<Or>opt).or.map((f) => TagUtils.toString(f))).deep.eq(expected)
expect((<Or>opt).or.map((f) => TagUtils.toString(f))).toEqual(expected)
})
it("should detect conflicting tags", () => {
const q = new And([new Tag("key", "value"), new RegexTag("key", "value", true)])
expect(q.optimize()).eq(false)
expect(q.optimize()).toBe(false)
})
it("should detect conflicting tags with a regex", () => {
const q = new And([new Tag("key", "value"), new RegexTag("key", /value/, true)])
expect(q.optimize()).eq(false)
expect(q.optimize()).toBe(false)
})
})
@ -184,17 +183,17 @@ describe("Tag optimalization", () => {
new And([new Tag("foo", "bar"), new Tag("x", "y")]),
])
const opt = <TagsFilter>t.optimize()
expect(TagUtils.toString(opt)).eq("foo=bar")
expect(TagUtils.toString(opt)).toBe("foo=bar")
})
it("should flatten nested ors", () => {
const t = new Or([new Or([new Tag("x", "y")])]).optimize()
expect(t).deep.eq(new Tag("x", "y"))
expect(t).toEqual(new Tag("x", "y"))
})
it("should flatten nested ors", () => {
const t = new Or([new Tag("a", "b"), new Or([new Tag("x", "y")])]).optimize()
expect(t).deep.eq(new Or([new Tag("a", "b"), new Tag("x", "y")]))
expect(t).toEqual(new Or([new Tag("a", "b"), new Tag("x", "y")]))
})
})
@ -259,33 +258,31 @@ describe("Tag optimalization", () => {
)
*/
expect(opt).deep.eq(
TagUtils.Tag({
or: [
"club=climbing",
{
and: ["sport=climbing", { or: ["club~*", "office~*"] }],
},
{
and: [
"sport=climbing",
{
or: [
"leisure=sports_centre",
{
and: [
"climbing!~route",
"climbing!=route_top",
"climbing!=route_bottom",
"leisure!~sports_centre",
],
},
],
},
],
},
],
})
)
expect(opt).toEqual(TagUtils.Tag({
or: [
"club=climbing",
{
and: ["sport=climbing", { or: ["club~*", "office~*"] }],
},
{
and: [
"sport=climbing",
{
or: [
"leisure=sports_centre",
{
and: [
"climbing!~route",
"climbing!=route_top",
"climbing!=route_bottom",
"leisure!~sports_centre",
],
},
],
},
],
},
],
}))
})
})

View file

@ -1,12 +1,12 @@
import { describe } from "mocha"
import { expect } from "chai"
import { TagUtils } from "../../../Logic/Tags/TagUtils"
import { equal } from "assert"
import { describe, expect, it } from "vitest"
describe("TagUtils", () => {
describe("ParseTag", () => {
it("should refuse a key!=* tag", () => {
expect(() => TagUtils.Tag("key!=*")).to.throw()
expect(() => TagUtils.Tag("key!=*")).toThrowError()
})
it("should handle compare tag <=5", () => {
@ -42,8 +42,8 @@ describe("TagUtils", () => {
it("should handle date comparison tags", () => {
const filter = TagUtils.Tag("date_created<2022-01-07")
expect(filter.matchesProperties({ date_created: "2022-01-08" })).false
expect(filter.matchesProperties({ date_created: "2022-01-01" })).true
expect(filter.matchesProperties({ date_created: "2022-01-08" })).toBe(false)
expect(filter.matchesProperties({ date_created: "2022-01-01" })).toBe(true)
})
})
})

View file

@ -1,7 +1,6 @@
import { describe } from "mocha"
import { expect } from "chai"
import { Utils } from "../../../Utils"
import Wikidata from "../../../Logic/Web/Wikidata"
import { describe, expect, it } from "vitest"
const Q140 = {
entities: {
@ -9464,21 +9463,20 @@ Utils.injectJsonDownloadForTests(
describe("Wikidata", () => {
it("should download Q140 (lion)", async () => {
const wikidata = await Wikidata.LoadWikidataEntryAsync("Q140")
expect(wikidata.claims.get("P18")).length(2)
expect(wikidata.claims.get("P18")).toHaveLength(2)
})
it("should download wikidata", async () => {
const wdata = await Wikidata.LoadWikidataEntryAsync(14517013)
expect(wdata.wikisites).to.have.key("nl")
expect(wdata.wikisites.get("nl")).eq("Vredesmolen")
expect(wdata.wikisites.get("nl")).toBe("Vredesmolen")
})
it("should download a lexeme", async () => {
const response = await Wikidata.LoadWikidataEntryAsync(
"https://www.wikidata.org/wiki/Lexeme:L614072"
)
expect(response).not.undefined
expect(response.labels).to.have.key("nl")
expect(response.labels).to.contains("Groen")
expect(response).toBeDefined()
expect(response.labels).toEqual(new Map<string, string>([["nl", "Groen"]]))
})
})