diff options
-rw-r--r-- | src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt new file mode 100644 index 00000000..7b9b16e4 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt @@ -0,0 +1,34 @@ +package test.pl.treksoft.kvision.data + +import com.lightningkite.kotlin.observable.list.observableListOf +import pl.treksoft.kvision.basic.Label +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.data.DataComponent +import pl.treksoft.kvision.data.DataContainer +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class DataContainerSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + class Model(value: String) : DataComponent() { + var value: String by obs(value) + } + val model = observableListOf(Model("First"), Model("Second")) + val container = DataContainer(model, { element, _ -> Label(element.value) }) + root.add(container) + val element = document.getElementById("test") + assertEquals("<div style=\"display: flex; flex-direction: column;\"><div><span>First</span></div><div><span>Second</span></div></div>", element?.innerHTML, "Should render correct data container") + model.add(Model("Third")) + assertEquals("<div style=\"display: flex; flex-direction: column;\"><div><span>First</span></div><div><span>Second</span></div><div><span>Third</span></div></div>", element?.innerHTML, "Should render correct data container after model change") + model[1].value = "Changed" + assertEquals("<div style=\"display: flex; flex-direction: column;\"><div><span>First</span></div><div><span>Changed</span></div><div><span>Third</span></div></div>", element?.innerHTML, "Should render correct data container after model element change") + } + } + +}
\ No newline at end of file |