karibu-testing icon indicating copy to clipboard operation
karibu-testing copied to clipboard

Allow _click of MenuItem in a MenuBar

Open eiswind opened this issue 5 years ago • 5 comments

Currently MenuItem._click() seems to be tied to a contextMenu. If the parent is a menubar I guess it could fire a simple click event. (?)

Unfortunately MenuBarRootItem has package scope, so we can't search for that easily.

eiswind avatar May 01 '20 16:05 eiswind

Yeah, that sounds pretty reasonable, thanks! It seems that the ContextMenu is there just to verify that the menu item is actually visible and enabled. Unfortunately that's not possible with MenuBar since it's not possible to retrieve the MenuBar instance from MenuItem. Opened a feature request here: https://github.com/vaadin/vaadin-menu-bar-flow/issues/83

As a workaround you can use menuBar._clickItemWithCaption("foo").

mvysny avatar May 01 '20 18:05 mvysny

Alternatively I can implement menuBar._click(MenuItem).

mvysny avatar May 01 '20 19:05 mvysny

That way one would need to lookup both components. I worked around with a helper

_get<MenuItem> { text = "Logfiles" }._menuBarClick()

That helper does not check anything, so probably using clickItemWithCaption would be better.

eiswind avatar May 02 '20 11:05 eiswind

Alternatively I can implement menuBar._click(MenuItem).

That would help in some places!

eiswind avatar May 04 '20 13:05 eiswind

_get<MenuItem> { text = "Logfiles" }._menuBarClick()

Awesome workaround :-D Yet I'm hesitant to include this into Karibu-Testing since it's exactly as you said - no checks are done. Actually _get() performs the visibility checks, but doesn't check the enablement of the menu bar.

menuBar._click(MenuItem)

Thanks! This has been implemented in the commit #53fb104 and will be released with the next release of Karibu-Testing :+1:

Now that the workarounds are in place, let's wait for Vaadin folk to fix https://github.com/vaadin/vaadin-menu-bar-flow/issues/83 so that I can implement the _click() method properly.

mvysny avatar May 04 '20 13:05 mvysny