refactoring: Fix some tests
This commit is contained in:
parent
bef05481bd
commit
ea62b5b7ff
4 changed files with 30 additions and 24 deletions
|
@ -49,18 +49,22 @@ export default class DeleteAction extends OsmChangeAction {
|
|||
/**
|
||||
*
|
||||
* import {OsmNode} from "../OsmObject"
|
||||
* import { ImmutableStore } from "../../UIEventSource";
|
||||
* import { OsmConnection } from "../OsmConnection";
|
||||
*
|
||||
* 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)
|
||||
* const state = { dryRun: new ImmutableStore(true), osmConnection: new OsmConnection() }
|
||||
* const descr = await da.CreateChangeDescriptions(new Changes(state), 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)
|
||||
* const state = { dryRun: new ImmutableStore(true), osmConnection: new OsmConnection() }
|
||||
* const descr = await da.CreateChangeDescriptions(new Changes(state), obj)
|
||||
* descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase", changeType: "deletion"}, type: "node",id: 1 }
|
||||
*/
|
||||
public async CreateChangeDescriptions(
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { OsmNode, OsmObject, OsmRelation, OsmWay } from "./OsmObject"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
import { Store, UIEventSource } from "../UIEventSource"
|
||||
import Constants from "../../Models/Constants"
|
||||
import OsmChangeAction from "./Actions/OsmChangeAction"
|
||||
import { ChangeDescription, ChangeDescriptionTools } from "./Actions/ChangeDescription"
|
||||
import { Utils } from "../../Utils"
|
||||
import { LocalStorageSource } from "../Web/LocalStorageSource"
|
||||
import SimpleMetaTagger from "../SimpleMetaTagger"
|
||||
import {FeatureSource, IndexedFeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { FeatureSource, IndexedFeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { GeoLocationPointProperties } from "../State/GeoLocationState"
|
||||
import { GeoOperations } from "../GeoOperations"
|
||||
import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler"
|
||||
|
@ -25,10 +25,10 @@ export class Changes {
|
|||
public readonly pendingChanges: UIEventSource<ChangeDescription[]> =
|
||||
LocalStorageSource.GetParsed<ChangeDescription[]>("pending-changes", [])
|
||||
public readonly allChanges = new UIEventSource<ChangeDescription[]>(undefined)
|
||||
public readonly state: { allElements: IndexedFeatureSource; osmConnection: OsmConnection }
|
||||
public readonly state: { allElements?: IndexedFeatureSource; osmConnection: OsmConnection }
|
||||
public readonly extraComment: UIEventSource<string> = new UIEventSource(undefined)
|
||||
|
||||
private readonly historicalUserLocations: FeatureSource
|
||||
private readonly historicalUserLocations?: FeatureSource
|
||||
private _nextId: number = -1 // Newly assigned ID's are negative
|
||||
private readonly isUploading = new UIEventSource(false)
|
||||
private readonly previouslyCreated: OsmObject[] = []
|
||||
|
@ -36,12 +36,12 @@ export class Changes {
|
|||
private readonly _changesetHandler: ChangesetHandler
|
||||
|
||||
constructor(
|
||||
state?: {
|
||||
dryRun: UIEventSource<boolean>
|
||||
allElements: IndexedFeatureSource
|
||||
featurePropertiesStore: FeaturePropertiesStore
|
||||
state: {
|
||||
dryRun: Store<boolean>
|
||||
allElements?: IndexedFeatureSource
|
||||
featurePropertiesStore?: FeaturePropertiesStore
|
||||
osmConnection: OsmConnection
|
||||
historicalUserLocations: FeatureSource
|
||||
historicalUserLocations?: FeatureSource
|
||||
},
|
||||
leftRightSensitive: boolean = false
|
||||
) {
|
||||
|
@ -190,9 +190,11 @@ export class Changes {
|
|||
|
||||
const changedObjectCoordinates: [number, number][] = []
|
||||
|
||||
const feature = this.state.allElements.featuresById.data.get(change.mainObjectId)
|
||||
if (feature !== undefined) {
|
||||
changedObjectCoordinates.push(GeoOperations.centerpointCoordinates(feature))
|
||||
{
|
||||
const feature = this.state.allElements?.featuresById?.data.get(change.mainObjectId)
|
||||
if (feature !== undefined) {
|
||||
changedObjectCoordinates.push(GeoOperations.centerpointCoordinates(feature))
|
||||
}
|
||||
}
|
||||
|
||||
for (const changeDescription of changeDescriptions) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import escapeHtml from "escape-html"
|
||||
import UserDetails, { OsmConnection } from "./OsmConnection"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
import { Store, UIEventSource } from "../UIEventSource"
|
||||
import Locale from "../../UI/i18n/Locale"
|
||||
import Constants from "../../Models/Constants"
|
||||
import { Changes } from "./Changes"
|
||||
|
@ -16,7 +16,7 @@ export class ChangesetHandler {
|
|||
private readonly allElements: { addAlias: (id0: String, id1: string) => void }
|
||||
private osmConnection: OsmConnection
|
||||
private readonly changes: Changes
|
||||
private readonly _dryRun: UIEventSource<boolean>
|
||||
private readonly _dryRun: Store<boolean>
|
||||
private readonly userDetails: UIEventSource<UserDetails>
|
||||
private readonly backend: string
|
||||
|
||||
|
@ -27,9 +27,9 @@ export class ChangesetHandler {
|
|||
private readonly _remappings = new Map<string, string>()
|
||||
|
||||
constructor(
|
||||
dryRun: UIEventSource<boolean>,
|
||||
dryRun: Store<boolean>,
|
||||
osmConnection: OsmConnection,
|
||||
allElements: { addAlias: (id0: string, id1: string) => void },
|
||||
allElements: { addAlias: (id0: string, id1: string) => void } | undefined,
|
||||
changes: Changes
|
||||
) {
|
||||
this.osmConnection = osmConnection
|
||||
|
@ -299,7 +299,7 @@ export class ChangesetHandler {
|
|||
}
|
||||
for (const mapping of mappings) {
|
||||
const [oldId, newId] = mapping
|
||||
this.allElements.addAlias(oldId, newId)
|
||||
this.allElements?.addAlias(oldId, newId)
|
||||
if (newId !== undefined) {
|
||||
this._remappings.set(mapping[0], mapping[1])
|
||||
}
|
||||
|
|
|
@ -83,13 +83,13 @@ export default class SpecialVisualizations {
|
|||
* Note that _normal_ substitutions are ignored.
|
||||
*
|
||||
* // Return empty list on empty input
|
||||
* SubstitutedTranslation.constructSpecification("") // => []
|
||||
* SpecialVisualizations.constructSpecification("") // => []
|
||||
*
|
||||
* // Advanced cases with commas, braces and newlines should be handled without problem
|
||||
* const templates = SubstitutedTranslation.constructSpecification("{send_email(&LBRACEemail&RBRACE,Broken bicycle pump,Hello&COMMA\n\nWith this email&COMMA I'd like to inform you that the bicycle pump located at https://mapcomplete.osm.be/cyclofix?lat=&LBRACE_lat&RBRACE&lon=&LBRACE_lon&RBRACE&z=18#&LBRACEid&RBRACE is broken.\n\n Kind regards,Report this bicycle pump as broken)}")
|
||||
* const templ = templates[0]
|
||||
* templ.special.func.funcName // => "send_email"
|
||||
* templ.special.args[0] = "{email}"
|
||||
* const templates = SpecialVisualizations.constructSpecification("{send_email(&LBRACEemail&RBRACE,Broken bicycle pump,Hello&COMMA\n\nWith this email&COMMA I'd like to inform you that the bicycle pump located at https://mapcomplete.osm.be/cyclofix?lat=&LBRACE_lat&RBRACE&lon=&LBRACE_lon&RBRACE&z=18#&LBRACEid&RBRACE is broken.\n\n Kind regards,Report this bicycle pump as broken)}")
|
||||
* const templ = <Exclude<RenderingSpecification, string>> templates[0]
|
||||
* templ.func.funcName // => "send_email"
|
||||
* templ.args[0] = "{email}"
|
||||
*/
|
||||
public static constructSpecification(
|
||||
template: string,
|
||||
|
|
Loading…
Reference in a new issue