From 7a87d41649d9b9e7b9f5963bb1e9eaf34455d4a5 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 12 Sep 2022 21:23:57 +0200 Subject: [PATCH] Add test --- Logic/Osm/Actions/DeleteAction.ts | 32 ++++++++++++++++++++++++------- UI/Popup/DeleteWizard.ts | 3 ++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Logic/Osm/Actions/DeleteAction.ts b/Logic/Osm/Actions/DeleteAction.ts index 2e0ae7fa02..6d89ce4498 100644 --- a/Logic/Osm/Actions/DeleteAction.ts +++ b/Logic/Osm/Actions/DeleteAction.ts @@ -7,6 +7,7 @@ import {TagsFilter} from "../../Tags/TagsFilter" import {And} from "../../Tags/And" import {Tag} from "../../Tags/Tag" import {Utils} from "../../../Utils"; +import {OsmId} from "../../../Models/OsmFeature"; export default class DeleteAction extends OsmChangeAction { private readonly _softDeletionTags: TagsFilter @@ -15,12 +16,13 @@ export default class DeleteAction extends OsmChangeAction { specialMotivation: string changeType: "deletion" } - private readonly _id: string - private _hardDelete: boolean + private readonly _id: OsmId + private readonly _hardDelete: boolean + constructor( - id: string, - softDeletionTags: TagsFilter, + id: OsmId, + softDeletionTags: TagsFilter | undefined, meta: { theme: string specialMotivation: string @@ -43,9 +45,25 @@ export default class DeleteAction extends OsmChangeAction { ])) } } - - public async CreateChangeDescriptions(changes: Changes): Promise { - const osmObject = await OsmObject.DownloadObjectAsync(this._id) + /** + * + * import {OsmNode} from "../OsmObject" + * + * const obj : OsmNode= new OsmNode(1) + * obj.tags = {id:"node/1",name:"Monte Piselli - San Giacomo"} + * const da = new DeleteAction("node/1", new Tag("man_made",""), {theme: "test", specialMotivation: "Testcase"}, true) + * const descr = await da.CreateChangeDescriptions(new Changes(), obj) + * descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase",changeType: "deletion"}, type: "node",id: 1 } + * + * // Must not crash if softDeletionTags are undefined + * const da = new DeleteAction("node/1", undefined, {theme: "test", specialMotivation: "Testcase"}, true) + * const obj : OsmNode= new OsmNode(1) + * obj.tags = {id:"node/1",name:"Monte Piselli - San Giacomo"} + * const descr = await da.CreateChangeDescriptions(new Changes(), obj) + * descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase", changeType: "deletion"}, type: "node",id: 1 } + */ + public async CreateChangeDescriptions(changes: Changes, object?: OsmObject): Promise { + const osmObject = object ?? await OsmObject.DownloadObjectAsync(this._id) if (this._hardDelete) { return [ diff --git a/UI/Popup/DeleteWizard.ts b/UI/Popup/DeleteWizard.ts index b217a82b8b..2988c40fd5 100644 --- a/UI/Popup/DeleteWizard.ts +++ b/UI/Popup/DeleteWizard.ts @@ -22,6 +22,7 @@ import Title from "../Base/Title" import { SubstitutedTranslation } from "../SubstitutedTranslation" import FeaturePipelineState from "../../Logic/State/FeaturePipelineState" import TagRenderingQuestion from "./TagRenderingQuestion" +import {OsmId} from "../../Models/OsmFeature"; export default class DeleteWizard extends Toggle { /** @@ -43,7 +44,7 @@ export default class DeleteWizard extends Toggle { * @param state: the state of the application * @param options softDeletionTags: the tags to apply if the user doesn't have permission to delete, e.g. 'disused:amenity=public_bookcase', 'amenity='. After applying, the element should not be picked up on the map anymore. If undefined, the wizard will only show up if the point can be (hard) deleted */ - constructor(id: string, state: FeaturePipelineState, options: DeleteConfig) { + constructor(id: OsmId, state: FeaturePipelineState, options: DeleteConfig) { const deleteAbility = new DeleteabilityChecker(id, state, options.neededChangesets) const tagsSource = state.allElements.getEventSourceById(id)