diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-04-25 08:12:25 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-04-25 08:12:25 +0200 |
commit | 5b9535e9964816eb228d3797f4c8a3e7676d1f53 (patch) | |
tree | 00889e3c489288d6386367e8ac26973868e11f8f /src/test | |
parent | 76c436567b87672609879a11762202599ed27af4 (diff) | |
download | kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.tar.gz kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.tar.bz2 kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.zip |
Multiplatform kvision-common and kvision-server modules.
Support for automatic remote bindings (work in progress).
Diffstat (limited to 'src/test')
4 files changed, 58 insertions, 153 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/FormPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/FormPanelSpec.kt index 33b439a5..5c07ca58 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/form/FormPanelSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/FormPanelSpec.kt @@ -24,8 +24,8 @@ package test.pl.treksoft.kvision.form import pl.treksoft.kvision.form.FormPanel import pl.treksoft.kvision.form.text.Text import pl.treksoft.kvision.form.time.DateTime +import pl.treksoft.kvision.types.KDate import test.pl.treksoft.kvision.SimpleSpec -import kotlin.js.Date import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -37,16 +37,8 @@ class FormPanelSpec : SimpleSpec { @Test fun add() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val formPanel = FormPanel.create<DataForm>() + val data = DataForm(a = "Test value") formPanel.setData(data) val result = formPanel.getData() assertNull(result.a, "FormPanel should return null without adding any control") @@ -61,16 +53,8 @@ class FormPanelSpec : SimpleSpec { @Test fun remove() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val formPanel = FormPanel.create<DataForm>() + val data = DataForm(a = "Test value") formPanel.add(DataForm::a, Text()) formPanel.setData(data) formPanel.remove(DataForm::a) @@ -82,16 +66,8 @@ class FormPanelSpec : SimpleSpec { @Test fun removeAll() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val formPanel = FormPanel.create<DataForm>() + val data = DataForm(a = "Test value") formPanel.add(DataForm::a, Text()) formPanel.setData(data) formPanel.removeAll() @@ -103,15 +79,7 @@ class FormPanelSpec : SimpleSpec { @Test fun getControl() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } + val formPanel = FormPanel.create<DataForm>() formPanel.add(DataForm::a, Text()) val control = formPanel.getControl(DataForm::b) assertNull(control, "Should return null when there is no such control") @@ -123,16 +91,8 @@ class FormPanelSpec : SimpleSpec { @Test fun get() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val formPanel = FormPanel.create<DataForm>() + val data = DataForm(a = "Test value") formPanel.add(DataForm::a, Text()) val b = formPanel[DataForm::b] assertNull(b, "Should return null value when there is no added control") @@ -147,16 +107,8 @@ class FormPanelSpec : SimpleSpec { @Test fun getData() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val formPanel = FormPanel.create<DataForm>() + val data = DataForm(a = "Test value") val textField = Text() formPanel.add(DataForm::a, textField) formPanel.setData(data) @@ -169,25 +121,18 @@ class FormPanelSpec : SimpleSpec { @Test fun validate() { run { - class DataForm(val map: Map<String, Any?>) { - val s: String? by map - val d: Date? by map - } - - val formPanel = FormPanel { - DataForm(it) - } - formPanel.add(DataForm::s, Text()) { + val formPanel = FormPanel.create<DataForm2>() + formPanel.add(DataForm2::s, Text()) { it.getValue()?.length ?: 0 > 4 } - formPanel.add(DataForm::d, DateTime(), required = true) - formPanel.setData(DataForm(mapOf("s" to "123"))) + formPanel.add(DataForm2::d, DateTime(), required = true) + formPanel.setData(DataForm2(s = "123")) val valid = formPanel.validate() assertEquals(false, valid, "Should be invalid with initial data") - formPanel.setData(DataForm(mapOf("s" to "12345"))) + formPanel.setData(DataForm2(s = "12345")) val valid2 = formPanel.validate() assertEquals(false, valid2, "Should be invalid with partially changed data") - formPanel.setData(DataForm(mapOf("s" to "12345", "d" to Date()))) + formPanel.setData(DataForm2(s = "12345", d = KDate())) val valid3 = formPanel.validate() assertEquals(true, valid3, "Should be valid") } diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/FormSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/FormSpec.kt index ee3cd2af..f673018a 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/form/FormSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/FormSpec.kt @@ -21,32 +21,39 @@ */ package test.pl.treksoft.kvision.form +import kotlinx.serialization.Serializable import pl.treksoft.kvision.form.Form import pl.treksoft.kvision.form.text.Text import pl.treksoft.kvision.form.time.DateTime +import pl.treksoft.kvision.types.KDate import test.pl.treksoft.kvision.SimpleSpec -import kotlin.js.Date import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull +@Serializable +data class DataForm( + val a: String? = null, + val b: Boolean? = null, + val c: KDate? = null +) + +@Serializable +data class DataForm2( + val s: String? = null, + val d: KDate? = null +) + + @Suppress("CanBeParameter") class FormSpec : SimpleSpec { @Test fun add() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val form = Form { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val form = Form.create<DataForm>() + val data = DataForm(a = "Test value") form.setData(data) val result = form.getData() assertNull(result.a, "Form should return null without adding any control") @@ -61,16 +68,8 @@ class FormSpec : SimpleSpec { @Test fun remove() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val form = Form { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val form = Form.create<DataForm>() + val data = DataForm(a = "Test value") form.add(DataForm::a, Text()) form.setData(data) form.remove(DataForm::a) @@ -82,16 +81,8 @@ class FormSpec : SimpleSpec { @Test fun removeAll() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val form = Form { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val form = Form.create<DataForm>() + val data = DataForm(a = "Test value") form.add(DataForm::a, Text()) form.setData(data) form.removeAll() @@ -103,15 +94,7 @@ class FormSpec : SimpleSpec { @Test fun getControl() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val form = Form { - DataForm(it) - } + val form = Form.create<DataForm>() form.add(DataForm::a, Text()) val control = form.getControl(DataForm::b) assertNull(control, "Should return null when there is no such control") @@ -123,16 +106,8 @@ class FormSpec : SimpleSpec { @Test fun get() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val form = Form { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val form = Form.create<DataForm>() + val data = DataForm(a = "Test value") form.add(DataForm::a, Text()) val b = form[DataForm::b] assertNull(b, "Should return null value when there is no added control") @@ -147,16 +122,8 @@ class FormSpec : SimpleSpec { @Test fun getData() { run { - class DataForm(val map: Map<String, Any?>) { - val a: String? by map - val b: Boolean? by map - val c: Date? by map - } - - val form = Form { - DataForm(it) - } - val data = DataForm(mapOf("a" to "Test value")) + val form = Form.create<DataForm>() + val data = DataForm(a = "Test value") val textField = Text() form.add(DataForm::a, textField) form.setData(data) @@ -169,25 +136,18 @@ class FormSpec : SimpleSpec { @Test fun validate() { run { - class DataForm(val map: Map<String, Any?>) { - val s: String? by map - val d: Date? by map - } - - val form = Form { - DataForm(it) - } - form.add(DataForm::s, Text()) { + val form = Form.create<DataForm2>() + form.add(DataForm2::s, Text()) { it.getValue()?.length ?: 0 > 4 } - form.add(DataForm::d, DateTime(), required = true) - form.setData(DataForm(mapOf("s" to "123"))) + form.add(DataForm2::d, DateTime(), required = true) + form.setData(DataForm2(s = "123")) val valid = form.validate() assertEquals(false, valid, "Should be invalid with initial data") - form.setData(DataForm(mapOf("s" to "12345"))) + form.setData(DataForm2(s = "12345")) val valid2 = form.validate() assertEquals(false, valid2, "Should be invalid with partially changed data") - form.setData(DataForm(mapOf("s" to "12345", "d" to Date()))) + form.setData(DataForm2(s = "12345", d = KDate())) val valid3 = form.validate() assertEquals(true, valid3, "Should be valid") } 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 index fed0a1f4..d824125b 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt @@ -21,11 +21,11 @@ */ package test.pl.treksoft.kvision.form.time -import pl.treksoft.kvision.panel.Root import pl.treksoft.kvision.form.time.DateTimeInput -import pl.treksoft.kvision.utils.toStringF +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.types.KDate +import pl.treksoft.kvision.types.toStringF import test.pl.treksoft.kvision.DomSpec -import kotlin.js.Date import kotlin.test.Test import kotlin.test.assertEquals @@ -35,7 +35,7 @@ class DateTimeInputSpec : DomSpec { fun render() { run { val root = Root("test", true) - val data = Date() + val data = KDate() val dti = DateTimeInput(value = data).apply { placeholder = "place" id = "idti" 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 index 76dc273b..482a7b7a 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt @@ -23,10 +23,10 @@ package test.pl.treksoft.kvision.form.time import pl.treksoft.kvision.form.time.DateTime import pl.treksoft.kvision.panel.Root -import pl.treksoft.kvision.utils.toStringF +import pl.treksoft.kvision.types.KDate +import pl.treksoft.kvision.types.toStringF import test.pl.treksoft.kvision.DomSpec import kotlin.browser.document -import kotlin.js.Date import kotlin.test.Test class DateTimeSpec : DomSpec { @@ -35,7 +35,7 @@ class DateTimeSpec : DomSpec { fun render() { run { val root = Root("test", true) - val data = Date() + val data = KDate() val ti = DateTime(value = data, label = "Label").apply { placeholder = "place" name = "name" |