Refactoring of tests

This commit is contained in:
pietervdvn 2022-01-14 13:58:15 +01:00
parent 555dbf3478
commit f67d0701b0
19 changed files with 64 additions and 28 deletions

View file

@ -49,7 +49,7 @@ export default class ActorsSpec extends T {
}
)
super("Actors", [
super([
[
"download latest version",
() => {

View file

@ -0,0 +1,31 @@
import T from "./TestHelper";
import CreateNoteImportLayer from "../Models/ThemeConfig/Conversion/CreateNoteImportLayer";
import * as bookcases from "../assets/layers/public_bookcase/public_bookcase.json"
import {DesugaringContext, PrepareLayer} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert";
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
import * as fs from "fs";
export default class CreateNoteImportLayerSpec extends T {
constructor() {
super([
["Bookcase", () => {
const desugaringState: DesugaringContext = {
sharedLayers: new Map<string, LayerConfigJson>(),
tagRenderings: new Map<string, TagRenderingConfigJson>()
}
const layerPrepare = new PrepareLayer()
const layer = new LayerConfig(layerPrepare.convertStrict(desugaringState, bookcases, "ImportLayerGeneratorTest:Parse bookcases"), "ImportLayerGeneratorTest: init bookcases-layer")
const generator = new CreateNoteImportLayer()
const generatedLayer = generator.convertStrict(desugaringState, layer, "ImportLayerGeneratorTest: convert")
fs.writeFileSync("bookcases-import-layer.generated.json", JSON.stringify(generatedLayer, null, " "), "utf8")
console.log(JSON.stringify(generatedLayer, null, " "))
}]
]);
}
}

View file

@ -89,8 +89,7 @@ export default class GeoOperationsSpec extends T {
private static outsidePolygon = [4.02099609375, 47.81315451752768]
constructor() {
super(
"GeoOperationsSpec", [
super([
["Point out of polygon", () => {
GeoOperationsSpec.isFalse(GeoOperations.inside([
3.779296875,

View file

@ -6,8 +6,7 @@ import LayerConfig from "../Models/ThemeConfig/LayerConfig";
export default class ImageAttributionSpec extends T {
constructor() {
super(
"imageattribution", [
super([
[
"Should find all the images",
() => {

View file

@ -6,7 +6,7 @@ import {Utils} from "../Utils";
export default class ImageProviderSpec extends T {
constructor() {
super("ImageProvider", [
super([
["Search images", () => {
let i = 0

View file

@ -141,9 +141,7 @@ export default class LegacyThemeLoaderSpec extends T {
}
constructor() {
super("LegacyThemeLoader",
[
super([
["Walking_node_theme", () => {
const config = LegacyThemeLoaderSpec.walking_node_theme

View file

@ -14,7 +14,7 @@ export default class OsmConnectionSpec extends T {
private static _osm_token = "LJFmv2nUicSNmBNsFeyCHx5KKx6Aiesx8pXPbX4n"
constructor() {
super("osmconnection", [
super([
["login on dev",
() => {
const osmConn = new OsmConnection({

View file

@ -3,7 +3,7 @@ import {OsmObject} from "../Logic/Osm/OsmObject";
export default class OsmObjectSpec extends T {
constructor() {
super("osmobject", [
super( [
[
"Download referencing ways",
() => {

View file

@ -548,7 +548,7 @@ export default class RelationSplitHandlerSpec extends T {
)
super("relationsplithandler", [
super( [
["split 295132739",
async () => {
// Lets mimick a split action of https://www.openstreetmap.org/way/295132739

View file

@ -324,7 +324,7 @@ export default class ReplaceGeometrySpec extends T {
constructor() {
super("ReplaceGeometry", [
super( [
["House replacement with connected node", async () => {
Minimap.createMiniMap = () => undefined;

View file

@ -8,7 +8,7 @@ export default class SplitActionSpec extends T {
constructor() {
super("splitaction", [
super([
["split 295132739",
() => SplitActionSpec.split().then(_ => console.log("OK"))],
["split 295132739 on already existing node",

View file

@ -13,7 +13,7 @@ import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
export default class TagSpec extends T {
constructor() {
super("tag", [
super( [
["Tag replacement works in translation", () => {
const tr = new Translation({
"en": "Test {key} abc"

View file

@ -15,12 +15,14 @@ import ImageProviderSpec from "./ImageProvider.spec";
import ActorsSpec from "./Actors.spec";
import ReplaceGeometrySpec from "./ReplaceGeometry.spec";
import LegacyThemeLoaderSpec from "./LegacyThemeLoader.spec";
import T from "./TestHelper";
import CreateNoteImportLayerSpec from "./CreateNoteImportLayer.spec";
async function main() {
ScriptUtils.fixUtils()
const allTests = [
const allTests : T[] = [
new OsmObjectSpec(),
new TagSpec(),
new ImageAttributionSpec(),
@ -35,7 +37,8 @@ async function main() {
new ImageProviderSpec(),
new ActorsSpec(),
new ReplaceGeometrySpec(),
new LegacyThemeLoaderSpec()
new LegacyThemeLoaderSpec(),
new CreateNoteImportLayerSpec()
]
Utils.externalDownloadFunction = async (url) => {
@ -54,12 +57,20 @@ async function main() {
const allFailures: { testsuite: string, name: string, msg: string } [] = []
let testsToRun = allTests
if (args.length > 0) {
args = args.map(a => a.toLowerCase())
args = args.map(a => a.toLowerCase()).map(a => {
if(!a.endsWith("spec")){
return a + "spec"
}else{
return a;
}
})
testsToRun = allTests.filter(t => args.indexOf(t.name.toLowerCase()) >= 0)
}
if (testsToRun.length == 0) {
throw "No tests found. Try one of " + allTests.map(t => t.name).join(", ")
const available = allTests.map(t => t.name)
available.sort()
throw "No tests found. Try one of " + available.join(", ")
}
for (let i = 0; i < testsToRun.length; i++) {

View file

@ -3,8 +3,8 @@ export default class T {
public readonly name: string;
private readonly _tests: [string, (() => (void | Promise<void>))][];
constructor(testsuite: string, tests: [string, () => (Promise<void> | void)][]) {
this.name = testsuite
constructor(tests: [string, () => (Promise<void> | void)][]) {
this.name = this.constructor.name;
this._tests = tests;
}

View file

@ -10,8 +10,7 @@ import Constants from "../Models/Constants";
export default class ThemeSpec extends T {
constructor() {
super("theme",
[
super( [
["Nested overrides work", () => {
let themeConfigJson: LayoutConfigJson = {

View file

@ -6,7 +6,7 @@ import {equal} from "assert";
export default class TileFreshnessCalculatorSpec extends T {
constructor() {
super("TileFreshnessCalculatorSpec", [
super( [
[
"TileFresnessTests",
() => {

View file

@ -6,7 +6,7 @@ import {Denomination} from "../Models/Denomination";
export default class UnitsSpec extends T {
constructor() {
super("units", [
super( [
["Simple canonicalize", () => {
const unit = new Denomination({

View file

@ -39,7 +39,7 @@ export default class UtilsSpec extends T {
}
constructor() {
super("utils", [
super( [
["Sort object keys", () => {
const o = {
x: 'x',

View file

@ -7255,8 +7255,7 @@ export default class WikidataSpecTest extends T {
}
constructor() {
super("Wikidata",
[
super( [
["Download Lion", async () => {
Utils.injectJsonDownloadForTests(