How can I test the visibility of an (alert) dialog...
# compose-desktop
d
How can I test the visibility of an (alert) dialog and its content with a Unit test? I'm using the new Dialog/Window API and wrote successfully some Unit tests with the test rule. When the dialog is displayed it doesn't work. The matchers (e.g.
onNodeWithText
) can't find the text and I assume it's because it's in a different window and the rule can't access it? Did look into the
DesktopComposeTestRule
and saw that it creates a window for the test and so on, but can't figure out a way to test the visibility of the dialog texts.
i
Do you use
UndecoratedWindowAlertDialogProvider
? If yes, then this is definitely not supported at the moment, as we create a real native window, which is not visible to
DesktopComposeTestRule
If not, then I am not sure, as we create a layer of the window, which is visible to
DesktopComposeTestRule
Actually, we haven't implemented
DesktopComposeTestRule
very well at the moment, and most certainly it doesn't work well with any popups/dialogs. We plan to fix multiple issues before 1.0.0. But not sure if we will properly support dialog's/popup's in tests. There are some ideas, but they are only ideas, there is no a solid plan yet. If you want to track the issue, you can create it here. Current workarounds: • test content of
AlertDialog
separately • mock
AlertDialog
in tests by something else (
Box
for example)
d
Yes, I used
UndecoratedWindowAlertDialogProvider
for the AlertDialog. The workarounds sound good and I give it a try. Based on that I might use set the dialog provider with a param in the composable and use PopupAlertDialogProvider for testing. For the Dialog (Window Dialog) extracting the dialog content seems to be the best way to test it. Will play around with it a little and might create an issue.
Obviously, there are more important topics on the roadmap than testing dialogs 😉