diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-02-27 09:22:19 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-02-27 09:22:19 +0100 |
commit | bff6c721074bda50e2d5a23d8aa96bf1f939f62a (patch) | |
tree | b997cbb25ebf9787366a9bc9e69314916728a1b0 | |
parent | 37bfeeefaa5cf5f30bde50dcb0f1bef7e20409b4 (diff) | |
download | kvision-bff6c721074bda50e2d5a23d8aa96bf1f939f62a.tar.gz kvision-bff6c721074bda50e2d5a23d8aa96bf1f939f62a.tar.bz2 kvision-bff6c721074bda50e2d5a23d8aa96bf1f939f62a.zip |
Fix tests
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 14 | ||||
-rw-r--r-- | src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt | 17 |
2 files changed, 23 insertions, 8 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index abff5e37..4dcb62e3 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -358,12 +358,14 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component val handlers = on(eventTarget ?: this) (handlers::apply)(blockAsWidget) for (key: String in js("Object").keys(handlers)) { - val handler = handlers.asDynamic()[key] - val map = listenersMap[key] - if (map != null) { - map[handlerCounter] = handler - } else { - listenersMap[key] = mutableMapOf(handlerCounter to handler) + if (key != "self") { + val handler = handlers.asDynamic()[key] + val map = listenersMap[key] + if (map != null) { + map[handlerCounter] = handler + } else { + listenersMap[key] = mutableMapOf(handlerCounter to handler) + } } } refresh() diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt index 42a07ba8..159df178 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt @@ -96,16 +96,29 @@ class WidgetSpec : WSpec { fun setEventListener() { runW { widget, _ -> widget.setEventListener<Widget> { click = { } } - assertTrue("Element should have an event listener") { widget.listenersMap.size == 1 } + assertTrue("Element should have one event listener") { widget.listenersMap["click"]?.size == 1 } + widget.setEventListener<Widget> { click = { } } + assertTrue("Element should have two event listeners") { widget.listenersMap["click"]?.size == 2 } } } @Test fun removeEventListener() { runW { widget, _ -> + val id = widget.setEventListener<Widget> { click = { } } + widget.setEventListener<Widget> { click = { } } + widget.removeEventListener(id) + assertTrue("One of event listeners is removed") { widget.listenersMap["click"]?.size == 1 } + } + } + + @Test + fun removeEventListeners() { + runW { widget, _ -> + widget.setEventListener<Widget> { click = { } } widget.setEventListener<Widget> { click = { } } widget.removeEventListeners() - assertTrue("Element should not have any event listener") { widget.listenersMap.size == 0 } + assertTrue("Element should not have any event listeners") { widget.listenersMap.isEmpty() } } } |