From 9a1be3609acc08349387013430f395b9426c23a0 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 4 Nov 2017 00:06:21 +0100 Subject: Unit tests --- .../pl/treksoft/kvision/form/SelectInputSpec.kt | 29 ++++++++++++++++++++ .../pl/treksoft/kvision/form/SelectOptGroupSpec.kt | 26 ++++++++++++++++++ .../pl/treksoft/kvision/form/SelectOptionSpec.kt | 28 +++++++++++++++++++ .../test/pl/treksoft/kvision/form/SelectSpec.kt | 31 ++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/SelectInputSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptGroupSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptionSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/SelectSpec.kt diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/SelectInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectInputSpec.kt new file mode 100644 index 00000000..988fabbf --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectInputSpec.kt @@ -0,0 +1,29 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.SELECTWIDTHTYPE +import pl.treksoft.kvision.form.SelectInput +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertTrue + +class SelectInputSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val selectInput = SelectInput(listOf("test1" to "Test 1", "test2" to "Test 2"), "test1", true).apply { + liveSearch = true + placeholder = "Choose ..." + selectWidthType = SELECTWIDTHTYPE.FIT + emptyOption = true + } + root.add(selectInput) + val element = document.getElementById("test") + assertTrue(true == element?.innerHTML?.endsWith(""), "Should render correct select input") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptGroupSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptGroupSpec.kt new file mode 100644 index 00000000..5c77152e --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptGroupSpec.kt @@ -0,0 +1,26 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.SelectOptGroup +import pl.treksoft.kvision.form.SelectOption +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class SelectOptGroupSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val selectOptGroup = SelectOptGroup("Group", listOf("test1" to "Test 1", "test2" to "Test 2"), 2) + root.add(selectOptGroup) + val element = document.getElementById("test") + assertEquals("", element?.innerHTML, "Should render correct select option group") + selectOptGroup.add(SelectOption("test3", "Test 3")) + assertEquals("", element?.innerHTML, "Should render correct select option group with added option") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptionSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptionSpec.kt new file mode 100644 index 00000000..a1808d20 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectOptionSpec.kt @@ -0,0 +1,28 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.Password +import pl.treksoft.kvision.form.SelectOption +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class SelectOptionSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val selectOption = SelectOption("testValue", "testLabel") + root.add(selectOption) + val element = document.getElementById("test") + assertEquals("", element?.innerHTML, "Should render correct select option") + selectOption.icon = "fa-flag" + assertEquals("", element?.innerHTML, "Should render correct select option with icon") + selectOption.divider = true + assertEquals("", element?.innerHTML, "Should render correct divider option") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/SelectSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectSpec.kt new file mode 100644 index 00000000..92e4689a --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/SelectSpec.kt @@ -0,0 +1,31 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.SELECTWIDTHTYPE +import pl.treksoft.kvision.form.Select +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertTrue + +class SelectSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val select = Select(listOf("test1" to "Test 1", "test2" to "Test 2"), "test1", true, "Label").apply { + liveSearch = true + placeholder = "Choose ..." + selectWidthType = SELECTWIDTHTYPE.FIT + emptyOption = true + } + root.add(select) + val element = document.getElementById("test") + val id = select.input.id + assertTrue(true == element?.innerHTML?.startsWith("
"), "Should render correct select form field") + assertTrue(true == element?.innerHTML?.endsWith("
"), "Should render correct select form field") + } + } + +} \ No newline at end of file -- cgit