summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt4
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt4
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt34
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt35
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt40
5 files changed, 113 insertions, 4 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
index e2f88e72..708752ea 100644
--- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
@@ -74,9 +74,9 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
}
private val idc = "kv_dropdown_" + counter
- protected val button: DropDownButton = DropDownButton(idc, text, icon, style, size, block,
+ internal val button: DropDownButton = DropDownButton(idc, text, icon, style, size, block,
disabled, image, setOf("dropdown"))
- protected val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu"))
+ internal val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu"))
init {
button.setEventListener {
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt b/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt
index dd2093cd..a4ac44ed 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt
@@ -20,12 +20,12 @@ interface TestSpec {
interface DomSpec : TestSpec {
override fun beforeTest() {
- val fixture = "<div style=\"display: none\"><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("test")
+ val div = document.getElementById("pretest")
div?.remove()
}
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt
new file mode 100644
index 00000000..328bbfca
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt
@@ -0,0 +1,34 @@
+package test.pl.treksoft.kvision.modal
+
+import pl.treksoft.jquery.jQuery
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.modal.Alert
+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 AlertSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ Root("test")
+ Alert.show("Alert caption", "Alert content")
+ val alert = document.getElementById("test")?.let { jQuery(it).find(".modal")[0] }
+ assertNotNull(alert, "Should show alert window")
+ val title = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() }
+ assertEquals("Alert caption", title, "Should render alert window with correct caption")
+ val body = document.getElementById("test")?.let { jQuery(it).find(".modal-body").html() }
+ assertEquals("<span>Alert content</span>", body, "Should render alert window with correct content")
+ val footer = document.getElementById("test")?.let { jQuery(it).find(".modal-footer").html() }
+ assertEquals("<button class=\"btn btn-primary\" type=\"button\"><span class=\"glyphicon glyphicon-ok\"></span> OK</button>", footer, "Should render alert window with correct footer")
+ val button = document.getElementById("test")?.let { jQuery(it).find(".modal-footer").find("button") }
+ button?.click()
+ val alert2 = document.getElementById("test")?.let { jQuery(it).find(".modal")[0] }
+ assertNull(alert2, "Should hide alert window after clicking OK")
+ }
+ }
+}
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt
new file mode 100644
index 00000000..9e91be0a
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt
@@ -0,0 +1,35 @@
+package test.pl.treksoft.kvision.modal
+
+import pl.treksoft.jquery.jQuery
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.modal.Alert
+import pl.treksoft.kvision.modal.Confirm
+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 ConfirmSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ Root("test")
+ Confirm.show("Confirm caption", "Confirm content")
+ val confirm = document.getElementById("test")?.let { jQuery(it).find(".modal")[0] }
+ assertNotNull(confirm, "Should show confirm window")
+ val title = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() }
+ assertEquals("Confirm caption", title, "Should render confirm window with correct caption")
+ val body = document.getElementById("test")?.let { jQuery(it).find(".modal-body").html() }
+ assertEquals("<span>Confirm content</span>", body, "Should render confirm window with correct content")
+ val buttons = document.getElementById("test")?.let { jQuery(it).find(".modal-footer").find("button") }
+ assertEquals(2, buttons?.length, "Should render confirm window with two buttons")
+ val button = document.getElementById("test")?.let { jQuery(it).find(".modal-footer").find("button")[0] }
+ button?.click()
+ val confirm2 = document.getElementById("test")?.let { jQuery(it).find(".modal")[0] }
+ assertNull(confirm2, "Should hide confirm window after clicking YES")
+ }
+ }
+} \ 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
new file mode 100644
index 00000000..7e4e7814
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt
@@ -0,0 +1,40 @@
+package test.pl.treksoft.kvision.modal
+
+import pl.treksoft.jquery.jQuery
+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
+import kotlin.test.assertEquals
+import kotlin.test.assertNull
+
+class ModalSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ Root("test")
+ 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")
+ }
+ }
+
+ @Test
+ fun toggle() {
+ run {
+ Root("test")
+ val modal = Modal("Modal")
+ modal.toggle()
+ val content = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() }
+ assertEquals("Modal", content, "Should show modal after toggle")
+ modal.toggle()
+ val content2 = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() }
+ assertNull(content2, "Should hide modal after second toggle")
+ }
+ }
+
+} \ No newline at end of file