From 79a1a1573051649b7b2d7b3fcd57d8506eb26bcb Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Sep 2017 16:15:38 +0200 Subject: Testing framework --- build.gradle | 44 +++++--- src/main/assets/img/kotlin.png | Bin 0 -> 5966 bytes 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 ++++++++++ src/main/web/index.html | 14 ++- src/test/kotlin/test/TestMainApplication.kt | 8 -- .../kotlin/test/pl/treksoft/kvision/TestUtil.kt | 48 ++++++++ .../test/pl/treksoft/kvision/core/ContainerSpec.kt | 68 ++++++++++++ .../test/pl/treksoft/kvision/core/KVManagerSpec.kt | 58 ++++++++++ .../test/pl/treksoft/kvision/core/RootSpec.kt | 29 +++++ .../test/pl/treksoft/kvision/core/WidgetSpec.kt | 89 +++++++++++++++ webpack.config.d/bootstrap.js | 4 + webpack.config.d/file.js | 6 + 32 files changed, 1182 insertions(+), 83 deletions(-) create mode 100644 src/main/assets/img/kotlin.png 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 delete mode 100644 src/test/kotlin/test/TestMainApplication.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/TestUtil.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/core/ContainerSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/core/KVManagerSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/core/RootSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt create mode 100644 webpack.config.d/bootstrap.js create mode 100644 webpack.config.d/file.js diff --git a/build.gradle b/build.gradle index fc9e4a1f..c9cf1563 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.1.4' + ext.kotlin_version = '1.1.4-3' repositories { jcenter() @@ -21,18 +21,34 @@ apply plugin: 'org.jetbrains.kotlin.frontend' repositories { jcenter() maven { url = 'https://dl.bintray.com/gbaldeck/kotlin' } + maven { url = 'https://dl.bintray.com/rjaros/kotlin' } } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" // for now only compile configuration is supported compile "com.github.snabbdom:snabbdom-kotlin:0.1.0" + compile "pl.treksoft:navigo-kotlin:0.0.1" + } kotlinFrontend { npm { + dependency "jquery" + dependency "bootstrap" + dependency "css-loader" dependency "style-loader" - dependency ("snabbdom", "0.7.0") + dependency "less" + dependency "less-loader" + dependency "imports-loader" + dependency "bootstrap-webpack" + dependency "font-awesome" + dependency("font-awesome-webpack", "0.0.5-beta.2") + dependency "file-loader" + dependency "url-loader" + dependency("snabbdom", "0.6.9") + dependency "snabbdom-virtualize" + dependency "navigo" devDependency("karma") } @@ -43,17 +59,6 @@ kotlinFrontend { define "PRODUCTION", false -// rollupBundle { -// bundleName = "rolledUp" -// } - -// allBundles { -// /* set properties for all bundles */ -// } - -// bundle("someBundler") { -// .... -// } } compileKotlin2Js { @@ -61,7 +66,6 @@ compileKotlin2Js { kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js" kotlinOptions.sourceMap = true kotlinOptions.moduleKind = 'commonjs' - kotlinOptions.main = "call" } compileTestKotlin2Js { @@ -69,6 +73,14 @@ compileTestKotlin2Js { kotlinOptions.outputFile = "$project.buildDir.path/js-tests/${project.name}-tests.js" kotlinOptions.sourceMap = true kotlinOptions.moduleKind = 'commonjs' -// kotlinOptions.moduleName = project.name + "-test" - kotlinOptions.main = "call" +} + +task copyResources(type: Copy) { + from "src/main/assets" + into file(buildDir.path + "/js") +} + +afterEvaluate { + tasks.getByName("webpack-bundle") { dependsOn(copyResources) } + tasks.getByName("webpack-run") { dependsOn(copyResources) } } diff --git a/src/main/assets/img/kotlin.png b/src/main/assets/img/kotlin.png new file mode 100644 index 00000000..4ac96a24 Binary files /dev/null and b/src/main/assets/img/kotlin.png differ 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