From 0b349de3cc699b54b02d7177418c8cf155afe929 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 3 May 2020 22:43:53 +0200 Subject: Simplify state binding functions. Deprecate stateBinding() in favor of bind(). --- .../pl/treksoft/kvision/state/StateBindingSpec.kt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/test') 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 @@ -33,6 +34,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( + "
1
2
3
", + element?.innerHTML, + "Should render initial state of the widget" + ) + observableList.add(4) + assertEqualsHtml( + "
1
2
3
4
", + element?.innerHTML, + "Should render changed state of the widget" + ) + } + } + + @Suppress("DEPRECATION") @Test fun stateBinding() { run { @@ -60,6 +90,7 @@ class StateBindingSpec : DomSpec { } } + @Suppress("DEPRECATION") @Test fun stateUpdate() { run { -- cgit