Merge feature/svelte into develop
This commit is contained in:
commit
868d476891
120 changed files with 5168 additions and 10657 deletions
|
@ -1,17 +0,0 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
|
||||
describe("TestSuite", () => {
|
||||
describe("function under test", () => {
|
||||
it("should work", () => {
|
||||
expect("abc").eq("abc")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("global test", async () => {
|
||||
expect("abc").eq("abc")
|
||||
expect(() => {
|
||||
throw "hi"
|
||||
}).throws(/hi/)
|
||||
})
|
|
@ -1,5 +1,5 @@
|
|||
import { describe } from "mocha"
|
||||
import { exec } from "child_process"
|
||||
import { describe, it } from "vitest"
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import * as turf from "@turf/turf"
|
||||
import { GeoOperations } from "../../Logic/GeoOperations"
|
||||
import { Feature, LineString, Polygon } from "geojson"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("GeoOperations", () => {
|
||||
describe("calculateOverlap", () => {
|
||||
|
@ -124,9 +123,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
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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,
|
||||
])
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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"]]))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { Utils } from "../../../../Utils"
|
||||
import { DesugaringContext } from "../../../../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
|
@ -7,6 +5,7 @@ import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagR
|
|||
import { PrepareLayer } from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import * as bookcases from "../../../../assets/layers/public_bookcase/public_bookcase.json"
|
||||
import CreateNoteImportLayer from "../../../../Models/ThemeConfig/Conversion/CreateNoteImportLayer"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("CreateNoteImportLayer", () => {
|
||||
it("should generate a layerconfig", () => {
|
||||
|
@ -24,18 +23,15 @@ describe("CreateNoteImportLayer", () => {
|
|||
layer,
|
||||
"ImportLayerGeneratorTest: convert"
|
||||
)
|
||||
expect(generatedLayer.isShown["and"][1].or[0].and[0]).deep.equal(
|
||||
"_tags~(^|.*;)amenity=public_bookcase($|;.*)"
|
||||
)
|
||||
expect(generatedLayer.minzoom <= layer.minzoom, "Zoomlevel is to high").true
|
||||
expect(generatedLayer.isShown["and"][1].or[0].and[0]).toEqual("_tags~(^|.*;)amenity=public_bookcase($|;.*)")
|
||||
// "Zoomlevel is to high"
|
||||
expect(generatedLayer.minzoom <= layer.minzoom).toBe(true)
|
||||
let renderings = Utils.NoNull(
|
||||
Utils.NoNull(
|
||||
generatedLayer.tagRenderings.map((tr) => (<TagRenderingConfigJson>tr).render)
|
||||
).map((render) => render["en"])
|
||||
)
|
||||
expect(
|
||||
renderings.some((r) => r.indexOf("import_button") > 0),
|
||||
"no import button found"
|
||||
).true
|
||||
// "no import button found"
|
||||
expect(renderings.some((r) => r.indexOf("import_button") > 0)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"
|
||||
import { FixLegacyTheme } from "../../../../Models/ThemeConfig/Conversion/LegacyJsonConvert"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("FixLegacyTheme", () => {
|
||||
it("should create a working theme config", () => {
|
||||
|
@ -135,8 +134,9 @@ describe("FixLegacyTheme", () => {
|
|||
],
|
||||
}
|
||||
const fixed = new FixLegacyTheme().convert(<any>walking_node_theme, "While testing")
|
||||
expect(fixed.errors, "Could not fix the legacy theme").empty
|
||||
// "Could not fix the legacy theme"
|
||||
expect(fixed.errors).empty
|
||||
const theme = new LayoutConfig(fixed.result, false)
|
||||
expect(theme).not.undefined
|
||||
expect(theme).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import LineRenderingConfigJson from "../../../../Models/ThemeConfig/Json/LineRenderingConfigJson"
|
||||
|
@ -10,6 +8,7 @@ import {
|
|||
} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import { QuestionableTagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||
import RewritableConfigJson from "../../../../Models/ThemeConfig/Json/RewritableConfigJson"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("ExpandRewrite", () => {
|
||||
it("should not allow overlapping keys", () => {
|
||||
|
@ -103,10 +102,10 @@ describe("PrepareLayer", () => {
|
|||
offset: 6,
|
||||
},
|
||||
],
|
||||
titleIcons: [{ render: "defaults", id: "defaults" }],
|
||||
titleIcons: [{ render: "icons.defaults", id: "iconsdefaults" }],
|
||||
}
|
||||
|
||||
expect(result).deep.eq(expected)
|
||||
expect(result).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -126,7 +125,7 @@ describe("RewriteSpecial", function () {
|
|||
},
|
||||
}
|
||||
const r = new RewriteSpecial().convert(tr, "test").result
|
||||
expect(r).to.deep.eq({
|
||||
expect(r).toEqual({
|
||||
id: "uk_addresses_import_button",
|
||||
render: {
|
||||
"*": "{import_button(address,urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$,Add this address,./assets/themes/uk_addresses/housenumber_add.svg,,,,none,)}",
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { LayoutConfigJson } from "../../../../Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { PrepareTheme } from "../../../../Models/ThemeConfig/Conversion/PrepareTheme"
|
||||
import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"
|
||||
import * as bookcaseLayer from "../../../../assets/generated/layers/public_bookcase.json"
|
||||
import bookcaseLayer from "../../../../assets/generated/layers/public_bookcase.json"
|
||||
import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig"
|
||||
import { ExtractImages } from "../../../../Models/ThemeConfig/Conversion/FixImages"
|
||||
import * as cyclofix from "../../../../assets/generated/themes/cyclofix.json"
|
||||
import cyclofix from "../../../../assets/generated/themes/cyclofix.json"
|
||||
import { Tag } from "../../../../Logic/Tags/Tag"
|
||||
import { DesugaringContext } from "../../../../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { And } from "../../../../Logic/Tags/And"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
const themeConfigJson: LayoutConfigJson = {
|
||||
description: "Descr",
|
||||
|
@ -38,7 +37,7 @@ const themeConfigJson: LayoutConfigJson = {
|
|||
describe("PrepareTheme", () => {
|
||||
it("should substitute layers", () => {
|
||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer)
|
||||
const theme = { ...themeConfigJson, layers: ["public_bookcase"] }
|
||||
const prepareStep = new PrepareTheme({
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
|
@ -49,14 +48,14 @@ describe("PrepareTheme", () => {
|
|||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.osmTags).deep.eq(
|
||||
expect(layerUnderTest.source.osmTags).toEqual(
|
||||
new And([new Tag("amenity", "public_bookcase")])
|
||||
)
|
||||
})
|
||||
|
||||
it("should apply override", () => {
|
||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer)
|
||||
let themeConfigJsonPrepared = new PrepareTheme({
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
sharedLayers: sharedLayers,
|
||||
|
@ -65,12 +64,12 @@ describe("PrepareTheme", () => {
|
|||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.geojsonSource).eq("xyz")
|
||||
expect(layerUnderTest.source.geojsonSource).toBe("xyz")
|
||||
})
|
||||
|
||||
it("should apply override", () => {
|
||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer["default"])
|
||||
sharedLayers.set("public_bookcase", bookcaseLayer)
|
||||
let themeConfigJsonPrepared = new PrepareTheme({
|
||||
tagRenderings: new Map<string, TagRenderingConfigJson>(),
|
||||
sharedLayers: sharedLayers,
|
||||
|
@ -85,7 +84,7 @@ describe("PrepareTheme", () => {
|
|||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.geojsonSource).eq("https://example.com/data.geojson")
|
||||
expect(layerUnderTest.source.geojsonSource).toBe("https://example.com/data.geojson")
|
||||
})
|
||||
|
||||
it("should remove names which are overriden with null", () => {
|
||||
|
@ -126,8 +125,8 @@ describe("PrepareTheme", () => {
|
|||
const rewritten = new PrepareTheme(ctx, {
|
||||
skipDefaultLayers: true,
|
||||
}).convertStrict(layout, "test")
|
||||
expect(rewritten.layers[0]).deep.eq(testLayer)
|
||||
expect(rewritten.layers[1]).deep.eq({
|
||||
expect(rewritten.layers[0]).toEqual(testLayer)
|
||||
expect(rewritten.layers[1]).toEqual({
|
||||
source: {
|
||||
osmTags: "x=y",
|
||||
},
|
||||
|
@ -142,8 +141,10 @@ describe("PrepareTheme", () => {
|
|||
|
||||
describe("ExtractImages", () => {
|
||||
it("should find all images in a themefile", () => {
|
||||
const images = new Set(
|
||||
new ExtractImages(true, new Map<string, any>()).convertStrict(<any>cyclofix, "test")
|
||||
const images = new Set<string>(
|
||||
new ExtractImages(true, new Set<string>())
|
||||
.convertStrict(<any>cyclofix, "test")
|
||||
.map((x) => x.path)
|
||||
)
|
||||
const expectedValues = [
|
||||
"./assets/layers/bike_repair_station/repair_station.svg",
|
||||
|
@ -158,7 +159,11 @@ describe("ExtractImages", () => {
|
|||
"close",
|
||||
]
|
||||
for (const expected of expectedValues) {
|
||||
expect(images).contains(expected)
|
||||
if (!images.has(expected)) {
|
||||
expect.fail(
|
||||
"Image " + expected + " not found (has:" + Array.from(images).join(",") + ")"
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import SourceConfig from "../../../Models/ThemeConfig/SourceConfig"
|
||||
import { TagUtils } from "../../../Logic/Tags/TagUtils"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("SourceConfig", () => {
|
||||
it("should throw an error on conflicting tags", () => {
|
||||
|
@ -14,6 +13,6 @@ describe("SourceConfig", () => {
|
|||
},
|
||||
false
|
||||
)
|
||||
}).to.throw(/tags are conflicting/)
|
||||
}).toThrowError(/tags are conflicting/)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import Locale from "../../../UI/i18n/Locale"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("TagRenderingConfig", () => {
|
||||
describe("isKnown", () => {
|
||||
|
@ -26,11 +25,11 @@ describe("TagRenderingConfig", () => {
|
|||
"Tests"
|
||||
)
|
||||
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).undefined
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).toBeUndefined()
|
||||
|
||||
expect(tr.GetRenderValue({ noname: "yes" })?.textFor("nl")).eq("Has no name")
|
||||
expect(tr.GetRenderValue({ name: "xyz" })?.textFor("nl")).eq("Ook een {name}")
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).undefined
|
||||
expect(tr.GetRenderValue({ noname: "yes" })?.textFor("nl")).toBe("Has no name")
|
||||
expect(tr.GetRenderValue({ name: "xyz" })?.textFor("nl")).toBe("Ook een {name}")
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should give a correct indication", () => {
|
||||
|
@ -63,8 +62,8 @@ describe("TagRenderingConfig", () => {
|
|||
}
|
||||
|
||||
const tagRendering = new TagRenderingConfig(config, "test")
|
||||
expect(tagRendering.IsKnown({ bottle: "yes" })).true
|
||||
expect(tagRendering.IsKnown({})).false
|
||||
expect(tagRendering.IsKnown({ bottle: "yes" })).toBe(true)
|
||||
expect(tagRendering.IsKnown({})).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { Unit } from "../../Models/Unit"
|
||||
import { Denomination } from "../../Models/Denomination"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("Unit", () => {
|
||||
it("should convert a value back and forth", () => {
|
||||
|
@ -19,10 +18,10 @@ describe("Unit", () => {
|
|||
)
|
||||
|
||||
const canonical = denomintion.canonicalValue("5", true)
|
||||
expect(canonical).eq("5 MW")
|
||||
expect(canonical).toBe("5 MW")
|
||||
const units = new Unit(["key"], [denomintion], false)
|
||||
const [detected, detectedDenom] = units.findDenomination("5 MW", () => "be")
|
||||
expect(detected).eq("5")
|
||||
expect(detectedDenom).eq(denomintion)
|
||||
expect(detected).toBe("5")
|
||||
expect(detectedDenom).toBe(denomintion)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { describe } from "mocha"
|
||||
import { TagRenderingConfigJson } from "../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import TagRenderingQuestion from "../../../UI/Popup/TagRenderingQuestion"
|
||||
import { UIEventSource } from "../../../Logic/UIEventSource"
|
||||
import { expect } from "chai"
|
||||
import Locale from "../../../UI/i18n/Locale"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("TagRenderingQuestion", () => {
|
||||
it("should have a freeform text field with the user defined placeholder", () => {
|
||||
|
@ -20,12 +19,13 @@ describe("TagRenderingQuestion", () => {
|
|||
}
|
||||
const config = new TagRenderingConfig(configJson, "test")
|
||||
const ui = new TagRenderingQuestion(new UIEventSource<any>({}), config)
|
||||
|
||||
const html = ui.ConstructElement()
|
||||
expect(html.getElementsByTagName("input")[0]["placeholder"]).eq(
|
||||
expect(html.getElementsByTagName("input")[0]["placeholder"]).toBe(
|
||||
"Some user defined placeholder"
|
||||
)
|
||||
})
|
||||
|
||||
}) //*/
|
||||
/*
|
||||
it("should have a freeform text field with a type explanation", () => {
|
||||
Locale.language.setData("en")
|
||||
const configJson = <TagRenderingConfigJson>{
|
||||
|
@ -40,8 +40,8 @@ describe("TagRenderingQuestion", () => {
|
|||
const config = new TagRenderingConfig(configJson, "test")
|
||||
const ui = new TagRenderingQuestion(new UIEventSource<any>({}), config)
|
||||
const html = ui.ConstructElement()
|
||||
expect(html.getElementsByTagName("input")[0]["placeholder"]).eq(
|
||||
expect(html.getElementsByTagName("input")[0]["placeholder"]).toBe(
|
||||
"capacity (a positive, whole number)"
|
||||
)
|
||||
})
|
||||
})//*/
|
||||
})
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import { describe } from "mocha"
|
||||
import SpecialVisualizations from "../../UI/SpecialVisualizations"
|
||||
import { expect } from "chai"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("SpecialVisualisations", () => {
|
||||
describe("predifined special visualisations", () => {
|
||||
it("should not have an argument called 'type'", () => {
|
||||
const specials = SpecialVisualizations.specialVisualizations
|
||||
for (const special of specials) {
|
||||
expect(special.funcName).not.eq(
|
||||
"type",
|
||||
"A special visualisation is not allowed to be named 'type', as this will conflict with the 'special'-blocks"
|
||||
)
|
||||
expect(special.funcName).not.toBe("type")
|
||||
|
||||
if (special.args === undefined) {
|
||||
throw (
|
||||
|
@ -20,10 +16,7 @@ describe("SpecialVisualisations", () => {
|
|||
}
|
||||
|
||||
for (const arg of special.args) {
|
||||
expect(arg.name).not.eq(
|
||||
"type",
|
||||
"An argument is not allowed to be called 'type', as this will conflict with the 'special'-blocks"
|
||||
)
|
||||
expect(arg.name).not.toBe("type")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { Utils } from "../Utils"
|
||||
import LZString from "lz-string"
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
const example = {
|
||||
id: "bookcases",
|
||||
|
@ -36,25 +35,25 @@ describe("Utils", () => {
|
|||
const str = JSON.stringify({ title: "abc", and: "xyz", render: "somevalue" })
|
||||
const minified = Utils.MinifyJSON(str)
|
||||
const restored = Utils.UnMinify(minified)
|
||||
expect(str).eq(restored)
|
||||
expect(str).toBe(restored)
|
||||
})
|
||||
it("should minify and restore the bookcase example", () => {
|
||||
const str = JSON.stringify(example, null, 0)
|
||||
const minified = Utils.MinifyJSON(str)
|
||||
const restored = Utils.UnMinify(minified)
|
||||
expect(str).eq(restored)
|
||||
expect(str).toBe(restored)
|
||||
})
|
||||
it("should LZ-compress a theme", () => {
|
||||
const str = JSON.stringify(example, null, 0)
|
||||
const minified = LZString.compressToBase64(Utils.MinifyJSON(str))
|
||||
const restored = Utils.UnMinify(LZString.decompressFromBase64(minified))
|
||||
expect(str).eq(restored)
|
||||
expect(str).toBe(restored)
|
||||
})
|
||||
it("shoud be able to decode the LZ-compression of a theme", () => {
|
||||
const str = JSON.stringify(example, null, 0)
|
||||
const minified = LZString.compressToBase64(str)
|
||||
const restored = LZString.decompressFromBase64(minified)
|
||||
expect(str).eq(restored)
|
||||
expect(str).toBe(restored)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { Utils } from "../../Utils"
|
||||
import { existsSync, mkdirSync, readFileSync, rmdirSync, unlinkSync } from "fs"
|
||||
import ScriptUtils from "../../scripts/ScriptUtils"
|
||||
import { main } from "../../scripts/generateCache"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
function initDownloads(query: string) {
|
||||
const d = {
|
||||
|
@ -7613,10 +7612,8 @@ describe("GenerateCache", () => {
|
|||
encoding: "utf8",
|
||||
})
|
||||
)
|
||||
expect(birdhides.features.length).deep.equal(5)
|
||||
expect(
|
||||
birdhides.features.some((f) => f.properties.id === "node/5158056232"),
|
||||
"Didn't find birdhide node/5158056232 "
|
||||
).true
|
||||
expect(birdhides.features.length).toEqual(5)
|
||||
// "Didn't find birdhide node/5158056232 "
|
||||
expect(birdhides.features.some((f) => f.properties.id === "node/5158056232")).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -2,40 +2,19 @@ import ScriptUtils from "../scripts/ScriptUtils"
|
|||
import { Utils } from "../Utils"
|
||||
import * as fakedom from "fake-dom"
|
||||
import Locale from "../UI/i18n/Locale"
|
||||
import { beforeEach } from "vitest"
|
||||
import { ReferencingWaysMetaTagger } from "../Logic/SimpleMetaTagger"
|
||||
|
||||
export const mochaHooks = {
|
||||
beforeEach(done) {
|
||||
ScriptUtils.fixUtils()
|
||||
Locale.language.setData("en")
|
||||
beforeEach(async () => {
|
||||
ScriptUtils.fixUtils()
|
||||
Locale.language.setData("en")
|
||||
ReferencingWaysMetaTagger.enabled = false
|
||||
if (fakedom === undefined || window === undefined) {
|
||||
throw "FakeDom not initialized"
|
||||
}
|
||||
|
||||
if (fakedom === undefined || window === undefined) {
|
||||
throw "FakeDom not initialized"
|
||||
}
|
||||
|
||||
// Block internet access
|
||||
const realDownloadFunc = Utils.externalDownloadFunction
|
||||
Utils.externalDownloadFunction = async (url) => {
|
||||
console.error(
|
||||
"Fetching ",
|
||||
url,
|
||||
"blocked in tests, use Utils.injectJsonDownloadForTests"
|
||||
)
|
||||
const data = await realDownloadFunc(url)
|
||||
console.log(
|
||||
"\n\n ----------- \nBLOCKED DATA\n Utils.injectJsonDownloadForTests(\n" + " ",
|
||||
JSON.stringify(url),
|
||||
", \n",
|
||||
" ",
|
||||
// JSON.stringify(data),
|
||||
"\n )\n------------------\n\n"
|
||||
)
|
||||
throw new Error(
|
||||
"Detected internet access for URL " +
|
||||
url +
|
||||
", please inject it with Utils.injectJsonDownloadForTests"
|
||||
)
|
||||
}
|
||||
|
||||
done()
|
||||
},
|
||||
}
|
||||
// Block internet access
|
||||
Utils.externalDownloadFunction = async (url) => {
|
||||
throw "Fetching " + url + "blocked in tests, use Utils.injectJsonDownloadForTests instead"
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue