aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-08 01:16:23 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-08 01:16:23 +0200
commitdc9dc5df0e012b487dd6fd5918a1e0bd3d06a4ce (patch)
tree509b6297d4e5733404fd036c1b01c4acda1505a0 /src
parentce691e9b1409324af359afc721b8561c298d7b71 (diff)
downloadkvision-dc9dc5df0e012b487dd6fd5918a1e0bd3d06a4ce.tar.gz
kvision-dc9dc5df0e012b487dd6fd5918a1e0bd3d06a4ce.tar.bz2
kvision-dc9dc5df0e012b487dd6fd5918a1e0bd3d06a4ce.zip
Unit tests
Diffstat (limited to 'src')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/core/WidgetWrapperSpec.kt28
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/helpers/CloseIconSpec.kt23
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/DockPanelSpec.kt29
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/FlexPanelSpec.kt28
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/GridPanelSpec.kt26
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/HPanelSpec.kt27
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/ResponsiveGridPanelSpec.kt26
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/panel/VPanelSpec.kt27
8 files changed, 214 insertions, 0 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetWrapperSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetWrapperSpec.kt
new file mode 100644
index 00000000..a053627d
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetWrapperSpec.kt
@@ -0,0 +1,28 @@
+package test.pl.treksoft.kvision.core
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.core.UNIT
+import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.WidgetWrapper
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class WidgetWrapperSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val widget = Widget()
+ val wrapper = WidgetWrapper(widget)
+ wrapper.width = 100 to UNIT.em
+ root.add(wrapper)
+ val element = document.getElementById("test")
+ assertEquals("<div style=\"width: 100em;\"><div></div></div>", element?.innerHTML, "Should render widget inside custom wrapper")
+ widget.hide()
+ assertEquals("", element?.innerHTML, "Should not render wrapper when widget is hidden")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/helpers/CloseIconSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/helpers/CloseIconSpec.kt
new file mode 100644
index 00000000..a36beafa
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/helpers/CloseIconSpec.kt
@@ -0,0 +1,23 @@
+package test.pl.treksoft.kvision.helpers
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.helpers.CloseIcon
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class CloseIconSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val ci = CloseIcon()
+ root.add(ci)
+ val element = document.getElementById("test")
+ assertEquals("<button class=\"close\" type=\"button\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>", element?.innerHTML, "Should render correct close icon")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/DockPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/DockPanelSpec.kt
new file mode 100644
index 00000000..73754d60
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/DockPanelSpec.kt
@@ -0,0 +1,29 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.DockPanel
+import pl.treksoft.kvision.panel.SIDE
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DockPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val dockPanel = DockPanel()
+ root.add(dockPanel)
+ dockPanel.add(Label("abc"), SIDE.UP)
+ dockPanel.add(Label("def"), SIDE.RIGHT)
+ dockPanel.add(Label("ghi"), SIDE.DOWN)
+ dockPanel.add(Label("jkl"), SIDE.LEFT)
+ dockPanel.add(Label("mno"), SIDE.CENTER)
+ val element = document.getElementById("test")
+ assertEquals("<div><div style=\"display: flex; flex-direction: column; justify-content: space-between; align-items: stretch;\"><div style=\"order: 2;\"><div style=\"display: flex; justify-content: space-between; align-items: center;\"><div style=\"order: 3;\"><span>def</span></div><div style=\"order: 1;\"><span>jkl</span></div><div style=\"order: 2;\"><span>mno</span></div></div></div><div style=\"order: 1; align-self: center;\"><span>abc</span></div><div style=\"order: 3; align-self: center;\"><span>ghi</span></div></div></div>", element?.innerHTML, "Should render correct dock panel")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/FlexPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/FlexPanelSpec.kt
new file mode 100644
index 00000000..3f5885fa
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/FlexPanelSpec.kt
@@ -0,0 +1,28 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.FLEXDIR
+import pl.treksoft.kvision.panel.FLEXJUSTIFY
+import pl.treksoft.kvision.panel.FlexPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class FlexPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val flexPanel = FlexPanel(FLEXDIR.ROWREV, justify = FLEXJUSTIFY.SPACEEVENLY)
+ root.add(flexPanel)
+ flexPanel.add(Label("abc"), 1)
+ flexPanel.add(Label("def"), 2)
+ flexPanel.add(Label("ghi"), 3)
+ val element = document.getElementById("test")
+ assertEquals("<div style=\"display: flex; flex-direction: row-reverse; justify-content: space-evenly;\"><div style=\"order: 1;\"><span>abc</span></div><div style=\"order: 2;\"><span>def</span></div><div style=\"order: 3;\"><span>ghi</span></div></div>", element?.innerHTML, "Should render correct flex panel")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/GridPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/GridPanelSpec.kt
new file mode 100644
index 00000000..547baafe
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/GridPanelSpec.kt
@@ -0,0 +1,26 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.GridPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class GridPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val gridPanel = GridPanel()
+ root.add(gridPanel)
+ gridPanel.add(Label("abc"), 1, 1)
+ gridPanel.add(Label("def"), 2, 2)
+ gridPanel.add(Label("ghi"), 3, 3)
+ val element = document.getElementById("test")
+ assertEquals("<div style=\"display: grid;\"><div style=\"grid-column-start: 1; grid-row-start: 1;\"><span>abc</span></div><div style=\"grid-column-start: 2; grid-row-start: 2;\"><span>def</span></div><div style=\"grid-column-start: 3; grid-row-start: 3;\"><span>ghi</span></div></div>", element?.innerHTML, "Should render correct grid panel")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/HPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/HPanelSpec.kt
new file mode 100644
index 00000000..48449fc2
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/HPanelSpec.kt
@@ -0,0 +1,27 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.FLEXJUSTIFY
+import pl.treksoft.kvision.panel.HPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class HPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val hPanel = HPanel(justify = FLEXJUSTIFY.SPACEBETWEEN)
+ root.add(hPanel)
+ hPanel.add(Label("abc"), 1)
+ hPanel.add(Label("def"), 2)
+ hPanel.add(Label("ghi"), 3)
+ val element = document.getElementById("test")
+ assertEquals("<div style=\"display: flex; justify-content: space-between;\"><div style=\"order: 1;\"><span>abc</span></div><div style=\"order: 2;\"><span>def</span></div><div style=\"order: 3;\"><span>ghi</span></div></div>", element?.innerHTML, "Should render correct horizontal panel")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/ResponsiveGridPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/ResponsiveGridPanelSpec.kt
new file mode 100644
index 00000000..5fb9376d
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/ResponsiveGridPanelSpec.kt
@@ -0,0 +1,26 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.ResponsiveGridPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class ResponsiveGridPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val rgPanel = ResponsiveGridPanel()
+ root.add(rgPanel)
+ rgPanel.add(Label("abc"), 1, 1)
+ rgPanel.add(Label("def"), 2, 2)
+ rgPanel.add(Label("ghi"), 3, 3)
+ val element = document.getElementById("test")
+ assertEquals("<div><div class=\"row\"></div><div class=\"row\"><div class=\"col-md-3\"></div><div class=\"col-md-3\"><span>abc</span></div><div class=\"col-md-3\"></div><div class=\"col-md-3\"></div></div><div class=\"row\"><div class=\"col-md-3\"></div><div class=\"col-md-3\"></div><div class=\"col-md-3\"><span>def</span></div><div class=\"col-md-3\"></div></div><div class=\"row\"><div class=\"col-md-3\"></div><div class=\"col-md-3\"></div><div class=\"col-md-3\"></div><div class=\"col-md-3\"><span>ghi</span></div></div></div>", element?.innerHTML, "Should render correct responsive grid panel")
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/panel/VPanelSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/panel/VPanelSpec.kt
new file mode 100644
index 00000000..a65b3ca9
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/panel/VPanelSpec.kt
@@ -0,0 +1,27 @@
+package test.pl.treksoft.kvision.panel
+
+import pl.treksoft.kvision.basic.Label
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.panel.FLEXJUSTIFY
+import pl.treksoft.kvision.panel.VPanel
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class VPanelSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val vPanel = VPanel(justify = FLEXJUSTIFY.SPACEBETWEEN)
+ root.add(vPanel)
+ vPanel.add(Label("abc"), 1)
+ vPanel.add(Label("def"), 2)
+ vPanel.add(Label("ghi"), 3)
+ val element = document.getElementById("test")
+ assertEquals("<div style=\"display: flex; flex-direction: column; justify-content: space-between;\"><div style=\"order: 1;\"><span>abc</span></div><div style=\"order: 2;\"><span>def</span></div><div style=\"order: 3;\"><span>ghi</span></div></div>", element?.innerHTML, "Should render correct vertical panel")
+ }
+ }
+} \ No newline at end of file