From 4f9d464f69e1ca1a793710fa47808df55cdea749 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 23 Mar 2018 00:14:40 +0100 Subject: Unit tests for context menu component. --- .../treksoft/kvision/dropdown/ContextMenuSpec.kt | 57 ++++++++++++++++++++++ .../pl/treksoft/kvision/dropdown/DropDownSpec.kt | 4 +- .../pl/treksoft/kvision/dropdown/HeaderSpec.kt | 28 +++++++++++ .../pl/treksoft/kvision/dropdown/SeparatorSpec.kt | 28 +++++++++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/dropdown/HeaderSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/dropdown/SeparatorSpec.kt diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt new file mode 100644 index 00000000..748f7c3c --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/ContextMenuSpec.kt @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.dropdown + +import pl.treksoft.kvision.dropdown.ContextMenu +import pl.treksoft.kvision.html.Link.Companion.link +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.utils.obj +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class ContextMenuSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test", true) + val m = ContextMenu() { + link("a", "b") + link("c", "d") + } + root.setContextMenu(m) + m.show() + val element = document.getElementById("test") + assertEqualsHtml( + "", + element?.innerHTML, + "Should render correct context menu" + ) + } + } + + @Suppress("UnsafeCastFromDynamic") + @Test + fun positionMenu() { + run { + val root = Root("test", true) + val m = ContextMenu() { + link("a", "b") + link("c", "d") + } + root.setContextMenu(m) + m.positionMenu(obj { + pageX = 40 + pageY = 50 + }) + val element = document.getElementById("test") + assertEqualsHtml( + "", + element?.innerHTML, + "Should place context menu in the correct position" + ) + } + } +} \ No newline at end of file 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 8001ba95..a04b25b0 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt @@ -92,7 +92,7 @@ class DropDownSpec : DomSpec { val element = document.getElementById("test") val id = dd.button.id assertEqualsHtml( - "
", + "
", element?.innerHTML, "Should render correct drop down" ) @@ -109,7 +109,7 @@ class DropDownSpec : DomSpec { val element = document.getElementById("test") val id = dd.button.id assertEqualsHtml( - "
", + "
", element?.innerHTML, "Should render correct drop down" ) diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/HeaderSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/HeaderSpec.kt new file mode 100644 index 00000000..a8d7d528 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/HeaderSpec.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.dropdown + +import pl.treksoft.kvision.dropdown.Header +import pl.treksoft.kvision.panel.Root +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class HeaderSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test", true) + val h = Header("Test") + root.add(h) + val element = document.getElementById("test") + assertEqualsHtml( + "
  • Test
  • ", + element?.innerHTML, + "Should render correct drop down header" + ) + } + } +} \ No newline at end of file diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/SeparatorSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/SeparatorSpec.kt new file mode 100644 index 00000000..aafd7237 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/SeparatorSpec.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.dropdown + +import pl.treksoft.kvision.dropdown.Separator +import pl.treksoft.kvision.panel.Root +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class SeparatorSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test", true) + val s = Separator() + root.add(s) + val element = document.getElementById("test") + assertEqualsHtml( + "
  • ", + element?.innerHTML, + "Should render correct drop down separator" + ) + } + } +} \ No newline at end of file -- cgit