From 79a1a1573051649b7b2d7b3fcd57d8506eb26bcb Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Sep 2017 16:15:38 +0200 Subject: Testing framework --- src/main/kotlin/pl/treksoft/kvision/Application.kt | 6 - .../kotlin/pl/treksoft/kvision/ApplicationBase.kt | 6 + src/main/kotlin/pl/treksoft/kvision/Main.kt | 35 ++++++ .../kotlin/pl/treksoft/kvision/MainApplication.kt | 11 -- src/main/kotlin/pl/treksoft/kvision/Showcase.kt | 102 +++++++++++++++++ src/main/kotlin/pl/treksoft/kvision/basic/Label.kt | 7 ++ .../kotlin/pl/treksoft/kvision/core/Container.kt | 32 ++++++ src/main/kotlin/pl/treksoft/kvision/core/Img.kt | 10 ++ .../kotlin/pl/treksoft/kvision/core/KVManager.kt | 34 ++++++ .../kotlin/pl/treksoft/kvision/core/KVObject.kt | 3 + src/main/kotlin/pl/treksoft/kvision/core/Root.kt | 27 +++++ src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 121 +++++++++++++++++++++ .../pl/treksoft/kvision/dropdown/DropDown.kt | 55 ++++++++++ src/main/kotlin/pl/treksoft/kvision/html/Button.kt | 99 +++++++++++++++++ src/main/kotlin/pl/treksoft/kvision/html/Image.kt | 66 +++++++++++ src/main/kotlin/pl/treksoft/kvision/html/InTag.kt | 48 ++++++++ src/main/kotlin/pl/treksoft/kvision/html/List.kt | 62 +++++++++++ src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 69 ++++++++++++ src/main/kotlin/pl/treksoft/kvision/main.kt | 40 ------- .../kotlin/pl/treksoft/kvision/routing/Routing.kt | 7 ++ .../kotlin/pl/treksoft/kvision/snabbdom/Types.kt | 57 ++++++++++ 21 files changed, 840 insertions(+), 57 deletions(-) delete mode 100644 src/main/kotlin/pl/treksoft/kvision/Application.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/ApplicationBase.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/Main.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/MainApplication.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/Showcase.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/basic/Label.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Container.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Img.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/core/KVObject.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Root.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/core/Widget.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Button.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Image.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/html/InTag.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/html/List.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/html/Tag.kt delete mode 100644 src/main/kotlin/pl/treksoft/kvision/main.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/routing/Routing.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt (limited to 'src/main/kotlin/pl/treksoft/kvision') diff --git a/src/main/kotlin/pl/treksoft/kvision/Application.kt b/src/main/kotlin/pl/treksoft/kvision/Application.kt deleted file mode 100644 index a7b3d465..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/Application.kt +++ /dev/null @@ -1,6 +0,0 @@ -package pl.treksoft.kvision - -abstract class ApplicationBase { - abstract fun start(state: Map) - abstract fun dispose(): Map -} \ No newline at end of file diff --git a/src/main/kotlin/pl/treksoft/kvision/ApplicationBase.kt b/src/main/kotlin/pl/treksoft/kvision/ApplicationBase.kt new file mode 100644 index 00000000..a7b3d465 --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/ApplicationBase.kt @@ -0,0 +1,6 @@ +package pl.treksoft.kvision + +abstract class ApplicationBase { + abstract fun start(state: Map) + abstract fun dispose(): Map +} \ No newline at end of file diff --git a/src/main/kotlin/pl/treksoft/kvision/Main.kt b/src/main/kotlin/pl/treksoft/kvision/Main.kt new file mode 100644 index 00000000..918cd51f --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/Main.kt @@ -0,0 +1,35 @@ +package pl.treksoft.kvision + +import kotlin.browser.* +import kotlin.dom.* + +fun main(args: Array) { + var application: ApplicationBase? = null + + val state: dynamic = module.hot?.let { hot -> + hot.accept() + + hot.dispose { data -> + data.appState = application?.dispose() + application = null + } + + hot.data + } + + if (document.body != null) { + application = start(state) + } else { + application = null + document.addEventListener("DOMContentLoaded", { application = start(state) }) + } +} + +fun start(state: dynamic): ApplicationBase? { + if (document.getElementById("showcase") == null) return null + val application = Showcase() + @Suppress("UnsafeCastFromDynamic") + application.start(state?.appState ?: emptyMap()) + return application +} + diff --git a/src/main/kotlin/pl/treksoft/kvision/MainApplication.kt b/src/main/kotlin/pl/treksoft/kvision/MainApplication.kt deleted file mode 100644 index 92bcca53..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/MainApplication.kt +++ /dev/null @@ -1,11 +0,0 @@ -package pl.treksoft.kvision - -import kotlin.browser.* - -class MainApplication : ApplicationBase() { - - override fun start(state: Map) { - } - - override fun dispose() = mapOf() -} \ No newline at end of file diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt new file mode 100644 index 00000000..caa66269 --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -0,0 +1,102 @@ +package pl.treksoft.kvision + +import pl.treksoft.kvision.basic.Label +import pl.treksoft.kvision.core.Container +import pl.treksoft.kvision.core.Img +import pl.treksoft.kvision.core.KVManager +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.dropdown.DropDown +import pl.treksoft.kvision.html.* +import pl.treksoft.kvision.html.TAG.H1 +import pl.treksoft.kvision.routing.routing + +class Showcase : ApplicationBase() { + + override fun start(state: Map) { + val root = Root("showcase") + val container = Container(setOf("abc", "def")) + val h1 = Tag(H1, "To jest test pisania tekstu", false, ALIGN.NONE, classes = setOf("test", "test2")) + container.add(h1) + val label = Label("KVLabel1") + container.add(label) + val label2 = Label("KVLabel2") + container.add(label2) + root.add(container) + label.hide() + label.show() + + val dd = DropDown("Dropdown", listOf("DAsdasd asdasdas das", "dasdasd asdasdas das"), "flag") + root.add(dd) + + val p = Tag(TAG.P, "To jest prawo", align = ALIGN.RIGHT) + p.title = "Tytuł" + root.add(p) + val del = InTag(INTAG.DEL, "To jest deleted") + root.add(del) + + val list = ListTag(LIST.DL_HORIZ, listOf("abc", "defdasdasdasddasdtdasdas", "Dasdsada", "dasdasdads"), true) + root.add(list) + + val img = Image(Img("kotlin.png"), "Image", true, IMAGE_SHAPE.ROUNDED) + root.add(img) + + val button = Button("To jest przycisk FA", "fa-flag", BUTTON_STYLE.DANGER) + button.setEventListener