mapcomplete/test/ImageAttribution.spec.ts

45 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-04-09 02:56:48 +02:00
import {equal} from "assert";
import T from "./TestHelper";
import {Translation} from "../UI/i18n/Translation";
import * as cyclofix from "../assets/generated/themes/cyclofix.json"
import {ExtractImages} from "../Models/ThemeConfig/Conversion/FixImages";
2021-04-09 02:56:48 +02:00
export default class ImageAttributionSpec extends T {
constructor() {
2022-01-14 13:58:15 +01:00
super([
2022-01-26 21:40:38 +01:00
[
"Should find all the images",
() => {
2022-02-19 02:45:15 +01:00
const images = new Set(new ExtractImages(true, new Map<string, any>()).convertStrict(<any> cyclofix, "test"))
const expectedValues = [
'./assets/layers/bike_repair_station/repair_station.svg',
2022-01-26 21:40:38 +01:00
'./assets/layers/bike_repair_station/repair_station_pump.svg',
2022-02-07 02:19:34 +01:00
'./assets/layers/bike_repair_station/broken_pump.svg',
2022-01-26 21:40:38 +01:00
'./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_2.jpg',
'close']
2022-01-26 21:40:38 +01:00
for (const expected of expectedValues) {
T.isTrue(images.has(expected), expected + " not found")
}
2022-01-26 21:40:38 +01:00
}
],
[
"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")
2021-04-09 02:56:48 +02:00
2022-01-26 21:40:38 +01:00
}
]
2022-01-26 21:40:38 +01:00
]);
}
}