From dc9dc5df0e012b487dd6fd5918a1e0bd3d06a4ce Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 8 Oct 2017 01:16:23 +0200 Subject: Unit tests --- .../pl/treksoft/kvision/core/WidgetWrapperSpec.kt | 28 +++++++++++++++++++++ .../pl/treksoft/kvision/helpers/CloseIconSpec.kt | 23 +++++++++++++++++ .../pl/treksoft/kvision/panel/DockPanelSpec.kt | 29 ++++++++++++++++++++++ .../pl/treksoft/kvision/panel/FlexPanelSpec.kt | 28 +++++++++++++++++++++ .../pl/treksoft/kvision/panel/GridPanelSpec.kt | 26 +++++++++++++++++++ .../test/pl/treksoft/kvision/panel/HPanelSpec.kt | 27 ++++++++++++++++++++ .../kvision/panel/ResponsiveGridPanelSpec.kt | 26 +++++++++++++++++++ .../test/pl/treksoft/kvision/panel/VPanelSpec.kt | 27 ++++++++++++++++++++ 8 files changed, 214 insertions(+) create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/core/WidgetWrapperSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/helpers/CloseIconSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/panel/DockPanelSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/panel/FlexPanelSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/panel/GridPanelSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/panel/HPanelSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/panel/ResponsiveGridPanelSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/panel/VPanelSpec.kt (limited to 'src/test') 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("
", 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("", 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("
def
jkl
mno
abc
ghi
", 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("
abc
def
ghi
", 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("
abc
def
ghi
", 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("
abc
def
ghi
", 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("
abc
def
ghi
", 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("
abc
def
ghi
", element?.innerHTML, "Should render correct vertical panel") + } + } +} \ No newline at end of file -- cgit