aboutsummaryrefslogtreecommitdiff
path: root/examples/helloworld/src/test/kotlin
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-01-21 20:36:13 +0100
committerRobert Jaros <rjaros@finn.pl>2018-01-21 20:36:13 +0100
commit7e095b7322c7dc831e8e3481848257dcda99d467 (patch)
tree9c05d9f97ebf9c0af5b685a5bf4e75833f9ad667 /examples/helloworld/src/test/kotlin
parentdb7eb7216e097b7f05fcad998be3dda2f4ce9af5 (diff)
downloadkvision-7e095b7322c7dc831e8e3481848257dcda99d467.tar.gz
kvision-7e095b7322c7dc831e8e3481848257dcda99d467.tar.bz2
kvision-7e095b7322c7dc831e8e3481848257dcda99d467.zip
Hello World example
Diffstat (limited to 'examples/helloworld/src/test/kotlin')
-rw-r--r--examples/helloworld/src/test/kotlin/test/com/example/HelloworldSpec.kt21
-rw-r--r--examples/helloworld/src/test/kotlin/test/com/example/TestUtil.kt32
2 files changed, 53 insertions, 0 deletions
diff --git a/examples/helloworld/src/test/kotlin/test/com/example/HelloworldSpec.kt b/examples/helloworld/src/test/kotlin/test/com/example/HelloworldSpec.kt
new file mode 100644
index 00000000..8054c000
--- /dev/null
+++ b/examples/helloworld/src/test/kotlin/test/com/example/HelloworldSpec.kt
@@ -0,0 +1,21 @@
+package test.com.example
+
+import com.example.Helloworld
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertTrue
+
+class HelloworldSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ Helloworld().start(mapOf())
+ val element = document.getElementById("helloworld")
+ assertTrue(
+ element?.innerHTML?.contains("Hello world!") ?: false,
+ "Application should render Hello world! text"
+ )
+ }
+ }
+}
diff --git a/examples/helloworld/src/test/kotlin/test/com/example/TestUtil.kt b/examples/helloworld/src/test/kotlin/test/com/example/TestUtil.kt
new file mode 100644
index 00000000..c5ec014f
--- /dev/null
+++ b/examples/helloworld/src/test/kotlin/test/com/example/TestUtil.kt
@@ -0,0 +1,32 @@
+package test.com.example
+
+import pl.treksoft.jquery.jQuery
+import kotlin.browser.document
+
+interface TestSpec {
+ fun beforeTest()
+
+ fun afterTest()
+
+ fun run(code: () -> Unit) {
+ beforeTest()
+ code()
+ afterTest()
+ }
+}
+
+interface DomSpec : TestSpec {
+
+ override fun beforeTest() {
+ val fixture = "<div style=\"display: none\" id=\"pretest\">" +
+ "<div id=\"helloworld\"></div></div>"
+ document.body?.insertAdjacentHTML("afterbegin", fixture)
+ }
+
+ override fun afterTest() {
+ val div = document.getElementById("pretest")
+ div?.remove()
+ jQuery(`object` = ".modal-backdrop").remove()
+ }
+
+}