diff --git a/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenuTest.kt b/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenuTest.kt index 5056936c..c692627f 100644 --- a/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenuTest.kt +++ b/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenuTest.kt @@ -347,18 +347,22 @@ internal fun DynaNodeGroup.contextMenuTestbatch() { test("setOpened(true) fires GridContextMenuOpenedEvent") { var called = false lateinit var cm: GridContextMenu - UI.getCurrent().grid { + val grid = UI.getCurrent().grid { cm = gridContextMenu { item("click me") } + addColumn({ it }).apply { + id_ = "foo!" + } } - cm.addGridContextMenuOpenedListener() { e -> + cm.addGridContextMenuOpenedListener { e -> called = true expect(true) { e.isOpened } expect(false) { e.isFromClient } expect("foo") { e.item.orElse(null) } + expect("foo!") { e.columnId.get() } } - cm.setOpened(true, "foo") + cm.setOpened(true, "foo", grid.columns[0]) expect(true) { called } } @@ -376,6 +380,7 @@ internal fun DynaNodeGroup.contextMenuTestbatch() { expect(false) { e.isOpened } expect(false) { e.isFromClient } expect("foo") { e.item.orElse(null) } + expect(null) { e.columnId.orElse(null) } } cm.setOpened(false, "foo") expect(true) { called } diff --git a/karibu-testing-v10/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenu.kt b/karibu-testing-v10/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenu.kt index 9c4b78af..380be4ea 100644 --- a/karibu-testing-v10/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenu.kt +++ b/karibu-testing-v10/src/main/kotlin/com/github/mvysny/kaributesting/v10/ContextMenu.kt @@ -105,8 +105,7 @@ public fun GridContextMenu._clickItemWithCaption(caption: String, gridIte */ public fun GridContextMenu._clickItemMatching(searchSpec: SearchSpec>, gridItem: T?) { // fires ContextMenuOpenedListener to simulate menu opening - _setContextMenuTargetItemKey(gridItem) - element.setProperty("opened", true) + setOpened(true, gridItem) // notify the context menu dynamic item generator dynamicContentHandler?.also { @@ -124,7 +123,7 @@ public fun GridContextMenu._clickItemMatching(searchSpec: SearchSpec)._click(gridItem) // fires ContextMenuOpenedListener to simulate menu closing - element.setProperty("opened", false) + setOpened(false, gridItem) } private fun Component.getParentMap(): Map, Component> { @@ -206,7 +205,7 @@ private fun MenuItemBase<*, *, *>.checkMenuItemVisible(originalItem: MenuItemBas } } val parent: Component = parentMap[this] - ?: fail("${originalItem.toPrettyString()} is not part of\n${getContextMenu().toPrettyTree()}?!?") + ?: fail("${originalItem.toPrettyString()} is not part of\n${contextMenu.toPrettyTree()}?!?") when (parent) { is MenuItem -> parent.checkMenuItemVisible(originalItem, parentMap) is GridMenuItem<*> -> parent.checkMenuItemVisible(originalItem, parentMap) @@ -269,7 +268,13 @@ public fun ContextMenu.setOpened(opened: Boolean) { /** * Opens or closes the menu. Fires the [ContextMenuBase.OpenedChangeEvent]. */ -public fun GridContextMenu.setOpened(opened: Boolean, gridItem: T?) { +@JvmOverloads +public fun GridContextMenu.setOpened(opened: Boolean, gridItem: T?, column: Grid.Column? = null) { _setContextMenuTargetItemKey(gridItem) + if (column != null) { + val id = requireNotNull(column.id_) { "Column $column must have an ID assigned in order to be identifiable in the event object" } + require(id.isNotBlank()) { "Column $column must have an ID assigned in order to be identifiable in the event object" } + target.element.setProperty("_contextMenuTargetColumnId", id) + } element.setProperty("opened", opened) }