Thursday, 15 September 2022

Instrumental testing - how to check the view is not existing (JetpackCompose)?

I am using Jetpack compose and there is such an implementation

...
imgRes?.let {
            Spacer(modifier = Modifier.width(4.dp))

            Image(
                painter = it,
                contentDescription = when (metadata.hasSubscription) {
                    true -> stringResource(id = R.string.subscribed)
                    false -> stringResource(id = R.string.not_subscribed)
                    else -> null
                },
                modifier = Modifier
                    .height(17.dp)
                    .width(17.dp)
            )
        }
...

So, when imgRes is not null, I put the view on the screen with dedicated contentDescription according to the hasSubscription state, correspondently in testing, I am checking if the view with specific contentDescription existing on the screen, however, I also need to check the state when imgRes is null and the image is not existing on the screen. But in the case when the view is presented I know how to find it by contentDescription, but how to check if the view is presented if it hasn't any id? How to find this view on the screen?



from Instrumental testing - how to check the view is not existing (JetpackCompose)?

No comments:

Post a Comment