diff options
author | Robert Jaros <rjaros@finn.pl> | 2017-11-04 00:06:21 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2017-11-04 00:06:21 +0100 |
commit | 9a1be3609acc08349387013430f395b9426c23a0 (patch) | |
tree | bc81a82e74ca6f984cfddd9ab51e802b265b6895 | |
parent | c28f003eb5c588c5942b86521991c46374ad190a (diff) | |
download | kvision-9a1be3609acc08349387013430f395b9426c23a0.tar.gz kvision-9a1be3609acc08349387013430f395b9426c23a0.tar.bz2 kvision-9a1be3609acc08349387013430f395b9426c23a0.zip |
Unit tests
4 files changed, 114 insertions, 0 deletions
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("<select class=\"selectpicker\" multiple=\"\" data-live-search=\"true\" title=\"Choose ...\" data-style=\"btn-default\" data-width=\"fit\" tabindex=\"-98\"><option value=\"#kvnull\"></option><option value=\"test1\">Test 1</option><option value=\"test2\">Test 2</option></select></div>"), "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("<optgroup label=\"Group\" data-max-options=\"2\"><option value=\"test1\">Test 1</option><option value=\"test2\">Test 2</option></optgroup>", element?.innerHTML, "Should render correct select option group") + selectOptGroup.add(SelectOption("test3", "Test 3")) + assertEquals("<optgroup label=\"Group\" data-max-options=\"2\"><option value=\"test1\">Test 1</option><option value=\"test2\">Test 2</option><option value=\"test3\">Test 3</option></optgroup>", 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("<option value=\"testValue\">testLabel</option>", element?.innerHTML, "Should render correct select option") + selectOption.icon = "fa-flag" + assertEquals("<option value=\"testValue\" data-icon=\"fa fa-flag\">testLabel</option>", element?.innerHTML, "Should render correct select option with icon") + selectOption.divider = true + assertEquals("<option data-divider=\"true\"></option>", 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("<div class=\"form-group\"><label for=\"$id\">Label</label>"), "Should render correct select form field") + assertTrue(true == element?.innerHTML?.endsWith("<select class=\"form-control selectpicker\" id=\"$id\" multiple=\"\" data-live-search=\"true\" title=\"Choose ...\" data-style=\"btn-default\" data-width=\"fit\" tabindex=\"-98\"><option value=\"#kvnull\"></option><option value=\"test1\">Test 1</option><option value=\"test2\">Test 2</option></select></div></div>"), "Should render correct select form field") + } + } + +}
\ No newline at end of file |