From eddd58f3f31954809645bdf2222833424c3f9a73 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Mon, 8 Oct 2018 21:56:05 +0200 Subject: Testing modules. --- .../kotlin/test/pl/treksoft/kvision/TestUtil.kt | 101 ++++++++++++++++ .../pl/treksoft/kvision/dropdown/DropDownSpec.kt | 132 +++++++++++++++++++++ .../test/pl/treksoft/kvision/modal/AlertSpec.kt | 59 +++++++++ .../pl/treksoft/kvision/modal/CloseIconSpec.kt | 47 ++++++++ .../test/pl/treksoft/kvision/modal/ConfirmSpec.kt | 55 +++++++++ .../test/pl/treksoft/kvision/modal/ModalSpec.kt | 62 ++++++++++ .../test/pl/treksoft/kvision/window/WindowSpec.kt | 54 +++++++++ .../kvision-bootstrap/webpack.config.d/jquery.js | 5 + .../kvision-spinner/webpack.config.d/jquery.js | 5 + .../pl/treksoft/kvision/dropdown/DropDown.kt | 3 + src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 23 +++- .../pl/treksoft/kvision/dropdown/DropDownSpec.kt | 132 --------------------- .../test/pl/treksoft/kvision/modal/AlertSpec.kt | 59 --------- .../pl/treksoft/kvision/modal/CloseIconSpec.kt | 47 -------- .../test/pl/treksoft/kvision/modal/ConfirmSpec.kt | 55 --------- .../test/pl/treksoft/kvision/modal/ModalSpec.kt | 62 ---------- .../test/pl/treksoft/kvision/panel/RootSpec.kt | 14 --- .../test/pl/treksoft/kvision/window/WindowSpec.kt | 54 --------- 18 files changed, 545 insertions(+), 424 deletions(-) create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt create mode 100644 kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt create mode 100644 kvision-modules/kvision-bootstrap/webpack.config.d/jquery.js create mode 100644 kvision-modules/kvision-spinner/webpack.config.d/jquery.js delete mode 100644 src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt delete mode 100644 src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt delete mode 100644 src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt delete mode 100644 src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt delete mode 100644 src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt delete mode 100644 src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt new file mode 100644 index 00000000..6e30f12c --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision + +import org.w3c.dom.Element +import pl.treksoft.jquery.jQuery +import pl.treksoft.kvision.core.Widget +import pl.treksoft.kvision.panel.Root +import kotlin.browser.document +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +val webpack = require("bootstrap") + +interface TestSpec { + fun beforeTest() + + fun afterTest() + + fun run(code: () -> Unit) { + beforeTest() + code() + afterTest() + } +} + +interface SimpleSpec : TestSpec { + + override fun beforeTest() { + } + + override fun afterTest() { + } + +} + +interface DomSpec : TestSpec { + + override fun beforeTest() { + val fixture = "
" + + "
" + document.body?.insertAdjacentHTML("afterbegin", fixture) + } + + override fun afterTest() { + val div = document.getElementById("pretest") + div?.let { jQuery(it).remove() } + jQuery(`object` = ".modal-backdrop").remove() + } + + fun assertEqualsHtml(expected: String?, actual: String?, message: String?) { + if (expected != null && actual != null) { + val exp = jQuery(html = expected) + val act = jQuery(html = actual) + val result = exp[0]?.isEqualNode(act[0]) + if (result == true) { + assertTrue(result == true, message) + } else { + assertEquals(expected, actual, message) + } + } else { + assertEquals(expected, actual, message) + } + } +} + +interface WSpec : DomSpec { + + fun runW(code: (widget: Widget, element: Element?) -> Unit) { + run { + val root = Root("test", true) + val widget = Widget() + widget.id = "test_id" + root.add(widget) + val element = document.getElementById("test_id") + code(widget, element) + } + } + +} + +external fun require(name: String): dynamic diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt new file mode 100644 index 00000000..ff4daea7 --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision.dropdown + +import pl.treksoft.kvision.dropdown.DD +import pl.treksoft.kvision.dropdown.DropDown +import pl.treksoft.kvision.panel.Root +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertTrue + +class DropDownSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test", true) + val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag") + root.add(dd) + dd.toggle() + val element = document.getElementById("test") + val id = dd.buttonId() + assertEqualsHtml( + "
", + element?.innerHTML, + "Should render correct drop down" + ) + } + } + + @Test + fun renderDropUp() { + run { + val root = Root("test", true) + val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag").apply { dropup = true } + root.add(dd) + dd.toggle() + val element = document.getElementById("test") + val id = dd.buttonId() + assertEqualsHtml( + "
", + element?.innerHTML, + "Should render correct drop down" + ) + } + } + + @Test + fun renderHeaderElement() { + run { + val root = Root("test", true) + val dd = DropDown("Dropdown", listOf("abc" to DD.HEADER.option), "flag") + root.add(dd) + dd.toggle() + val element = document.getElementById("test") + val id = dd.buttonId() + assertEqualsHtml( + "
", + element?.innerHTML, + "Should render correct drop down" + ) + } + } + + @Test + fun renderSeparatorElement() { + run { + val root = Root("test", true) + val dd = DropDown("Dropdown", listOf("abc" to DD.SEPARATOR.option), "flag") + root.add(dd) + dd.toggle() + val element = document.getElementById("test") + val id = dd.buttonId() + assertEqualsHtml( + "
", + element?.innerHTML, + "Should render correct drop down" + ) + } + } + + @Test + fun renderDisabledElement() { + run { + val root = Root("test", true) + val dd = DropDown("Dropdown", listOf("abc" to DD.DISABLED.option), "flag") + root.add(dd) + dd.toggle() + val element = document.getElementById("test") + val id = dd.buttonId() + assertEqualsHtml( + "
", + element?.innerHTML, + "Should render correct drop down" + ) + } + } + + @Test + fun toggle() { + run { + val root = Root("test", true) + val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag") + root.add(dd) + val visible = dd.getElementJQuery()?.hasClass("open") ?: false + assertTrue("Dropdown menu is not visible before toggle") { !visible } + dd.toggle() + val visible2 = dd.getElementJQuery()?.hasClass("open") ?: false + assertTrue("Dropdown menu is visible after toggle") { visible2 } + } + } +} \ No newline at end of file diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt new file mode 100644 index 00000000..807f837a --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision.modal + +import pl.treksoft.jquery.jQuery +import pl.treksoft.kvision.modal.Alert +import pl.treksoft.kvision.panel.Root +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", true) + 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("
Alert content
", body, "Should render alert window with correct content") + val footer = document.getElementById("test")?.let { jQuery(it).find(".modal-footer").html() } + assertEqualsHtml( + "", + 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/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt new file mode 100644 index 00000000..2e3ea3ef --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision.modal + +import pl.treksoft.kvision.modal.CloseIcon +import pl.treksoft.kvision.panel.Root +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class CloseIconSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test", true) + val ci = CloseIcon() + root.add(ci) + val element = document.getElementById("test") + assertEqualsHtml( + "", + element?.innerHTML, + "Should render correct close icon" + ) + } + } + +} \ No newline at end of file diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt new file mode 100644 index 00000000..dc734e10 --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision.modal + +import pl.treksoft.jquery.jQuery +import pl.treksoft.kvision.panel.Root +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", true) + 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("
Confirm content
", 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/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt new file mode 100644 index 00000000..523abfd5 --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision.modal + +import pl.treksoft.jquery.jQuery +import pl.treksoft.kvision.modal.Modal +import pl.treksoft.kvision.panel.Root +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", true) + val modal = Modal("Modal") + modal.show() + val content = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() } + assertEquals("Modal", content, "Should render correct modal") + modal.hide() + } + } + + @Test + fun toggle() { + run { + Root("test", true) + 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") + modal.hide() + } + } + +} \ No newline at end of file diff --git a/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt new file mode 100644 index 00000000..477ab1f6 --- /dev/null +++ b/kvision-modules/kvision-bootstrap/src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package test.pl.treksoft.kvision.window + +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.window.Window +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class WindowSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test", true) + val window = Window("Window title", isResizable = false) + root.add(window) + val id = window.id + val element = document.getElementById("test") + assertEqualsHtml( + "

Window title

", + element?.innerHTML, + "Should render floating window without resizable handler" + ) + window.isResizable = true + assertEqualsHtml( + "

Window title

", + element?.innerHTML, + "Should render floating window with resizable handler" + ) + } + } + +} \ No newline at end of file diff --git a/kvision-modules/kvision-bootstrap/webpack.config.d/jquery.js b/kvision-modules/kvision-bootstrap/webpack.config.d/jquery.js new file mode 100644 index 00000000..bf5a1a20 --- /dev/null +++ b/kvision-modules/kvision-bootstrap/webpack.config.d/jquery.js @@ -0,0 +1,5 @@ +config.plugins.push(new webpack.ProvidePlugin({ + $: "jquery", + jQuery: "jquery", + "window.jQuery": "jquery" +})); diff --git a/kvision-modules/kvision-spinner/webpack.config.d/jquery.js b/kvision-modules/kvision-spinner/webpack.config.d/jquery.js new file mode 100644 index 00000000..bf5a1a20 --- /dev/null +++ b/kvision-modules/kvision-spinner/webpack.config.d/jquery.js @@ -0,0 +1,5 @@ +config.plugins.push(new webpack.ProvidePlugin({ + $: "jquery", + jQuery: "jquery", + "window.jQuery": "jquery" +})); diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index 5f5f789c..4ae1e93b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -142,6 +142,9 @@ open class DropDown( idc, text, icon, style, disabled, forNavbar, withCaret, setOf("dropdown") ) + + fun buttonId() = button.id + internal val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu")) init { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index b45eed60..19f7e68a 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -42,6 +42,27 @@ internal data class FieldParams( val validator: ((F) -> Boolean?)? = null ) +/** + * A wrapper for a Map with a custom containsKey method implementation. + * Used with kotlinx.serialization Mapper. + */ +private class FormMapWrapper(private val map: Map) : Map { + override fun equals(other: Any?): Boolean = map == other + override fun hashCode(): Int = map.hashCode() + override fun toString(): String = map.toString() + override val size: Int get() = map.size + override fun isEmpty(): Boolean = map.isEmpty() + override fun containsKey(key: String): Boolean = + if (key.indexOf('.') != -1) map.containsKey(key) else + !(map.containsKey("$key.time") || map.containsKey("$key.size")) + + override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value) + override fun get(key: String): V? = map[key] + override val keys: Set get() = map.keys + override val values: Collection get() = map.values + override val entries: Set> get() = map.entries +} + /** * The form definition class. Can be used directly or indirectly inside a [FormPanel]. * @@ -82,7 +103,7 @@ class Form(private val panel: FormPanel? = null, private val seriali else -> listOf(entry.key to entry.value) } }.toMap() - val mapper = Mapper.InNullableMapper(map) + val mapper = Mapper.InNullableMapper(FormMapWrapper(map)) mapper.decode(serializer) } } diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt deleted file mode 100644 index 9aa088fd..00000000 --- a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package test.pl.treksoft.kvision.dropdown - -import pl.treksoft.kvision.dropdown.DD -import pl.treksoft.kvision.dropdown.DropDown -import pl.treksoft.kvision.panel.Root -import test.pl.treksoft.kvision.DomSpec -import kotlin.browser.document -import kotlin.test.Test -import kotlin.test.assertTrue - -class DropDownSpec : DomSpec { - - @Test - fun render() { - run { - val root = Root("test", true) - val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag") - root.add(dd) - dd.toggle() - val element = document.getElementById("test") - val id = dd.button.id - assertEqualsHtml( - "
", - element?.innerHTML, - "Should render correct drop down" - ) - } - } - - @Test - fun renderDropUp() { - run { - val root = Root("test", true) - val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag").apply { dropup = true } - root.add(dd) - dd.toggle() - val element = document.getElementById("test") - val id = dd.button.id - assertEqualsHtml( - "
", - element?.innerHTML, - "Should render correct drop down" - ) - } - } - - @Test - fun renderHeaderElement() { - run { - val root = Root("test", true) - val dd = DropDown("Dropdown", listOf("abc" to DD.HEADER.option), "flag") - root.add(dd) - dd.toggle() - val element = document.getElementById("test") - val id = dd.button.id - assertEqualsHtml( - "
  • abc
", - element?.innerHTML, - "Should render correct drop down" - ) - } - } - - @Test - fun renderSeparatorElement() { - run { - val root = Root("test", true) - val dd = DropDown("Dropdown", listOf("abc" to DD.SEPARATOR.option), "flag") - root.add(dd) - dd.toggle() - val element = document.getElementById("test") - val id = dd.button.id - assertEqualsHtml( - "
", - element?.innerHTML, - "Should render correct drop down" - ) - } - } - - @Test - fun renderDisabledElement() { - run { - val root = Root("test", true) - val dd = DropDown("Dropdown", listOf("abc" to DD.DISABLED.option), "flag") - root.add(dd) - dd.toggle() - val element = document.getElementById("test") - val id = dd.button.id - assertEqualsHtml( - "
", - element?.innerHTML, - "Should render correct drop down" - ) - } - } - - @Test - fun toggle() { - run { - val root = Root("test", true) - val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag") - root.add(dd) - val visible = dd.getElementJQuery()?.hasClass("open") ?: false - assertTrue("Dropdown menu is not visible before toggle") { !visible } - dd.toggle() - val visible2 = dd.getElementJQuery()?.hasClass("open") ?: false - assertTrue("Dropdown menu is visible after toggle") { visible2 } - } - } -} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt deleted file mode 100644 index 807f837a..00000000 --- a/src/test/kotlin/test/pl/treksoft/kvision/modal/AlertSpec.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package test.pl.treksoft.kvision.modal - -import pl.treksoft.jquery.jQuery -import pl.treksoft.kvision.modal.Alert -import pl.treksoft.kvision.panel.Root -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", true) - 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("
Alert content
", body, "Should render alert window with correct content") - val footer = document.getElementById("test")?.let { jQuery(it).find(".modal-footer").html() } - assertEqualsHtml( - "", - 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/CloseIconSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt deleted file mode 100644 index 2e3ea3ef..00000000 --- a/src/test/kotlin/test/pl/treksoft/kvision/modal/CloseIconSpec.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package test.pl.treksoft.kvision.modal - -import pl.treksoft.kvision.modal.CloseIcon -import pl.treksoft.kvision.panel.Root -import test.pl.treksoft.kvision.DomSpec -import kotlin.browser.document -import kotlin.test.Test - -class CloseIconSpec : DomSpec { - - @Test - fun render() { - run { - val root = Root("test", true) - val ci = CloseIcon() - root.add(ci) - val element = document.getElementById("test") - assertEqualsHtml( - "", - element?.innerHTML, - "Should render correct close icon" - ) - } - } - -} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt deleted file mode 100644 index dc734e10..00000000 --- a/src/test/kotlin/test/pl/treksoft/kvision/modal/ConfirmSpec.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package test.pl.treksoft.kvision.modal - -import pl.treksoft.jquery.jQuery -import pl.treksoft.kvision.panel.Root -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", true) - 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("
Confirm content
", 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 deleted file mode 100644 index 523abfd5..00000000 --- a/src/test/kotlin/test/pl/treksoft/kvision/modal/ModalSpec.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package test.pl.treksoft.kvision.modal - -import pl.treksoft.jquery.jQuery -import pl.treksoft.kvision.modal.Modal -import pl.treksoft.kvision.panel.Root -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", true) - val modal = Modal("Modal") - modal.show() - val content = document.getElementById("test")?.let { jQuery(it).find(".modal-title").html() } - assertEquals("Modal", content, "Should render correct modal") - modal.hide() - } - } - - @Test - fun toggle() { - run { - Root("test", true) - 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") - modal.hide() - } - } - -} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/RootSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/RootSpec.kt index d90abbe8..9e4342cc 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/panel/RootSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/RootSpec.kt @@ -56,18 +56,4 @@ class RootSpec : DomSpec { assertTrue("Should return self") { r == root } } } - - @Test - fun addModal() { - run { - val root = Root("test", true) - 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/window/WindowSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt deleted file mode 100644 index fde2335d..00000000 --- a/src/test/kotlin/test/pl/treksoft/kvision/window/WindowSpec.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package test.pl.treksoft.kvision.window - -import pl.treksoft.kvision.panel.Root -import pl.treksoft.kvision.window.Window -import test.pl.treksoft.kvision.DomSpec -import kotlin.browser.document -import kotlin.test.Test - -class WindowSpec : DomSpec { - - @Test - fun render() { - run { - val root = Root("test", true) - val window = Window("Window title", isResizable = false) - root.add(window) - val id = window.id - val element = document.getElementById("test") - assertEqualsHtml( - "

Window title

", - element?.innerHTML, - "Should render floating window without resizable handler" - ) - window.isResizable = true - assertEqualsHtml( - "

Window title

", - element?.innerHTML, - "Should render floating window with resizable handler" - ) - } - } - -} \ No newline at end of file -- cgit