Port tests to vitest
This commit is contained in:
parent
64a4d7e929
commit
228ceb120d
33 changed files with 673 additions and 326 deletions
|
@ -1,5 +1,3 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { Utils } from "../../../../Utils"
|
||||
import { DesugaringContext } from "../../../../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
|
@ -7,6 +5,7 @@ import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagR
|
|||
import { PrepareLayer } from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import * as bookcases from "../../../../assets/layers/public_bookcase/public_bookcase.json"
|
||||
import CreateNoteImportLayer from "../../../../Models/ThemeConfig/Conversion/CreateNoteImportLayer"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("CreateNoteImportLayer", () => {
|
||||
it("should generate a layerconfig", () => {
|
||||
|
@ -24,18 +23,15 @@ describe("CreateNoteImportLayer", () => {
|
|||
layer,
|
||||
"ImportLayerGeneratorTest: convert"
|
||||
)
|
||||
expect(generatedLayer.isShown["and"][1].or[0].and[0]).deep.equal(
|
||||
"_tags~(^|.*;)amenity=public_bookcase($|;.*)"
|
||||
)
|
||||
expect(generatedLayer.minzoom <= layer.minzoom, "Zoomlevel is to high").true
|
||||
expect(generatedLayer.isShown["and"][1].or[0].and[0]).toEqual("_tags~(^|.*;)amenity=public_bookcase($|;.*)")
|
||||
// "Zoomlevel is to high"
|
||||
expect(generatedLayer.minzoom <= layer.minzoom).toBe(true)
|
||||
let renderings = Utils.NoNull(
|
||||
Utils.NoNull(
|
||||
generatedLayer.tagRenderings.map((tr) => (<TagRenderingConfigJson>tr).render)
|
||||
).map((render) => render["en"])
|
||||
)
|
||||
expect(
|
||||
renderings.some((r) => r.indexOf("import_button") > 0),
|
||||
"no import button found"
|
||||
).true
|
||||
// "no import button found"
|
||||
expect(renderings.some((r) => r.indexOf("import_button") > 0)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"
|
||||
import { FixLegacyTheme } from "../../../../Models/ThemeConfig/Conversion/LegacyJsonConvert"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("FixLegacyTheme", () => {
|
||||
it("should create a working theme config", () => {
|
||||
|
@ -135,8 +134,9 @@ describe("FixLegacyTheme", () => {
|
|||
],
|
||||
}
|
||||
const fixed = new FixLegacyTheme().convert(<any>walking_node_theme, "While testing")
|
||||
expect(fixed.errors, "Could not fix the legacy theme").empty
|
||||
// "Could not fix the legacy theme"
|
||||
expect(fixed.errors).empty
|
||||
const theme = new LayoutConfig(fixed.result, false)
|
||||
expect(theme).not.undefined
|
||||
expect(theme).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { TagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import LineRenderingConfigJson from "../../../../Models/ThemeConfig/Json/LineRenderingConfigJson"
|
||||
|
@ -10,6 +8,7 @@ import {
|
|||
} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import { QuestionableTagRenderingConfigJson } from "../../../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||
import RewritableConfigJson from "../../../../Models/ThemeConfig/Json/RewritableConfigJson"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("ExpandRewrite", () => {
|
||||
it("should not allow overlapping keys", () => {
|
||||
|
@ -106,7 +105,7 @@ describe("PrepareLayer", () => {
|
|||
titleIcons: [{ render: "defaults", id: "defaults" }],
|
||||
}
|
||||
|
||||
expect(result).deep.eq(expected)
|
||||
expect(result).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -126,7 +125,7 @@ describe("RewriteSpecial", function () {
|
|||
},
|
||||
}
|
||||
const r = new RewriteSpecial().convert(tr, "test").result
|
||||
expect(r).to.deep.eq({
|
||||
expect(r).toEqual({
|
||||
id: "uk_addresses_import_button",
|
||||
render: {
|
||||
"*": "{import_button(address,urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$,Add this address,./assets/themes/uk_addresses/housenumber_add.svg,,,,none,)}",
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { LayoutConfigJson } from "../../../../Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
import { LayerConfigJson } from "../../../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { PrepareTheme } from "../../../../Models/ThemeConfig/Conversion/PrepareTheme"
|
||||
|
@ -12,6 +10,7 @@ import * as cyclofix from "../../../../assets/generated/themes/cyclofix.json"
|
|||
import { Tag } from "../../../../Logic/Tags/Tag"
|
||||
import { DesugaringContext } from "../../../../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { And } from "../../../../Logic/Tags/And"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
const themeConfigJson: LayoutConfigJson = {
|
||||
description: "Descr",
|
||||
|
@ -49,7 +48,7 @@ describe("PrepareTheme", () => {
|
|||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.osmTags).deep.eq(
|
||||
expect(layerUnderTest.source.osmTags).toEqual(
|
||||
new And([new Tag("amenity", "public_bookcase")])
|
||||
)
|
||||
})
|
||||
|
@ -65,7 +64,7 @@ describe("PrepareTheme", () => {
|
|||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.geojsonSource).eq("xyz")
|
||||
expect(layerUnderTest.source.geojsonSource).toBe("xyz")
|
||||
})
|
||||
|
||||
it("should apply override", () => {
|
||||
|
@ -85,7 +84,7 @@ describe("PrepareTheme", () => {
|
|||
const layerUnderTest = <LayerConfig>(
|
||||
themeConfig.layers.find((l) => l.id === "public_bookcase")
|
||||
)
|
||||
expect(layerUnderTest.source.geojsonSource).eq("https://example.com/data.geojson")
|
||||
expect(layerUnderTest.source.geojsonSource).toBe("https://example.com/data.geojson")
|
||||
})
|
||||
|
||||
it("should remove names which are overriden with null", () => {
|
||||
|
@ -126,8 +125,8 @@ describe("PrepareTheme", () => {
|
|||
const rewritten = new PrepareTheme(ctx, {
|
||||
skipDefaultLayers: true,
|
||||
}).convertStrict(layout, "test")
|
||||
expect(rewritten.layers[0]).deep.eq(testLayer)
|
||||
expect(rewritten.layers[1]).deep.eq({
|
||||
expect(rewritten.layers[0]).toEqual(testLayer)
|
||||
expect(rewritten.layers[1]).toEqual({
|
||||
source: {
|
||||
osmTags: "x=y",
|
||||
},
|
||||
|
@ -158,7 +157,7 @@ describe("ExtractImages", () => {
|
|||
"close",
|
||||
]
|
||||
for (const expected of expectedValues) {
|
||||
expect(images).contains(expected)
|
||||
expect(images).toEqual(expect.arrayContaining([expected]))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import SourceConfig from "../../../Models/ThemeConfig/SourceConfig"
|
||||
import { TagUtils } from "../../../Logic/Tags/TagUtils"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("SourceConfig", () => {
|
||||
it("should throw an error on conflicting tags", () => {
|
||||
|
@ -14,6 +13,6 @@ describe("SourceConfig", () => {
|
|||
},
|
||||
false
|
||||
)
|
||||
}).to.throw(/tags are conflicting/)
|
||||
}).toThrowError(/tags are conflicting/)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import Locale from "../../../UI/i18n/Locale"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("TagRenderingConfig", () => {
|
||||
describe("isKnown", () => {
|
||||
|
@ -26,11 +25,11 @@ describe("TagRenderingConfig", () => {
|
|||
"Tests"
|
||||
)
|
||||
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).undefined
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).toBeUndefined()
|
||||
|
||||
expect(tr.GetRenderValue({ noname: "yes" })?.textFor("nl")).eq("Has no name")
|
||||
expect(tr.GetRenderValue({ name: "xyz" })?.textFor("nl")).eq("Ook een {name}")
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).undefined
|
||||
expect(tr.GetRenderValue({ noname: "yes" })?.textFor("nl")).toBe("Has no name")
|
||||
expect(tr.GetRenderValue({ name: "xyz" })?.textFor("nl")).toBe("Ook een {name}")
|
||||
expect(tr.GetRenderValue({ foo: "bar" })).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should give a correct indication", () => {
|
||||
|
@ -63,8 +62,8 @@ describe("TagRenderingConfig", () => {
|
|||
}
|
||||
|
||||
const tagRendering = new TagRenderingConfig(config, "test")
|
||||
expect(tagRendering.IsKnown({ bottle: "yes" })).true
|
||||
expect(tagRendering.IsKnown({})).false
|
||||
expect(tagRendering.IsKnown({ bottle: "yes" })).toBe(true)
|
||||
expect(tagRendering.IsKnown({})).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import { Unit } from "../../Models/Unit"
|
||||
import { Denomination } from "../../Models/Denomination"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("Unit", () => {
|
||||
it("should convert a value back and forth", () => {
|
||||
|
@ -19,10 +18,10 @@ describe("Unit", () => {
|
|||
)
|
||||
|
||||
const canonical = denomintion.canonicalValue("5", true)
|
||||
expect(canonical).eq("5 MW")
|
||||
expect(canonical).toBe("5 MW")
|
||||
const units = new Unit(["key"], [denomintion], false)
|
||||
const [detected, detectedDenom] = units.findDenomination("5 MW", () => "be")
|
||||
expect(detected).eq("5")
|
||||
expect(detectedDenom).eq(denomintion)
|
||||
expect(detected).toBe("5")
|
||||
expect(detectedDenom).toBe(denomintion)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue