aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/basic/LabelSpec.kt23
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt17
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt23
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/ButtonSpec.kt25
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/ImageSpec.kt26
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/LinkSpec.kt23
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/ListSpec.kt39
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt21
8 files changed, 192 insertions, 5 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/basic/LabelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/basic/LabelSpec.kt
new file mode 100644
index 00000000..c3019cc9
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/basic/LabelSpec.kt
@@ -0,0 +1,23 @@
+package test.pl.treksoft.kvision.basic
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class LabelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val label = Label("This is a label")
+ root.add(label)
+ val element = document.getElementById("test")
+ assertEquals("<span>This is a label</span>", element?.innerHTML, "Should render correct label")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt
index f79d24df..d9d59c4c 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt
@@ -29,6 +29,23 @@ class ContainerSpec : DomSpec {
}
@Test
+ fun addAll() {
+ run {
+ val root = Root("test")
+ val container = Container()
+ val child1 = Widget()
+ child1.id = "child1"
+ val child2 = Widget()
+ child2.id = "child2"
+ container.addAll(listOf(child1, child2))
+ root.add(container)
+ val elem1 = document.getElementById("child1")
+ val elem2 = document.getElementById("child2")
+ assertTrue("Container renders children") { elem1 != null && elem2 != null }
+ }
+ }
+
+ @Test
fun remove() {
run {
val root = Root("test")
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt
new file mode 100644
index 00000000..878119dc
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt
@@ -0,0 +1,23 @@
+package test.pl.treksoft.kvision.dropdown
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.dropdown.DropDown
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DropDownSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag")
+ root.add(dd)
+ val element = document.getElementById("test")
+ assertEquals("<div class=\"dropdown\"><button class=\"dropdown btn btn-default\" id=\"kv_dropdown_0\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"kv_dropdown_0\"><li><a href=\"#!/x\">abc</a></li><li><a href=\"#!/y\">def</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/ButtonSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/ButtonSpec.kt
new file mode 100644
index 00000000..6019b912
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/ButtonSpec.kt
@@ -0,0 +1,25 @@
+package test.pl.treksoft.kvision.html
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.html.BUTTON_SIZE
+import pl.treksoft.kvision.html.BUTTON_STYLE
+import pl.treksoft.kvision.html.Button
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class ButtonSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val button = Button("Cancel", "fa-bars", BUTTON_STYLE.PRIMARY, BUTTON_SIZE.LARGE, true)
+ root.add(button)
+ val element = document.getElementById("test")
+ assertEquals("<button class=\"btn btn-primary btn-lg btn-block\" type=\"button\"><i class=\"fa fa-bars fa-lg\"></i> Cancel</button>", element?.innerHTML, "Should render correct html button")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/ImageSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/ImageSpec.kt
new file mode 100644
index 00000000..7d8e37fe
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/ImageSpec.kt
@@ -0,0 +1,26 @@
+package test.pl.treksoft.kvision.html
+
+import pl.treksoft.kvision.core.Img
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.html.IMAGE_SHAPE
+import pl.treksoft.kvision.html.Image
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class ImageSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val res = Img("kotlin.png")
+ val image = Image(res, "Image", true, IMAGE_SHAPE.ROUNDED, true)
+ root.add(image)
+ val element = document.getElementById("test")
+ assertEquals("<img class=\"img-responsive center-block img-rounded\" src=\"$res\" alt=\"Image\">", element?.innerHTML, "Should render correct html image")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/LinkSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/LinkSpec.kt
new file mode 100644
index 00000000..1f4b6d2c
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/LinkSpec.kt
@@ -0,0 +1,23 @@
+package test.pl.treksoft.kvision.html
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.html.Link
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class LinkSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val link = Link("Google", "http://www.google.com")
+ root.add(link)
+ val element = document.getElementById("test")
+ assertEquals("<a href=\"http://www.google.com\">Google</a>", element?.innerHTML, "Should render correct html link")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/ListSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/ListSpec.kt
new file mode 100644
index 00000000..78631076
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/ListSpec.kt
@@ -0,0 +1,39 @@
+package test.pl.treksoft.kvision.html
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.html.LIST
+import pl.treksoft.kvision.html.ListTag
+import pl.treksoft.kvision.html.TAG
+import pl.treksoft.kvision.html.Tag
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class ListSpec : DomSpec {
+
+ @Test
+ fun render_Elements() {
+ run {
+ val root = Root("test")
+ val list = ListTag(LIST.DL_HORIZ, listOf("a1", "a2", "b1", "b2"))
+ root.add(list)
+ val element = document.getElementById("test")
+ assertEquals("<dl class=\"dl-horizontal\"><dt>a1</dt><dd>a2</dd><dt>b1</dt><dd>b2</dd></dl>", element?.innerHTML, "Should render correct html list")
+ }
+ }
+
+ @Test
+ fun render_AsContainer() {
+ run {
+ val root = Root("test")
+ val list = ListTag(LIST.UL)
+ list.add(Tag(TAG.PRE, "pre"))
+ list.add(Tag(TAG.DEL, "del"))
+ root.add(list)
+ val element = document.getElementById("test")
+ assertEquals("<ul><li><pre>pre</pre></li><li><del>del</del></li></ul>", element?.innerHTML, "Should render correct html list")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
index 1ba7f97b..997714db 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
@@ -2,13 +2,13 @@ package test.pl.treksoft.kvision.html
import pl.treksoft.kvision.core.Root
import pl.treksoft.kvision.html.ALIGN
+import pl.treksoft.kvision.html.Link
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
import test.pl.treksoft.kvision.DomSpec
import kotlin.browser.document
import kotlin.test.Test
import kotlin.test.assertEquals
-import kotlin.test.assertTrue
class TagSpec : DomSpec {
@@ -24,15 +24,26 @@ class TagSpec : DomSpec {
}
@Test
- fun render_rich() {
+ fun render_Rich() {
run {
val root = Root("test")
- val tag = Tag(TAG.H1, "This is <b>h1</b>", rich = true, align = ALIGN.CENTER)
+ val tag = Tag(TAG.H1, "This is <b>h1</b>", rich = true, align = ALIGN.RIGHT)
root.add(tag)
val element = document.getElementById("test")
- assertEquals("<h1 class=\"text-center\"><span>This is <b>h1</b></span></h1>", element?.innerHTML, "Should render correct html tag")
+ assertEquals("<h1 class=\"text-right\"><span>This is <b>h1</b></span></h1>", element?.innerHTML, "Should render correct html tag")
}
}
-
+ @Test
+ fun render_AsContainer() {
+ run {
+ val root = Root("test")
+ val tag = Tag(TAG.P, align = ALIGN.RIGHT)
+ tag.add(Tag(TAG.DEL, "This is test"))
+ tag.add(Link("abc", "/x"))
+ root.add(tag)
+ val element = document.getElementById("test")
+ assertEquals("<p class=\"text-right\"><del>This is test</del><a href=\"/x\">abc</a></p>", element?.innerHTML, "Should render correct html tag with children")
+ }
+ }
} \ No newline at end of file