diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-03 22:43:53 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-03 22:43:53 +0200 |
commit | 0b349de3cc699b54b02d7177418c8cf155afe929 (patch) | |
tree | 3b01196a3e629e1b7437f7c7e5c8eb413a4ed937 /src/test/kotlin | |
parent | d502659176e11f4b1d2294e536d9e3b66b72080c (diff) | |
download | kvision-0b349de3cc699b54b02d7177418c8cf155afe929.tar.gz kvision-0b349de3cc699b54b02d7177418c8cf155afe929.tar.bz2 kvision-0b349de3cc699b54b02d7177418c8cf155afe929.zip |
Simplify state binding functions. Deprecate stateBinding() in favor of bind().
Diffstat (limited to 'src/test/kotlin')
-rw-r--r-- | src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt index c0de7c6f..940fd2cd 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/state/StateBindingSpec.kt @@ -24,6 +24,7 @@ package test.pl.treksoft.kvision.state import pl.treksoft.kvision.html.div import pl.treksoft.kvision.panel.Root import pl.treksoft.kvision.panel.SimplePanel +import pl.treksoft.kvision.state.bind import pl.treksoft.kvision.state.observableListOf import pl.treksoft.kvision.state.stateBinding import pl.treksoft.kvision.state.stateUpdate @@ -34,6 +35,35 @@ import kotlin.test.Test class StateBindingSpec : DomSpec { @Test + fun bind() { + run { + val root = Root("test", fixed = true) + val container = SimplePanel() + val observableList = observableListOf(1, 2, 3) + container.bind(observableList) { state -> + setAttribute("data-count", "${state.size}") + state.forEach { + div("$it") + } + } + root.add(container) + val element = document.getElementById("test") + assertEqualsHtml( + "<div data-count=\"3\"><div>1</div><div>2</div><div>3</div></div>", + element?.innerHTML, + "Should render initial state of the widget" + ) + observableList.add(4) + assertEqualsHtml( + "<div data-count=\"4\"><div>1</div><div>2</div><div>3</div><div>4</div></div>", + element?.innerHTML, + "Should render changed state of the widget" + ) + } + } + + @Suppress("DEPRECATION") + @Test fun stateBinding() { run { val root = Root("test", fixed = true) @@ -60,6 +90,7 @@ class StateBindingSpec : DomSpec { } } + @Suppress("DEPRECATION") @Test fun stateUpdate() { run { |