Add fakedom to test UI code, replace all 'innerText' with 'textContent' as it is not compatible with fakedom

This commit is contained in:
Pieter Vander Vennet 2022-06-28 03:21:18 +02:00
parent b0b674b2fb
commit 0f66d7f8cc
17 changed files with 281 additions and 20 deletions

View file

@ -0,0 +1,45 @@
import {describe} from 'mocha'
import {TagRenderingConfigJson} from "../../../Models/ThemeConfig/Json/TagRenderingConfigJson";
import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig";
import TagRenderingQuestion from "../../../UI/Popup/TagRenderingQuestion";
import {UIEventSource} from "../../../Logic/UIEventSource";
import { expect } from 'chai';
describe("TagRenderingQuestion", () => {
it("should have a freeform text field with the user defined placeholder", () => {
const configJson = <TagRenderingConfigJson>{
id: "test-tag-rendering",
question: "Question?",
render: "Rendering {capacity}",
freeform: {
key: "capacity",
type: "pnat",
placeholder: "Some user defined placeholder"
}
}
const config = new TagRenderingConfig(configJson, "test")
const ui = new TagRenderingQuestion( new UIEventSource<any>({}), config)
const html = ui.ConstructElement()
expect(html.getElementsByTagName("input")[0]["placeholder"]).eq("Some user defined placeholder")
})
it("should have a freeform text field with a type explanation", () => {
const configJson = <TagRenderingConfigJson>{
id: "test-tag-rendering",
question: "Question?",
render: "Rendering {capacity}",
freeform: {
key: "capacity",
type: "pnat",
}
}
const config = new TagRenderingConfig(configJson, "test")
const ui = new TagRenderingQuestion( new UIEventSource<any>({}), config)
const html = ui.ConstructElement()
expect(html.getElementsByTagName("input")[0]["placeholder"])
.eq("capacity (a positive, whole number)")
})
})