Add some regression tests

This commit is contained in:
pietervdvn 2021-05-10 23:42:14 +02:00
parent f6cbb44454
commit 35ecc21e09
2 changed files with 152 additions and 78 deletions

View file

@ -1,4 +1,5 @@
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import {equal} from "assert";
import T from "./TestHelper";
@ -14,6 +15,7 @@ import PublicHolidayInput from "../UI/OpeningHours/PublicHolidayInput";
import {SubstitutedTranslation} from "../UI/SubstitutedTranslation";
import {Tag} from "../Logic/Tags/Tag";
import {And} from "../Logic/Tags/And";
import * as Assert from "assert";
new T("Tags", [
@ -48,7 +50,6 @@ new T("Tags", [
equal(isNotEmpty.matchesProperties({"other_key": "value"}), false)
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");
@ -391,4 +392,37 @@ new T("Tags", [
equal(Utils.Round(-1.6), "-1.6")
}
]]);
],
["Regression", () => {
const config = {
"#": "Bottle refill",
"question": {
"en": "How easy is it to fill water bottles?",
"nl": "Hoe gemakkelijk is het om drinkbussen bij te vullen?",
"de": "Wie einfach ist es, Wasserflaschen zu füllen?"
},
"mappings": [
{
"if": "bottle=yes",
"then": {
"en": "It is easy to refill water bottles",
"nl": "Een drinkbus bijvullen gaat makkelijk",
"de": "Es ist einfach, Wasserflaschen nachzufüllen"
}
},
{
"if": "bottle=no",
"then": {
"en": "Water bottles may not fit",
"nl": "Een drinkbus past moeilijk",
"de": "Wasserflaschen passen möglicherweise nicht"
}
}
]
};
const tagRendering = new TagRenderingConfig(config, null, "test");
equal(true, tagRendering.IsKnown({bottle: "yes"}))
equal(false, tagRendering.IsKnown({}))
}]]);

View file

@ -5,6 +5,7 @@ Utils.runningFromConsole = true;
import TagRenderingQuestion from "../UI/Popup/TagRenderingQuestion";
import {UIEventSource} from "../Logic/UIEventSource";
import TagRenderingConfig from "../Customizations/JSON/TagRenderingConfig";
import EditableTagRendering from "../UI/Popup/EditableTagRendering";
new T("TagQuestionElement",
@ -53,6 +54,45 @@ new T("TagQuestionElement",
T.assertContains("What is the name of this bookcase?", html);
T.assertContains("This bookcase has no name", html);
T.assertContains("<input type='text'", html);
}],
["Regression: has drinking water is asked", () => {
const tags = new UIEventSource({
id: "node/123",
amenity: 'drinking_water'
});
const jsonConfig = {
"#": "Bottle refill",
"question": {
"en": "How easy is it to fill water bottles?",
"nl": "Hoe gemakkelijk is het om drinkbussen bij te vullen?",
"de": "Wie einfach ist es, Wasserflaschen zu füllen?"
},
"mappings": [
{
"if": "bottle=yes",
"then": {
"en": "It is easy to refill water bottles",
"nl": "Een drinkbus bijvullen gaat makkelijk",
"de": "Es ist einfach, Wasserflaschen nachzufüllen"
}
},
{
"if": "bottle=no",
"then": {
"en": "Water bottles may not fit",
"nl": "Een drinkbus past moeilijk",
"de": "Wasserflaschen passen möglicherweise nicht"
}
}
]
};
const config = new TagRenderingConfig(
jsonConfig, null, "test");
const questionElement = new EditableTagRendering(tags, config);
const html = questionElement.InnerRender();
T.assertContains("How easy is it to fill water bottles?", html);
T.assertContains("It is easy to refill water bottles", html);
T.assertContains("<input type='radio'", html);
}]
]
);