alorma
03/19/2021, 4:39 PMDropdownMenu
, how can I test it? at least test that some child is shown, or whole dropdownalorma
03/19/2021, 4:39 PM@Composable
fun OverflowIcon(showMenu: Boolean, onClick: (Boolean) -> Unit) {
IconButton(onClick = { onClick(!showMenu) }) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = stringResource(
id = R.string.top_bar_menu_icon_content_description
)
)
}
DropdownMenu(
expanded = showMenu,
onDismissRequest = { onClick(!showMenu) }
) {
DropdownMenuItem(onClick = {}) {
Text(
text = stringResource(
id = R.string.top_bar_menu_log_out
)
)
}
}
}
alorma
03/19/2021, 4:41 PM@Test
fun topBarMenuIconClick_showMenu() {
composeTestRule.setThemeContent {
DashboardTopBar(titleRes = R.string.weather_title)
}
val menuIcon = composeTestRule.activity.getString(
R.string.top_bar_menu_icon_content_description
)
val menuLogOut = composeTestRule.activity.getString(
R.string.top_bar_menu_log_out
)
composeTestRule.onNodeWithContentDescription(menuIcon).onParent().performClick()
composeTestRule.onRoot(useUnmergedTree = true).assert(hasText(menuLogOut)).assertExists()
}
but not seems to work