forked from MapComplete/MapComplete
Port tests to vitest
This commit is contained in:
parent
64a4d7e929
commit
228ceb120d
33 changed files with 673 additions and 326 deletions
|
@ -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,
|
||||
])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue