Stabilize personal theme, textfield now correctly appears if it is an option in the freeform too

This commit is contained in:
Pieter Vander Vennet 2021-02-20 01:45:51 +01:00
parent 79fc3f54e5
commit 416a76ae4f
22 changed files with 278 additions and 149 deletions

View file

@ -15,7 +15,7 @@ import PublicHolidayInput from "../UI/OpeningHours/PublicHolidayInput";
import {SubstitutedTranslation} from "../UI/SubstitutedTranslation";
new T([
new T("Tags", [
["Tag replacement works in translation", () => {
const tr = new Translation({
"en": "Test {key} abc"

60
test/TagQuestion.spec.ts Normal file
View file

@ -0,0 +1,60 @@
import T from "./TestHelper";
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import TagRenderingQuestion from "../UI/Popup/TagRenderingQuestion";
import {UIEventSource} from "../Logic/UIEventSource";
import TagRenderingConfig from "../Customizations/JSON/TagRenderingConfig";
import {equal} from "assert";
import * as assert from "assert";
new T("TagQuestionElement",
[
["Freeform has textfield", () => {
const tags = new UIEventSource({
id: "way/123",
amenity: 'public_bookcases'
});
const config = new TagRenderingConfig(
{
render: "The name is {name}",
question: "What is the name of this bookcase?",
freeform: {
key: "name",
type: "string"
}
}, undefined, "Testing tag"
);
const questionElement = new TagRenderingQuestion(tags, config);
const html = questionElement.InnerRender();
T.assertContains("What is the name of this bookcase?", html);
T.assertContains("<input type='text'", html);
}],
["TagsQuestion with Freeform and mappings has textfield", () => {
const tags = new UIEventSource({
id: "way/123",
amenity: 'public_bookcases'
});
const config = new TagRenderingConfig(
{
render: "The name is {name}",
question: "What is the name of this bookcase?",
freeform: {
key: "name",
type: "string"
},
mappings: [
{"if": "noname=yes",
"then": "This bookcase has no name"}
]
}, undefined, "Testing tag"
);
const questionElement = new TagRenderingQuestion(tags, config);
const html = questionElement.InnerRender();
T.assertContains("What is the name of this bookcase?", html);
T.assertContains("This bookcase has no name", html);
T.assertContains("<input type='text'", html);
}]
]
);

View file

@ -1,6 +1,7 @@
export default class T {
constructor(tests: [string, () => void ][]) {
constructor(testsuite: string, tests: [string, () => void ][]) {
let failures : string []= [];
for (const [name, test] of tests) {
try {
@ -11,11 +12,17 @@ export default class T {
}
}
if (failures.length == 0) {
console.log("All tests done!")
console.log(`All tests of ${testsuite} done!`)
} else {
console.warn(failures.length, "tests failed :(")
console.warn(failures.length, `tests of ${testsuite} failed :(`)
console.log("Failed tests: ", failures.join(","))
}
}
static assertContains(needle: string, actual: string){
if(actual.indexOf(needle) < 0){
throw `The substring ${needle} was not found`
}
}
}