Is it possible to UI test Window's Menu ? ```onNod...
# compose-desktop
o
Is it possible to UI test Window's Menu ?
Copy code
onNodeWithText("Tools").assertIsDisplayed()
This fails ("Tools" being one of the MenuBar's root Menu). I'm running on macOS if that matters (given how the macOS menu are managed vs app Window, it could) (See code in thread 🧵)
Copy code
@Test
fun `when clicking on show network logs then should trigger callback`() = runComposeUiTest {
    var isNetworkLogClicked = false
    setContent {
        Window(
            onCloseRequest = {},
            title = "Test",
        ) {
            AppMenuBar(
                onNetworkLogClick = { isNetworkLogClicked = true }
            )
        }
    }

    onNodeWithText("Tools")
        .assertIsDisplayed()
        .performClick()

    onNodeWithText("Show network logs")
        .assertIsDisplayed()
        .performClick()
}
Copy code
@Composable
fun FrameWindowScope.AppMenuBar(
    onNetworkLogClick: () -> Unit,
) {
    MenuBar {
        Menu("Tools", mnemonic = 'T') {
            Item(
                text = "Show network logs",
                shortcut = when (currentOS) {
                    OS.Mac -> KeyShortcut(key = Key.L, meta = true, shift = true)
                    OS.Linux,
                    OS.Windows -> KeyShortcut(key = Key.L, ctrl = true, shift = true)
                },
                onClick = onNetworkLogClick
            )
        }
    }
}
a
Currently no. UI test doesn’t create a real window, and even if it did, on macOS the toolbar isn’t part of the node tree.
😞 1
o
That's what I thought. I hoped for a way to invoke the composable in dedicated context just to stress it's behavior (callbacks)