forked from MapComplete/MapComplete
More work on splitting roads, WIP; refactoring tests
This commit is contained in:
parent
e374bb355c
commit
1f93923820
62 changed files with 1163 additions and 823 deletions
|
@ -10,7 +10,7 @@ Utils.runningFromConsole = true;
|
|||
export default class ImageAttributionSpec extends T {
|
||||
constructor() {
|
||||
super(
|
||||
"ImageAttribution Tests", [
|
||||
"imageattribution", [
|
||||
[
|
||||
"Should find all the images",
|
||||
() => {
|
||||
|
|
|
@ -8,7 +8,7 @@ Utils.runningFromConsole = true;
|
|||
export default class ImageSearcherSpec extends T {
|
||||
|
||||
constructor() {
|
||||
super("ImageSearcher", [
|
||||
super("imagesearcher", [
|
||||
[
|
||||
"Should find images",
|
||||
() => {
|
||||
|
|
|
@ -12,7 +12,7 @@ export default class OsmConnectionSpec extends T {
|
|||
private static _osm_token = "LJFmv2nUicSNmBNsFeyCHx5KKx6Aiesx8pXPbX4n"
|
||||
|
||||
constructor() {
|
||||
super("OsmConnectionSpec-test", [
|
||||
super("osmconnection", [
|
||||
["login on dev",
|
||||
() => {
|
||||
const osmConn = new OsmConnection(false, false,
|
||||
|
|
|
@ -1,27 +1,26 @@
|
|||
import T from "./TestHelper";
|
||||
import {OsmObject} from "../Logic/Osm/OsmObject";
|
||||
import ScriptUtils from "../scripts/ScriptUtils";
|
||||
import {UIEventSource} from "../Logic/UIEventSource";
|
||||
|
||||
export default class OsmObjectSpec extends T {
|
||||
private static async runTest(){
|
||||
const ways = await OsmObject.DownloadReferencingWays("node/1124134958")
|
||||
if(ways === undefined){
|
||||
throw "Did not get the ways"
|
||||
}
|
||||
if (ways.length !== 4) {
|
||||
throw "Expected 4 ways but got "+ways.length
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constructor() {
|
||||
super("OsmObject", [
|
||||
super("osmobject", [
|
||||
[
|
||||
"Download referencing ways",
|
||||
() => {
|
||||
let downloaded = false;
|
||||
OsmObject.DownloadReferencingWays("node/1124134958").addCallbackAndRunD(ways => {
|
||||
downloaded = true;
|
||||
console.log(ways)
|
||||
})
|
||||
let timeout = 10
|
||||
while (!downloaded && timeout >= 0) {
|
||||
ScriptUtils.sleep(1000)
|
||||
|
||||
timeout--;
|
||||
}
|
||||
if (!downloaded) {
|
||||
throw "Timeout: referencing ways not found"
|
||||
}
|
||||
OsmObjectSpec.runTest().then(_ => console.log("Referencing ways test is done (async)"))
|
||||
}
|
||||
|
||||
]
|
||||
|
|
66
test/RelationSplitHandler.spec.ts
Normal file
66
test/RelationSplitHandler.spec.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import T from "./TestHelper";
|
||||
import {InPlaceReplacedmentRTSH} from "../Logic/Osm/Actions/RelationSplitHandler";
|
||||
import {OsmObject, OsmRelation} from "../Logic/Osm/OsmObject";
|
||||
import {Changes} from "../Logic/Osm/Changes";
|
||||
import {equal} from "assert";
|
||||
|
||||
export default class RelationSplitHandlerSpec extends T {
|
||||
|
||||
private static async split(): Promise<void> {
|
||||
// Lets mimick a split action of https://www.openstreetmap.org/way/295132739
|
||||
|
||||
const relation: OsmRelation = <OsmRelation>await OsmObject.DownloadObjectAsync("relation/9572808")
|
||||
const originalNodeIds = [5273988967,
|
||||
170497153,
|
||||
1507524582,
|
||||
4524321710,
|
||||
170497155,
|
||||
170497157,
|
||||
170497158,
|
||||
3208166179,
|
||||
1507524610,
|
||||
170497160,
|
||||
3208166178,
|
||||
1507524573,
|
||||
1575932830,
|
||||
6448669326]
|
||||
|
||||
const withSplit = [[5273988967,
|
||||
170497153,
|
||||
1507524582,
|
||||
4524321710,
|
||||
170497155,
|
||||
170497157,
|
||||
170497158],
|
||||
[
|
||||
3208166179,
|
||||
1507524610,
|
||||
170497160,
|
||||
3208166178,
|
||||
1507524573,
|
||||
1575932830,
|
||||
6448669326]]
|
||||
|
||||
const splitter = new InPlaceReplacedmentRTSH(
|
||||
{
|
||||
relation: relation,
|
||||
originalWayId: 295132739,
|
||||
allWayIdsInOrder: [295132739, -1],
|
||||
originalNodes: originalNodeIds,
|
||||
allWaysNodesInOrder: withSplit
|
||||
})
|
||||
const changeDescription = await splitter.CreateChangeDescriptions(new Changes())
|
||||
const allIds = changeDescription[0].changes["members"].map(m => m.ref).join(",")
|
||||
const expected = "687866206,295132739,-1,690497698"
|
||||
if (allIds.indexOf(expected) < 0) {
|
||||
throw "Invalid order or the split ways. If this suddenly breaks, the parent relation at https://osm.org/relation/9572808 has probably changed and the test must be updated"
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super("relationsplithandler", [
|
||||
["split 295132739",
|
||||
() => RelationSplitHandlerSpec.split().then(_ => console.log("OK"))]
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ Utils.runningFromConsole = true;
|
|||
export default class TagSpec extends T {
|
||||
|
||||
constructor() {
|
||||
super("Tags", [
|
||||
super("tag", [
|
||||
["Tag replacement works in translation", () => {
|
||||
const tr = new Translation({
|
||||
"en": "Test {key} abc"
|
||||
|
|
|
@ -1,36 +1,16 @@
|
|||
import {Utils} from "../Utils";
|
||||
Utils.runningFromConsole = true;
|
||||
import TagSpec from "./Tag.spec";
|
||||
import ImageAttributionSpec from "./ImageAttribution.spec";
|
||||
import GeoOperationsSpec from "./GeoOperations.spec";
|
||||
import ImageSearcherSpec from "./ImageSearcher.spec";
|
||||
import ThemeSpec from "./Theme.spec";
|
||||
import UtilsSpec from "./Utils.spec";
|
||||
import OsmConnectionSpec from "./OsmConnection.spec";
|
||||
import T from "./TestHelper";
|
||||
import {FixedUiElement} from "../UI/Base/FixedUiElement";
|
||||
import Combine from "../UI/Base/Combine";
|
||||
import OsmObjectSpec from "./OsmObject.spec";
|
||||
import ScriptUtils from "../scripts/ScriptUtils";
|
||||
import UnitsSpec from "./Units.spec";
|
||||
import RelationSplitHandlerSpec from "./RelationSplitHandler.spec";
|
||||
|
||||
|
||||
|
||||
export default class TestAll {
|
||||
private needsBrowserTests: T[] = [new OsmConnectionSpec()]
|
||||
|
||||
public testAll(): void {
|
||||
Utils.runningFromConsole = false
|
||||
for (const test of this.needsBrowserTests.concat(allTests)) {
|
||||
if (test.failures.length > 0) {
|
||||
new Combine([new FixedUiElement("TEST FAILED: " + test.name).SetStyle("background: red"),
|
||||
...test.failures])
|
||||
.AttachTo("maindiv")
|
||||
throw "Some test failed"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ScriptUtils.fixUtils()
|
||||
const allTests = [
|
||||
new OsmObjectSpec(),
|
||||
|
@ -40,12 +20,34 @@ const allTests = [
|
|||
new ImageSearcherSpec(),
|
||||
new ThemeSpec(),
|
||||
new UtilsSpec(),
|
||||
new UnitsSpec()
|
||||
new UnitsSpec(),
|
||||
new RelationSplitHandlerSpec()
|
||||
]
|
||||
|
||||
let args = [...process.argv]
|
||||
args.splice(0, 2)
|
||||
args = args.map(a => a.toLowerCase())
|
||||
|
||||
for (const test of allTests) {
|
||||
if (test.failures.length > 0) {
|
||||
throw "Some test failed: " + test.failures.join(", ")
|
||||
const allFailures: { testsuite: string, name: string, msg: string } [] = []
|
||||
let testsToRun = allTests
|
||||
if (args.length > 0) {
|
||||
testsToRun = allTests.filter(t => args.indexOf(t.name) >= 0)
|
||||
}
|
||||
|
||||
if(testsToRun.length == 0){
|
||||
throw "No tests found"
|
||||
}
|
||||
|
||||
for (let i = 0; i < testsToRun.length; i++){
|
||||
const test = testsToRun[i];
|
||||
ScriptUtils.erasableLog(" Running test", i, "/", allTests.length)
|
||||
allFailures.push(...(test.Run() ?? []))
|
||||
|
||||
}
|
||||
if (allFailures.length > 0) {
|
||||
for (const failure of allFailures) {
|
||||
console.error(" !! " + failure.testsuite + "." + failure.name + " failed due to: " + failure.msg)
|
||||
}
|
||||
}
|
||||
throw "Some test failed"
|
||||
}
|
||||
console.log("All tests successful: ", allTests.map(t => t.name).join(", "))
|
||||
|
|
|
@ -1,23 +1,31 @@
|
|||
export default class T {
|
||||
|
||||
public readonly failures: string[] = []
|
||||
public readonly name: string;
|
||||
private readonly _tests: [string, (() => void)][];
|
||||
|
||||
constructor(testsuite: string, tests: [string, () => void][]) {
|
||||
this.name = testsuite
|
||||
for (const [name, test] of tests) {
|
||||
this._tests = tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* RUns the test, returns the error messages.
|
||||
* Returns an empty list if successful
|
||||
* @constructor
|
||||
*/
|
||||
public Run() : ({testsuite: string, name: string, msg: string} []) {
|
||||
const failures: {testsuite: string, name: string, msg: string} [] = []
|
||||
for (const [name, test] of this._tests) {
|
||||
try {
|
||||
test();
|
||||
} catch (e) {
|
||||
this.failures.push(name);
|
||||
console.warn(`>>> Failed test in ${this.name}: ${name}because${e}`);
|
||||
failures.push({testsuite: this.name, name: name, msg: ""+e});
|
||||
}
|
||||
}
|
||||
if (this.failures.length == 0) {
|
||||
console.log(`All tests of ${testsuite} done!`)
|
||||
if (failures.length == 0) {
|
||||
return undefined
|
||||
} else {
|
||||
console.warn(this.failures.length, `tests of ${testsuite} failed :(`)
|
||||
console.log("Failed tests: ", this.failures.join(","))
|
||||
return failures
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ Utils.runningFromConsole = true;
|
|||
|
||||
export default class ThemeSpec extends T {
|
||||
constructor() {
|
||||
super("Theme tests",
|
||||
super("theme",
|
||||
[
|
||||
["Nested overrides work", () => {
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import {Denomination} from "../Models/Denomination";
|
|||
export default class UnitsSpec extends T {
|
||||
|
||||
constructor() {
|
||||
super("Units", [
|
||||
super("units", [
|
||||
["Simple canonicalize", () => {
|
||||
|
||||
const unit = new Denomination({
|
||||
|
|
|
@ -39,7 +39,7 @@ export default class UtilsSpec extends T {
|
|||
}
|
||||
|
||||
constructor() {
|
||||
super("Utils", [
|
||||
super("utils", [
|
||||
["Sort object keys", () => {
|
||||
const o = {
|
||||
x: 'x',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue