aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/kotlin')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt5
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt34
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt15
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt3
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt32
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/StackPanelSpec.kt74
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/tabs/TabsSpec.kt60
7 files changed, 221 insertions, 2 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt b/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt
index a4ac44ed..fbda7a45 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt
@@ -1,6 +1,7 @@
package test.pl.treksoft.kvision
import org.w3c.dom.Element
+import pl.treksoft.jquery.jQuery
import pl.treksoft.kvision.core.Root
import pl.treksoft.kvision.core.Widget
import kotlin.browser.document
@@ -20,13 +21,15 @@ interface TestSpec {
interface DomSpec : TestSpec {
override fun beforeTest() {
- val fixture = "<div style=\"display: none\" id=\"pretest\"><div id=\"test\"></div></div>"
+ val fixture = "<div style=\"display: none\" id=\"pretest\">" +
+ "<div id=\"test\"></div></div>"
document.body?.insertAdjacentHTML("afterbegin", fixture)
}
override fun afterTest() {
val div = document.getElementById("pretest")
div?.remove()
+ jQuery(`object` = ".modal-backdrop").remove()
}
}
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 d9d59c4c..baed1372 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt
@@ -82,4 +82,38 @@ class ContainerSpec : DomSpec {
assertTrue("Container renders children") { elem1 == null && elem2 != null }
}
}
+ @Test
+ fun removeAll() {
+ run {
+ val root = Root("test")
+ val container = Container()
+ val child1 = Widget()
+ child1.id = "child1"
+ val child2 = Widget()
+ child2.id = "child2"
+ container.add(child1)
+ container.add(child2)
+ root.add(container)
+ container.removeAll()
+ val elem1 = document.getElementById("child1")
+ val elem2 = document.getElementById("child2")
+ assertTrue("Children are not rendered") { elem1 == null && elem2 == null }
+ }
+ }
+ @Test
+ fun getChildren() {
+ run {
+ val root = Root("test")
+ val container = Container()
+ val child1 = Widget()
+ child1.id = "child1"
+ val child2 = Widget()
+ child2.id = "child2"
+ container.add(child1)
+ container.add(child2)
+ root.add(container)
+ val childern = container.getChildren()
+ assertTrue("Returns children of current element") { childern.size == 2 }
+ }
+ }
} \ 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 d8739a8b..6407dbc3 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt
@@ -1,6 +1,7 @@
package test.pl.treksoft.kvision.core
import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.modal.Modal
import test.pl.treksoft.kvision.DomSpec
import kotlin.browser.document
import kotlin.test.Test
@@ -34,4 +35,18 @@ class RootSpec : DomSpec {
assertTrue("Should return self") { r == root }
}
}
+
+ @Test
+ fun addModal() {
+ run {
+ val root = Root("test")
+ val modal = Modal("test")
+ modal.id = "test_modal"
+ root.addModal(modal)
+ modal.show()
+ val elem = document.getElementById("test_modal")
+ assertTrue("Should render standard modal") { elem != null }
+ modal.hide()
+ }
+ }
} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt
index 7e4e7814..7bdd3562 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt
@@ -18,8 +18,8 @@ class ModalSpec : DomSpec {
val modal = Modal("Modal")
modal.show()
val content = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() }
- modal.hide()
assertEquals("Modal", content, "Should render correct modal")
+ modal.hide()
}
}
@@ -34,6 +34,7 @@ class ModalSpec : DomSpec {
modal.toggle()
val content2 = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() }
assertNull(content2, "Should hide modal after second toggle")
+ modal.hide()
}
}
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt
new file mode 100644
index 00000000..6e6ede53
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt
@@ -0,0 +1,32 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.jquery.jQuery
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.modal.Alert
+import pl.treksoft.kvision.panel.DIRECTION
+import pl.treksoft.kvision.panel.SplitPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+
+class SplitPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val splitPanel = SplitPanel(DIRECTION.VERTICAL)
+ root.add(splitPanel)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ splitPanel.add(label1)
+ splitPanel.add(label2)
+ val element = document.getElementById("test")
+ assertEquals("<div class=\"splitpanel-vertical\"><span class=\"resizable\">abc</span><div class=\"splitter-vertical\" id=\"kv_splitter_0\" style=\"touch-action: none;\"></div><span>def</span></div>", element?.innerHTML, "Should render correct split panel")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/StackPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/StackPanelSpec.kt
new file mode 100644
index 00000000..9484c194
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/StackPanelSpec.kt
@@ -0,0 +1,74 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.StackPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class StackPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val stackPanel = StackPanel()
+ root.add(stackPanel)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ stackPanel.add(label1)
+ stackPanel.add(label2)
+ val element = document.getElementById("test")
+ assertEquals("<div><span>def</span></div>", element?.innerHTML, "Should render correct stack panel")
+ }
+ }
+
+ @Test
+ fun renderNotActivateLast() {
+ run {
+ val root = Root("test")
+ val stackPanel = StackPanel(activateLast = false)
+ root.add(stackPanel)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ stackPanel.add(label1)
+ stackPanel.add(label2)
+ val element = document.getElementById("test")
+ assertEquals("<div><span>abc</span></div>", element?.innerHTML, "Should render correct stack panel with activateLast = false")
+ }
+ }
+
+ @Test
+ fun remove() {
+ run {
+ val root = Root("test")
+ val stackPanel = StackPanel(activateLast = false)
+ root.add(stackPanel)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ stackPanel.add(label1)
+ stackPanel.add(label2)
+ stackPanel.remove(label1)
+ val element = document.getElementById("test")
+ assertEquals("<div><span>def</span></div>", element?.innerHTML, "Should remove correct child widget")
+ }
+ }
+
+ @Test
+ fun removeAll() {
+ run {
+ val root = Root("test")
+ val stackPanel = StackPanel(activateLast = false)
+ root.add(stackPanel)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ stackPanel.add(label1)
+ stackPanel.add(label2)
+ stackPanel.removeAll()
+ val element = document.getElementById("test")
+ assertEquals("<div></div>", element?.innerHTML, "Should remove all child widgets")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/tabs/TabsSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/tabs/TabsSpec.kt
new file mode 100644
index 00000000..60e2ef60
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/tabs/TabsSpec.kt
@@ -0,0 +1,60 @@
+package test.pl.treksoft.kvision.tabs
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.tabs.Tabs
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class TabsSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val tabs = Tabs()
+ root.add(tabs)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ tabs.addTab("ABC", label1)
+ tabs.addTab("DEF", label2)
+ val element = document.getElementById("test")
+ assertEquals("<div><ul class=\"nav nav-tabs\"><li role=\"presentation\" class=\"active\"><a href=\"#\">ABC</a></li><li role=\"presentation\"><a href=\"#\">DEF</a></li></ul><div><span>abc</span></div></div>", element?.innerHTML, "Should render correct tabs")
+ }
+ }
+
+ @Test
+ fun setActiveIndex() {
+ run {
+ val root = Root("test")
+ val tabs = Tabs()
+ root.add(tabs)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ tabs.addTab("ABC", label1)
+ tabs.addTab("DEF", label2)
+ tabs.activeIndex = 1
+ val element = document.getElementById("test")
+ assertEquals("<div><ul class=\"nav nav-tabs\"><li role=\"presentation\" class=\"\"><a href=\"#\">ABC</a></li><li role=\"presentation\" class=\"active\"><a href=\"#\">DEF</a></li></ul><div><span>def</span></div></div>", element?.innerHTML, "Should change selected tab")
+ }
+ }
+
+ @Test
+ fun removeTab() {
+ run {
+ val root = Root("test")
+ val tabs = Tabs()
+ root.add(tabs)
+ val label1 = Label("abc")
+ val label2 = Label("def")
+ tabs.addTab("ABC", label1)
+ tabs.addTab("DEF", label2)
+ tabs.activeIndex = 1
+ tabs.removeTab(1)
+ val element = document.getElementById("test")
+ assertEquals("<div><ul class=\"nav nav-tabs\"><li role=\"presentation\" class=\"active\"><a href=\"#\">ABC</a></li></ul><div><span>abc</span></div></div>", element?.innerHTML, "Should remove tab")
+ }
+ }
+} \ No newline at end of file