aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-28 23:55:07 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-28 23:55:07 +0200
commit0bc8ff5a2d4b63d184d4289351d93195d8ef66bd (patch)
tree81c922eb1306b9040c12e78b2cf56ab1a5935f71 /src
parent06f297d68887c7934e66d2c757abc8bf619df66a (diff)
downloadkvision-0bc8ff5a2d4b63d184d4289351d93195d8ef66bd.tar.gz
kvision-0bc8ff5a2d4b63d184d4289351d93195d8ef66bd.tar.bz2
kvision-0bc8ff5a2d4b63d184d4289351d93195d8ef66bd.zip
Unit tests
Diffstat (limited to 'src')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/data/DataContainerSpec.kt34
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