Fix #1961, add test
This commit is contained in:
parent
23e563cdb7
commit
ad411f0943
3 changed files with 54 additions and 5 deletions
|
@ -2,12 +2,12 @@ import ChangeTagAction from "./ChangeTagAction"
|
||||||
import { Tag } from "../../Tags/Tag"
|
import { Tag } from "../../Tags/Tag"
|
||||||
import OsmChangeAction from "./OsmChangeAction"
|
import OsmChangeAction from "./OsmChangeAction"
|
||||||
import { ChangeDescription } from "./ChangeDescription"
|
import { ChangeDescription } from "./ChangeDescription"
|
||||||
import { Store } from "../../UIEventSource"
|
import { Store, UIEventSource } from "../../UIEventSource"
|
||||||
|
|
||||||
export default class LinkImageAction extends OsmChangeAction {
|
export default class LinkImageAction extends OsmChangeAction {
|
||||||
private readonly _proposedKey: "image" | "mapillary" | "wiki_commons" | string
|
private readonly _proposedKey: "image" | "mapillary" | "wiki_commons" | string
|
||||||
public readonly _url: string
|
public readonly _url: string
|
||||||
private readonly _currentTags: Store<Record<string, string>>
|
private readonly _currentTags: UIEventSource<Record<string, string>>
|
||||||
private readonly _meta: { theme: string; changeType: "add-image" | "link-image" }
|
private readonly _meta: { theme: string; changeType: "add-image" | "link-image" }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,7 @@ export default class LinkImageAction extends OsmChangeAction {
|
||||||
elementId: string,
|
elementId: string,
|
||||||
proposedKey: "image" | "mapillary" | "wiki_commons" | string,
|
proposedKey: "image" | "mapillary" | "wiki_commons" | string,
|
||||||
url: string,
|
url: string,
|
||||||
currentTags: Store<Record<string, string>>,
|
currentTags: UIEventSource<Record<string, string>>,
|
||||||
meta: {
|
meta: {
|
||||||
theme: string
|
theme: string
|
||||||
changeType: "add-image" | "link-image"
|
changeType: "add-image" | "link-image"
|
||||||
|
@ -51,6 +51,10 @@ export default class LinkImageAction extends OsmChangeAction {
|
||||||
currentTags,
|
currentTags,
|
||||||
this._meta
|
this._meta
|
||||||
)
|
)
|
||||||
|
this._currentTags.data[key] = url
|
||||||
|
this._currentTags.ping()
|
||||||
return tagChangeAction.CreateChangeDescriptions()
|
return tagChangeAction.CreateChangeDescriptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
id: Object.values(image.osmTags)[0],
|
id: Object.values(image.osmTags)[0],
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyLink(isLinked: boolean) {
|
async function applyLink(isLinked: boolean) {
|
||||||
console.log("Applying linked image", isLinked, targetValue)
|
console.log("Applying linked image", isLinked, targetValue)
|
||||||
const currentTags = tags.data
|
const currentTags = tags.data
|
||||||
const key = Object.keys(image.osmTags)[0]
|
const key = Object.keys(image.osmTags)[0]
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
theme: tags.data._orig_theme ?? state.layout.id,
|
theme: tags.data._orig_theme ?? state.layout.id,
|
||||||
changeType: "link-image",
|
changeType: "link-image",
|
||||||
})
|
})
|
||||||
state.changes.applyAction(action)
|
await state.changes.applyAction(action)
|
||||||
} else {
|
} else {
|
||||||
for (const k in currentTags) {
|
for (const k in currentTags) {
|
||||||
const v = currentTags[k]
|
const v = currentTags[k]
|
||||||
|
|
45
test/Logic/ActionInteraction.spec.ts
Normal file
45
test/Logic/ActionInteraction.spec.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import { ExtraFuncParams, ExtraFunctions } from "../../src/Logic/ExtraFunctions"
|
||||||
|
import { OsmFeature } from "../../src/Models/OsmFeature"
|
||||||
|
import { describe, expect, it } from "vitest"
|
||||||
|
import { Feature } from "geojson"
|
||||||
|
import { OsmConnection } from "../../src/Logic/Osm/OsmConnection"
|
||||||
|
import { ImmutableStore, UIEventSource } from "../../src/Logic/UIEventSource"
|
||||||
|
import { Changes } from "../../src/Logic/Osm/Changes"
|
||||||
|
import LinkImageAction from "../../src/Logic/Osm/Actions/LinkImageAction"
|
||||||
|
import FeaturePropertiesStore from "../../src/Logic/FeatureSource/Actors/FeaturePropertiesStore"
|
||||||
|
|
||||||
|
describe("Changes", () => {
|
||||||
|
it("should correctly apply the image tag if an image gets linked in between", async () => {
|
||||||
|
const dryRun = new ImmutableStore(true)
|
||||||
|
const osmConnection = new OsmConnection({ dryRun })
|
||||||
|
const changes = new Changes({ osmConnection, dryRun })
|
||||||
|
const id = "node/42"
|
||||||
|
const tags = new UIEventSource({ id, "amenity": "shop" })
|
||||||
|
const addImage = new LinkImageAction(id, "image", "https://example.org/uploaded_image", tags, {
|
||||||
|
theme: "test",
|
||||||
|
changeType: "add-image",
|
||||||
|
})
|
||||||
|
const linkImage = new LinkImageAction(id, "image", "https://example.org/image_to_link", tags, {
|
||||||
|
theme: "test",
|
||||||
|
changeType: "link-image",
|
||||||
|
})
|
||||||
|
|
||||||
|
await changes.applyAction(linkImage)
|
||||||
|
await changes.applyAction(addImage)
|
||||||
|
|
||||||
|
const data = tags.data
|
||||||
|
expect(data["image:0"]).toBe("https://example.org/uploaded_image")
|
||||||
|
expect(data["image"]).toBe("https://example.org/image_to_link")
|
||||||
|
|
||||||
|
const pending = changes.pendingChanges.data
|
||||||
|
|
||||||
|
const change0 = pending[0].tags[0]
|
||||||
|
expect(change0.k).toBe("image")
|
||||||
|
expect(change0.v).toBe("https://example.org/image_to_link")
|
||||||
|
|
||||||
|
const change1 = pending[1].tags[0]
|
||||||
|
expect(change1.k).toBe("image:0")
|
||||||
|
expect(change1.v).toBe("https://example.org/uploaded_image")
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue