aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-09-16 22:42:23 +0200
committerRobert Jaros <rjaros@finn.pl>2017-09-16 22:42:23 +0200
commit5d5db76ff0d9d1505c4a41cd84e871793a7a7b8d (patch)
treea8499b191e4e4f13f51b23a0cf6afb8778eb214e /src/test/kotlin
parent6f7435b41e8994821649a50978aeb5b5b65951bd (diff)
downloadkvision-5d5db76ff0d9d1505c4a41cd84e871793a7a7b8d.tar.gz
kvision-5d5db76ff0d9d1505c4a41cd84e871793a7a7b8d.tar.bz2
kvision-5d5db76ff0d9d1505c4a41cd84e871793a7a7b8d.zip
Implemented getRoot method in widget class
Diffstat (limited to 'src/test/kotlin')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt21
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt8
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt13
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