Fix: fix tests with some refactoring

This commit is contained in:
Pieter Vander Vennet 2024-09-27 03:04:05 +02:00
parent f132963485
commit 0b992e75a4
7 changed files with 64 additions and 401 deletions

View file

@ -1,5 +1,5 @@
import { OsmNode, OsmObject, OsmRelation, OsmWay } from "./OsmObject"
import { UIEventSource } from "../UIEventSource"
import { ImmutableStore, Store, UIEventSource } from "../UIEventSource"
import Constants from "../../Models/Constants"
import OsmChangeAction from "./Actions/OsmChangeAction"
import { ChangeDescription, ChangeDescriptionTools } from "./Actions/ChangeDescription"
@ -14,10 +14,9 @@ import { OsmConnection } from "./OsmConnection"
import OsmObjectDownloader from "./OsmObjectDownloader"
import ChangeLocationAction from "./Actions/ChangeLocationAction"
import ChangeTagAction from "./Actions/ChangeTagAction"
import FeatureSwitchState from "../State/FeatureSwitchState"
import DeleteAction from "./Actions/DeleteAction"
import MarkdownUtils from "../../Utils/MarkdownUtils"
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
/**
* Handles all changes made to OSM.
@ -30,7 +29,9 @@ export class Changes {
public readonly state: {
allElements?: IndexedFeatureSource
osmConnection: OsmConnection
featureSwitches?: FeatureSwitchState
featureSwitches?: {
featureSwitchMorePrivacy?: Store<boolean>
}
}
public readonly extraComment: UIEventSource<string> = new UIEventSource(undefined)
public readonly backend: string
@ -44,7 +45,17 @@ export class Changes {
private readonly _reportError?: (string: string | Error, extramessage?: string) => void
constructor(
state: SpecialVisualizationState,
state: {
featureSwitches: {
featureSwitchMorePrivacy?: Store<boolean>
featureSwitchIsTesting?: Store<boolean>
},
osmConnection: OsmConnection,
reportError?: (error: string) => void,
featureProperties?: FeaturePropertiesStore,
historicalUserLocations?: FeatureSource,
allElements?: IndexedFeatureSource
},
leftRightSensitive: boolean = false,
reportError?: (string: string | Error, extramessage?: string) => void
) {
@ -53,7 +64,7 @@ export class Changes {
this.allChanges.setData([...this.pendingChanges.data])
// If a pending change contains a negative ID, we save that
this._nextId = Math.min(-1, ...(this.pendingChanges.data?.map((pch) => pch.id ?? 0) ?? []))
if(isNaN(this._nextId)){
if(isNaN(this._nextId) && state.reportError !== undefined){
state.reportError("Got a NaN as nextID. Pending changes IDs are:" +this.pendingChanges.data?.map(pch => pch?.id).join("."))
this._nextId = -100
}
@ -73,6 +84,15 @@ export class Changes {
// This doesn't matter however, as the '-1' is per piecewise upload, not global per changeset
}
public static createTestObject(): Changes{
return new Changes({
osmConnection: new OsmConnection(),
featureSwitches:{
featureSwitchIsTesting: new ImmutableStore(true)
}
})
}
static buildChangesetXML(
csId: string,
allChanges: {