From 94d1930aaf160d7271aabe97bf167a911391210b Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 19 Oct 2017 13:00:36 +0200 Subject: Unit tests --- src/main/kotlin/pl/treksoft/kvision/Showcase.kt | 1 + .../pl/treksoft/kvision/form/CheckBoxInput.kt | 4 +-- .../kotlin/pl/treksoft/kvision/form/TextInput.kt | 2 +- .../kotlin/pl/treksoft/kvision/panel/SplitPanel.kt | 2 +- .../pl/treksoft/kvision/dropdown/DropDownSpec.kt | 15 +++++++---- .../pl/treksoft/kvision/form/CheckBoxInputSpec.kt | 25 ++++++++++++++++++ .../test/pl/treksoft/kvision/form/CheckBoxSpec.kt | 30 ++++++++++++++++++++++ .../pl/treksoft/kvision/form/FieldLabelSpec.kt | 23 +++++++++++++++++ .../test/pl/treksoft/kvision/form/PasswordSpec.kt | 26 +++++++++++++++++++ .../test/pl/treksoft/kvision/form/TextInputSpec.kt | 25 ++++++++++++++++++ .../test/pl/treksoft/kvision/form/TextSpec.kt | 25 ++++++++++++++++++ .../pl/treksoft/kvision/panel/SplitPanelSpec.kt | 3 ++- 12 files changed, 171 insertions(+), 10 deletions(-) create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxInputSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/FieldLabelSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt index bf0691e1..1eb0f319 100644 --- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -236,6 +236,7 @@ class Showcase : ApplicationBase() { println(self.text) println(textField.value) println(checkbox.value) + textField2.disabled = false grid4.colorHex = 0xff0000 dd3.text = "Zmiana" dd3.style = BUTTONSTYLE.WARNING diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt index 1893668b..44383629 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt @@ -52,13 +52,13 @@ open class CheckBoxInput(override var value: Boolean = false, val sn = super.getSnAttrs().toMutableList() sn.add("type" to "checkbox") if (startValue) { - sn.add("checked" to "checked") + sn.add("checked" to "true") } name?.let { sn.add("name" to it) } if (disabled) { - sn.add("disabled" to "disabled") + sn.add("disabled" to "true") } return sn } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt index a87cb164..08a39e87 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt @@ -118,7 +118,7 @@ class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? = } } if (disabled) { - sn.add("disabled" to "disabled") + sn.add("disabled" to "true") } return sn } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt index 06f9be59..03740222 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt @@ -18,7 +18,7 @@ open class SplitPanel(private val direction: DIRECTION = DIRECTION.VERTICAL, classes: Set = setOf()) : Container(classes + ("splitpanel-" + direction.dir)) { @Suppress("LeakingThis") - private val splitter = Splitter(this, direction) + internal val splitter = Splitter(this, direction) @Suppress("UnsafeCastFromDynamic") internal fun afterInsertSplitter() { diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt index 8f327928..5f417f03 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt @@ -19,7 +19,8 @@ class DropDownSpec : DomSpec { root.add(dd) dd.toggle() val element = document.getElementById("test") - assertEquals("
", element?.innerHTML, "Should render correct drop down") + val id = dd.button.id + assertEquals("
", element?.innerHTML, "Should render correct drop down") } } @@ -31,7 +32,8 @@ class DropDownSpec : DomSpec { root.add(dd) dd.toggle() val element = document.getElementById("test") - assertEquals("
", element?.innerHTML, "Should render correct drop down") + val id = dd.button.id + assertEquals("
", element?.innerHTML, "Should render correct drop down") } } @@ -43,7 +45,8 @@ class DropDownSpec : DomSpec { root.add(dd) dd.toggle() val element = document.getElementById("test") - assertEquals("
  • abc
", element?.innerHTML, "Should render correct drop down") + val id = dd.button.id + assertEquals("
  • abc
", element?.innerHTML, "Should render correct drop down") } } @@ -55,7 +58,8 @@ class DropDownSpec : DomSpec { root.add(dd) dd.toggle() val element = document.getElementById("test") - assertEquals("
  • abc
", element?.innerHTML, "Should render correct drop down") + val id = dd.button.id + assertEquals("
  • abc
", element?.innerHTML, "Should render correct drop down") } } @@ -67,7 +71,8 @@ class DropDownSpec : DomSpec { root.add(dd) dd.toggle() val element = document.getElementById("test") - assertEquals("
", element?.innerHTML, "Should render correct drop down") + val id = dd.button.id + assertEquals("
", element?.innerHTML, "Should render correct drop down") } } diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxInputSpec.kt new file mode 100644 index 00000000..780c0337 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxInputSpec.kt @@ -0,0 +1,25 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.CheckBoxInput +import pl.treksoft.kvision.form.TEXTINPUTTYPE +import pl.treksoft.kvision.form.TextInput +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class CheckBoxInputSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val ci = CheckBoxInput(value = true, name = "name", id = "idti", disabled = true) + root.add(ci) + val element = document.getElementById("test") + assertEquals("", element?.innerHTML, "Should render correct checkbox field") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt new file mode 100644 index 00000000..3da204b3 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt @@ -0,0 +1,30 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.CHECKBOXSTYLE +import pl.treksoft.kvision.form.CheckBox +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class CheckBoxSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val ci = CheckBox(value = true, name = "name", style = CHECKBOXSTYLE.DANGER, disabled = true, circled = true, + inline = true, label = "Label") + root.add(ci) + val element = document.getElementById("test") + val id = ci.input.id + assertEquals("
", element?.innerHTML, "Should render correct checkbox form field") + ci.style = CHECKBOXSTYLE.INFO + ci.circled = false + ci.inline = false + assertEquals("
", element?.innerHTML, "Should render correct checkbox form field") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/FieldLabelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/FieldLabelSpec.kt new file mode 100644 index 00000000..3cca28cf --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/FieldLabelSpec.kt @@ -0,0 +1,23 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.FieldLabel +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class FieldLabelSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val fl = FieldLabel("input", "Label") + root.add(fl) + val element = document.getElementById("test") + assertEquals("", element?.innerHTML, "Should render correct label") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt new file mode 100644 index 00000000..4563da03 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt @@ -0,0 +1,26 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.Password +import pl.treksoft.kvision.form.Text +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class PasswordSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val ti = Password(placeholder = "place", value = "abc", name = "name", + maxlength = 15, disabled = true, label = "Label") + root.add(ti) + val element = document.getElementById("test") + val id = ti.input.id + assertEquals("
", element?.innerHTML, "Should render correct input form field") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt new file mode 100644 index 00000000..55325436 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt @@ -0,0 +1,25 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.TEXTINPUTTYPE +import pl.treksoft.kvision.form.TextInput +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class TextInputSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val ti = TextInput(type = TEXTINPUTTYPE.PASSWORD, placeholder = "place", value = "abc", name = "name", + maxlength = 15, id = "idti", disabled = true) + root.add(ti) + val element = document.getElementById("test") + assertEquals("", element?.innerHTML, "Should render correct input field") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt new file mode 100644 index 00000000..5e378d55 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt @@ -0,0 +1,25 @@ +package test.pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.form.Text +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test +import kotlin.test.assertEquals + +class TextSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val ti = Text(placeholder = "place", value = "abc", name = "name", + maxlength = 15, disabled = true, label = "Label") + root.add(ti) + val element = document.getElementById("test") + val id = ti.input.id + assertEquals("
", element?.innerHTML, "Should render correct input form field") + } + } + +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt index 6e6ede53..e3442f59 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/SplitPanelSpec.kt @@ -26,7 +26,8 @@ class SplitPanelSpec : DomSpec { splitPanel.add(label1) splitPanel.add(label2) val element = document.getElementById("test") - assertEquals("
abc
def
", element?.innerHTML, "Should render correct split panel") + val id = splitPanel.splitter.id + assertEquals("
abc
def
", element?.innerHTML, "Should render correct split panel") } } } \ No newline at end of file -- cgit