diff options
Diffstat (limited to 'src/test/kotlin')
3 files changed, 31 insertions, 11 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt b/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt index a1a142e7..dd2093cd 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt @@ -1,7 +1,6 @@ package test.pl.treksoft.kvision import org.w3c.dom.Element -import org.w3c.dom.HTMLElement import pl.treksoft.kvision.core.Root import pl.treksoft.kvision.core.Widget import kotlin.browser.document @@ -21,8 +20,8 @@ interface TestSpec { interface DomSpec : TestSpec { override fun beforeTest() { - var fixture = "<div style=\"display: none\"><div id=\"test\"></div></div>"; - document.body?.insertAdjacentHTML("afterbegin", fixture); + val fixture = "<div style=\"display: none\"><div id=\"test\"></div></div>" + document.body?.insertAdjacentHTML("afterbegin", fixture) } override fun afterTest() { @@ -35,14 +34,14 @@ interface DomSpec : TestSpec { interface WSpec : DomSpec { fun runW(code: (widget: Widget, element: Element?) -> Unit) { - beforeTest() - val root = Root("test") - val widget = Widget() - widget.id = "test_id" - root.add(widget) - val element = document.getElementById("test_id") - code(widget, element) - afterTest() + run { + val root = Root("test") + val widget = Widget() + widget.id = "test_id" + root.add(widget) + val element = document.getElementById("test_id") + code(widget, element) + } } }
\ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt index dd80bab0..bb6ed603 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt @@ -26,4 +26,12 @@ class RootSpec : DomSpec { } } + @Test + fun getRoot() { + run { + val root = Root("test") + val r = root.getRoot() + assertTrue("Should return self") { r == root } + } + } }
\ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt index c68d5e7e..4117b03d 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt @@ -1,5 +1,7 @@ package test.pl.treksoft.kvision.core +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.core.Widget import test.pl.treksoft.kvision.WSpec import kotlin.browser.document import kotlin.test.Test @@ -103,4 +105,15 @@ class WidgetSpec : WSpec { assertTrue("Should return correct dom element from jQuery object") { e == element } } } + + @Test + fun getRoot() { + run { + val root = Root("test") + val widget = Widget() + root.add(widget) + val r = widget.getRoot() + assertTrue("Should return correct root element") { r == root } + } + } }
\ No newline at end of file |