diff options
Diffstat (limited to 'src/test/kotlin')
4 files changed, 111 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 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 |