aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-01-16 00:13:54 +0100
committerRobert Jaros <rjaros@finn.pl>2018-01-16 00:13:54 +0100
commitbcc5292dd95e5824da41a19bfbf64ebc25d79102 (patch)
tree5a97a4da432d2db97ea2fa6755c8b0e42394690f /src/test/kotlin
parenta107c5b7fe1cf0429436045e336b08d16b387367 (diff)
downloadkvision-bcc5292dd95e5824da41a19bfbf64ebc25d79102.tar.gz
kvision-bcc5292dd95e5824da41a19bfbf64ebc25d79102.tar.bz2
kvision-bcc5292dd95e5824da41a19bfbf64ebc25d79102.zip
Spinner form controls
Unit tests
Diffstat (limited to 'src/test/kotlin')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerInputSpec.kt54
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerSpec.kt53
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt28
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt34
4 files changed, 169 insertions, 0 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerInputSpec.kt
new file mode 100644
index 00000000..8c90c684
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerInputSpec.kt
@@ -0,0 +1,54 @@
+package test.pl.treksoft.kvision.form.spinner
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.form.spinner.SpinnerInput
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class SpinnerInputSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val si = SpinnerInput(value = 13).apply {
+ placeholder = "place"
+ id = "idti"
+ }
+ root.add(si)
+ val value = si.getElementJQuery()?.`val`()
+ assertEquals("13", value, "Should render spinner input with correct value")
+ }
+ }
+
+ @Test
+ fun spinUp() {
+ run {
+ val root = Root("test")
+ val si = SpinnerInput(value = 13).apply {
+ placeholder = "place"
+ id = "idti"
+ }
+ root.add(si)
+ assertEquals(13, si.value, "Should return initial value before spinUp")
+ si.spinUp()
+ assertEquals(14, si.value, "Should return changed value after spinUp")
+ }
+ }
+
+ @Test
+ fun spinDown() {
+ run {
+ val root = Root("test")
+ val si = SpinnerInput(value = 13).apply {
+ placeholder = "place"
+ id = "idti"
+ }
+ root.add(si)
+ assertEquals(13, si.value, "Should return initial value before spinDown")
+ si.spinDown()
+ assertEquals(12, si.value, "Should return changed value after spinDown")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerSpec.kt
new file mode 100644
index 00000000..b800f297
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/spinner/SpinnerSpec.kt
@@ -0,0 +1,53 @@
+package test.pl.treksoft.kvision.form.spinner
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.form.spinner.Spinner
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class SpinnerSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val ti = Spinner(value = 13, label = "Label").apply {
+ placeholder = "place"
+ name = "name"
+ disabled = true
+ }
+ root.add(ti)
+ val element = document.getElementById("test")
+ val id = ti.input.id
+ assertEquals("<div class=\"form-group\"><label class=\"control-label\" for=\"$id\">Label</label><div class=\"input-group kv-spinner-btn-vertical\"><span><div class=\"input-group bootstrap-touchspin\"><span class=\"input-group-addon bootstrap-touchspin-prefix\" style=\"display: none;\"></span><input class=\"form-control\" id=\"$id\" type=\"text\" value=\"13\" placeholder=\"place\" name=\"name\" disabled=\"\" style=\"display: block;\"><span class=\"input-group-addon bootstrap-touchspin-postfix\" style=\"display: none;\"></span><span class=\"input-group-btn-vertical\"><button class=\"btn btn-default bootstrap-touchspin-up\" type=\"button\"><i class=\"glyphicon glyphicon-chevron-up\"></i></button><button class=\"btn btn-default bootstrap-touchspin-down\" type=\"button\"><i class=\"glyphicon glyphicon-chevron-down\"></i></button></span></div></span></div></div>", element?.innerHTML, "Should render correct spinner input form control")
+ ti.validatorError = "Validation Error"
+ assertEquals("<div class=\"form-group has-error\"><label class=\"control-label\" for=\"$id\">Label</label><div class=\"input-group kv-spinner-btn-vertical\"><span><div class=\"input-group bootstrap-touchspin\"><span class=\"input-group-addon bootstrap-touchspin-prefix\" style=\"display: none;\"></span><input class=\"form-control\" id=\"$id\" type=\"text\" value=\"13\" placeholder=\"place\" name=\"name\" disabled=\"\" style=\"display: block;\"><span class=\"input-group-addon bootstrap-touchspin-postfix\" style=\"display: none;\"></span><span class=\"input-group-btn-vertical\"><button class=\"btn btn-default bootstrap-touchspin-up\" type=\"button\"><i class=\"glyphicon glyphicon-chevron-up\"></i></button><button class=\"btn btn-default bootstrap-touchspin-down\" type=\"button\"><i class=\"glyphicon glyphicon-chevron-down\"></i></button></span></div></span></div><span class=\"help-block small\">Validation Error</span></div>", element?.innerHTML, "Should render correct spinner input form control with validation error")
+ }
+ }
+
+ @Test
+ fun spinUp() {
+ run {
+ val root = Root("test")
+ val si = Spinner(value = 13)
+ root.add(si)
+ assertEquals(13, si.value, "Should return initial value before spinUp")
+ si.spinUp()
+ assertEquals(14, si.value, "Should return changed value after spinUp")
+ }
+ }
+
+ @Test
+ fun spinDown() {
+ run {
+ val root = Root("test")
+ val si = Spinner(value = 13)
+ root.add(si)
+ assertEquals(13, si.value, "Should return initial value before spinDown")
+ si.spinDown()
+ assertEquals(12, si.value, "Should return changed value after spinDown")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt
new file mode 100644
index 00000000..fe6c2b45
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt
@@ -0,0 +1,28 @@
+package test.pl.treksoft.kvision.form.time
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.form.time.DateTimeInput
+import pl.treksoft.kvision.utils.toStringF
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.js.Date
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DateTimeInputSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val data = Date()
+ val dti = DateTimeInput(value = data).apply {
+ placeholder = "place"
+ id = "idti"
+ }
+ root.add(dti)
+ val value = dti.getElementJQuery()?.`val`()
+ assertEquals(data.toStringF(dti.format), value, "Should render date time input with correctly formatted value")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt
new file mode 100644
index 00000000..1a8665b1
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt
@@ -0,0 +1,34 @@
+package test.pl.treksoft.kvision.form.time
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.form.time.DateTime
+import pl.treksoft.kvision.utils.toStringF
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.js.Date
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DateTimeSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val data = Date()
+ val ti = DateTime(value = data, label = "Label").apply {
+ placeholder = "place"
+ name = "name"
+ disabled = true
+ }
+ root.add(ti)
+ val element = document.getElementById("test")
+ val id = ti.input.id
+ val datastr = data.toStringF(ti.format)
+ assertEquals("<div class=\"form-group\"><label class=\"control-label\" for=\"$id\">Label</label><input class=\"form-control\" id=\"$id\" type=\"text\" placeholder=\"place\" name=\"name\" disabled=\"\" value=\"$datastr\"></div>", element?.innerHTML, "Should render correct date time input form control")
+ ti.validatorError = "Validation Error"
+ assertEquals("<div class=\"form-group has-error\"><label class=\"control-label\" for=\"$id\">Label</label><input class=\"form-control\" id=\"$id\" type=\"text\" placeholder=\"place\" name=\"name\" disabled=\"\" value=\"$datastr\"><span class=\"help-block small\">Validation Error</span></div>", element?.innerHTML, "Should render correct date time input form control with validation error")
+ }
+ }
+
+} \ No newline at end of file