2020-08-22 12:44:11 +02:00
|
|
|
import {UIElement} from "../UI/UIElement";
|
2020-08-22 17:33:08 +02:00
|
|
|
|
2020-08-22 12:44:11 +02:00
|
|
|
UIElement.runningFromConsole = true;
|
2020-08-30 01:13:18 +02:00
|
|
|
|
|
|
|
import {equal} from "assert";
|
2020-08-22 17:33:08 +02:00
|
|
|
import Translation from "../UI/i18n/Translation";
|
|
|
|
import T from "./TestHelper";
|
2020-08-30 01:13:18 +02:00
|
|
|
import {FromJSON} from "../Customizations/JSON/FromJSON";
|
|
|
|
import {And, Tag} from "../Logic/Tags";
|
|
|
|
import Locale from "../UI/i18n/Locale";
|
|
|
|
import Translations from "../UI/i18n/Translations";
|
2020-08-22 12:44:11 +02:00
|
|
|
|
|
|
|
|
2020-08-22 17:33:08 +02:00
|
|
|
new T([
|
|
|
|
["Tag replacement works in translation", () => {
|
|
|
|
const tr = new Translation({
|
|
|
|
"en": "Test {key} abc"
|
|
|
|
}).replace("{key}", "value");
|
|
|
|
equal(tr.txt, "Test value abc");
|
2020-08-22 12:44:11 +02:00
|
|
|
|
2020-08-23 02:26:17 +02:00
|
|
|
}],
|
2020-08-30 01:13:18 +02:00
|
|
|
["Parse tag config", (() => {
|
|
|
|
const tag = FromJSON.Tag("key=value") as Tag;
|
|
|
|
equal(tag.key, "key");
|
|
|
|
equal(tag.value, "value");
|
|
|
|
|
|
|
|
const and = FromJSON.Tag({"and": ["key=value", "x=y"]}) as And;
|
|
|
|
equal((and.and[0] as Tag).key, "key");
|
|
|
|
equal((and.and[1] as Tag).value, "y");
|
|
|
|
|
|
|
|
})],
|
|
|
|
["Parse translation map", (() => {
|
|
|
|
|
|
|
|
const json: any = {"en": "English", "nl": "Nederlands"};
|
|
|
|
const translation = Translations.WT(FromJSON.Translation(json));
|
|
|
|
Locale.language.setData("en");
|
|
|
|
equal(translation.txt, "English");
|
|
|
|
Locale.language.setData("nl");
|
|
|
|
equal(translation.txt, "Nederlands");
|
|
|
|
})],
|
|
|
|
["Parse tag rendering", (() => {
|
|
|
|
Locale.language.setData("nl");
|
|
|
|
const tr = FromJSON.TagRendering({
|
|
|
|
render: ({"en":"Name is {name}", "nl":"Ook een {name}"} as any),
|
|
|
|
question: "Wat is de naam van dit object?",
|
|
|
|
freeform: {
|
|
|
|
key: "name",
|
|
|
|
},
|
2020-08-31 02:59:47 +02:00
|
|
|
|
|
|
|
mappings: [
|
|
|
|
{
|
|
|
|
if: "noname=yes",
|
|
|
|
"then": "Has no name"
|
|
|
|
}
|
|
|
|
],
|
2020-08-30 01:13:18 +02:00
|
|
|
condition: "x="
|
2020-09-09 18:42:13 +02:00
|
|
|
}, "");
|
2020-08-30 01:13:18 +02:00
|
|
|
|
|
|
|
equal(true, tr.IsKnown({"noname": "yes"}));
|
|
|
|
equal(true, tr.IsKnown({"name": "ABC"}));
|
|
|
|
equal(false, tr.IsKnown({"foo": "bar"}));
|
2020-09-09 18:42:13 +02:00
|
|
|
equal("Has no name", tr.GetContent({"noname": "yes"})?.txt);
|
|
|
|
equal("Ook een xyz", tr.GetContent({"name": "xyz"})?.txt);
|
|
|
|
equal(undefined, tr.GetContent({"foo": "bar"}));
|
2020-08-30 01:13:18 +02:00
|
|
|
|
2020-09-09 18:42:13 +02:00
|
|
|
})],
|
|
|
|
[
|
|
|
|
"Select right value test",
|
|
|
|
() => {
|
|
|
|
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-08-22 17:33:08 +02:00
|
|
|
]);
|