Better handling of image detection when running from ts-node; add some tests
This commit is contained in:
parent
eb1dfe84da
commit
3e75921754
4 changed files with 42 additions and 12 deletions
|
@ -18,17 +18,39 @@ import {And} from "../Logic/Tags/And";
|
|||
import {ImageSearcher} from "../Logic/Actors/ImageSearcher";
|
||||
import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
|
||||
import AllKnownLayers from "../Customizations/AllKnownLayers";
|
||||
import LayerConfig from "../Customizations/JSON/LayerConfig";
|
||||
|
||||
|
||||
new T("ImageAttribution Tests", [
|
||||
[
|
||||
"Should find all the images",
|
||||
() => {
|
||||
const pumps = AllKnownLayers.sharedLayers["bike_repair_station"]
|
||||
const expected = "./assets/layers/bike_repair_station/pump_example_manual.jpg"
|
||||
const pumps: LayerConfig = AllKnownLayers.sharedLayers["bike_repair_station"]
|
||||
const images = pumps.ExtractImages();
|
||||
const expectedValues = ['./assets/layers/bike_repair_station/repair_station.svg',
|
||||
'./assets/layers/bike_repair_station/repair_station_pump.svg',
|
||||
'./assets/layers/bike_repair_station/broken_pump_2.svg',
|
||||
'./assets/layers/bike_repair_station/pump.svg',
|
||||
'./assets/themes/cyclofix/fietsambassade_gent_logo_small.svg',
|
||||
'./assets/layers/bike_repair_station/pump_example_manual.jpg',
|
||||
'./assets/layers/bike_repair_station/pump_example.png',
|
||||
'./assets/layers/bike_repair_station/pump_example_round.jpg',
|
||||
'./assets/layers/bike_repair_station/repair_station_example.jpg']
|
||||
for (const expected of expectedValues) {
|
||||
T.isTrue(images.has(expected), expected + " not found")
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"Test image discovery regex",
|
||||
() => {
|
||||
const tr = new Translation({en: "XYZ <img src='a.svg'/> XYZ <img src=\"some image.svg\"></img> XYZ <img src=b.svg/>"})
|
||||
const images = new Set<string>(tr.ExtractImages(false));
|
||||
equal(3, images.size)
|
||||
T.isTrue(images.has("a.svg"), "a.svg not found")
|
||||
T.isTrue(images.has("b.svg"), "b.svg not found")
|
||||
T.isTrue(images.has("some image.svg"), "some image.svg not found")
|
||||
|
||||
equal(images.length, 5, "The pump example was not found")
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
@ -25,4 +25,9 @@ export default class T {
|
|||
}
|
||||
}
|
||||
|
||||
static isTrue(b: boolean, msg: string) {
|
||||
if(!b){
|
||||
throw "Expected true, but got false: "+msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue