Refactoring: move download functionality for OsmObjects into a new object
This commit is contained in:
parent
8eb2c68f79
commit
1f9aacfb29
23 changed files with 633 additions and 901 deletions
|
@ -1,11 +1,14 @@
|
|||
import { Utils } from "../../../../Utils"
|
||||
import { OsmObject, OsmRelation } from "../../../../Logic/Osm/OsmObject"
|
||||
import { OsmRelation } from "../../../../Logic/Osm/OsmObject"
|
||||
import {
|
||||
InPlaceReplacedmentRTSH,
|
||||
TurnRestrictionRSH,
|
||||
} from "../../../../Logic/Osm/Actions/RelationSplitHandler"
|
||||
import { Changes } from "../../../../Logic/Osm/Changes"
|
||||
import { describe, expect, it } from "vitest"
|
||||
import OsmObjectDownloader from "../../../../Logic/Osm/OsmObjectDownloader"
|
||||
import { ImmutableStore } from "../../../../Logic/UIEventSource"
|
||||
import { OsmConnection } from "../../../../Logic/Osm/OsmConnection"
|
||||
|
||||
describe("RelationSplitHandler", () => {
|
||||
Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/node/1124134958/ways", {
|
||||
|
@ -624,8 +627,9 @@ describe("RelationSplitHandler", () => {
|
|||
it("should split all cycling relation (split 295132739)", async () => {
|
||||
// Lets mimic a split action of https://www.openstreetmap.org/way/295132739
|
||||
|
||||
const downloader = new OsmObjectDownloader()
|
||||
const relation: OsmRelation = <OsmRelation>(
|
||||
await OsmObject.DownloadObjectAsync("relation/9572808")
|
||||
await downloader.DownloadObjectAsync("relation/9572808")
|
||||
)
|
||||
const originalNodeIds = [
|
||||
5273988967, 170497153, 1507524582, 4524321710, 170497155, 170497157, 170497158,
|
||||
|
@ -645,9 +649,13 @@ describe("RelationSplitHandler", () => {
|
|||
originalNodes: originalNodeIds,
|
||||
allWaysNodesInOrder: withSplit,
|
||||
},
|
||||
"no-theme"
|
||||
"no-theme",
|
||||
downloader
|
||||
)
|
||||
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
|
||||
const changeDescription = await splitter.CreateChangeDescriptions(new Changes({
|
||||
dryRun: new ImmutableStore(false),
|
||||
osmConnection: new OsmConnection()
|
||||
}))
|
||||
const allIds = changeDescription[0].changes["members"].map((m) => m.ref).join(",")
|
||||
const expected = "687866206,295132739,-1,690497698"
|
||||
// "didn't find the expected order of ids in the relation to test"
|
||||
|
@ -655,8 +663,9 @@ describe("RelationSplitHandler", () => {
|
|||
})
|
||||
|
||||
it("should split turn restrictions (split of https://www.openstreetmap.org/way/143298912)", async () => {
|
||||
const downloader = new OsmObjectDownloader()
|
||||
const relation: OsmRelation = <OsmRelation>(
|
||||
await OsmObject.DownloadObjectAsync("relation/4374576")
|
||||
await downloader.DownloadObjectAsync("relation/4374576")
|
||||
)
|
||||
const originalNodeIds = [
|
||||
1407529979, 1974988033, 3250129361, 1634435395, 8493044168, 875668688, 1634435396,
|
||||
|
@ -695,9 +704,13 @@ describe("RelationSplitHandler", () => {
|
|||
originalNodes: originalNodeIds,
|
||||
allWaysNodesInOrder: withSplit,
|
||||
},
|
||||
"no-theme"
|
||||
"no-theme",
|
||||
downloader
|
||||
)
|
||||
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
|
||||
const changeDescription = await splitter.CreateChangeDescriptions(new Changes({
|
||||
dryRun: new ImmutableStore(false),
|
||||
osmConnection: new OsmConnection()
|
||||
}))
|
||||
const allIds = changeDescription[0].changes["members"]
|
||||
.map((m) => m.type + "/" + m.ref + "-->" + m.role)
|
||||
.join(",")
|
||||
|
@ -713,9 +726,15 @@ describe("RelationSplitHandler", () => {
|
|||
originalNodes: originalNodeIds,
|
||||
allWaysNodesInOrder: withSplit,
|
||||
},
|
||||
"no-theme"
|
||||
"no-theme",
|
||||
downloader
|
||||
)
|
||||
const changesReverse = await splitterReverse.CreateChangeDescriptions(
|
||||
new Changes({
|
||||
dryRun: new ImmutableStore(false),
|
||||
osmConnection: new OsmConnection(),
|
||||
})
|
||||
)
|
||||
const changesReverse = await splitterReverse.CreateChangeDescriptions(new Changes())
|
||||
expect(changesReverse.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Utils } from "../../../Utils"
|
|||
import ScriptUtils from "../../../scripts/ScriptUtils"
|
||||
import { readFileSync } from "fs"
|
||||
import { describe, expect, it } from "vitest"
|
||||
import OsmObjectDownloader from "../../../Logic/Osm/OsmObjectDownloader"
|
||||
|
||||
describe("OsmObject", () => {
|
||||
describe("download referencing ways", () => {
|
||||
|
@ -79,7 +80,8 @@ describe("OsmObject", () => {
|
|||
)
|
||||
|
||||
it("should download referencing ways", async () => {
|
||||
const ways = await OsmObject.DownloadReferencingWays("node/1124134958")
|
||||
const downloader = new OsmObjectDownloader()
|
||||
const ways = await downloader.DownloadReferencingWays("node/1124134958")
|
||||
expect(ways).toBeDefined()
|
||||
expect(ways).toHaveLength(4)
|
||||
})
|
||||
|
@ -90,7 +92,7 @@ describe("OsmObject", () => {
|
|||
"https://www.openstreetmap.org/api/0.6/relation/5759328/full",
|
||||
JSON.parse(readFileSync("./test/data/relation_5759328.json", { encoding: "utf-8" }))
|
||||
)
|
||||
const r = await OsmObject.DownloadObjectAsync("relation/5759328").then((x) => x)
|
||||
const r = await new OsmObjectDownloader().DownloadObjectAsync("relation/5759328").then((x) => x)
|
||||
const geojson = r.asGeoJson()
|
||||
expect(geojson.geometry.type).toBe("MultiPolygon")
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue