From 0bc8ff5a2d4b63d184d4289351d93195d8ef66bd Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 28 Oct 2017 23:55:07 +0200 Subject: Unit tests --- .../pl/treksoft/kvision/data/DataContainerSpec.kt | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt (limited to 'src') 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("
First
Second
", element?.innerHTML, "Should render correct data container") + model.add(Model("Third")) + assertEquals("
First
Second
Third
", element?.innerHTML, "Should render correct data container after model change") + model[1].value = "Changed" + assertEquals("
First
Changed
Third
", element?.innerHTML, "Should render correct data container after model element change") + } + } + +} \ No newline at end of file -- cgit