I have a test issue. I have a button near the bott...
# compose
m
I have a test issue. I have a button near the bottom of my screen. It appears on the screen, is clickable etc. However in my test it says the button exists and have a click, however the .assertIsDisplayed fails and it doesn't verify interaction with my mock viewModel. When I moved the button to the top of the screen the test passes without issue. This screen is static so there's no scroll but it seems the test thinks the button is below the fold. Do I need something else in my test? Any help is appreciated it, thanks!
Copy code
@Test
fun priceAlerts_LetsGoButton() {
    setUpPriceAlertsComposable()
    val button =
        composeRule.onNodeWithText(context.getString(
            R.string.improved_onboarding_V1_lets_go_button))
            .assertExists()
    button.assertIsDisplayed()
    button.performClick().assertExists()
    verify(mockViewModel).letsGoClick(any())
}
a
Are you the running the test on the same device as that screenshot?
m
no, this is a unit test and the screenshot is from my Pixel 4XL. I think I need to make the column scrollable for smaller devices. I just tried that and was able to do the performScrollTo and the test worked. The designer and I didn't think how this would look on smaller devices, amateur mistake...
Thank you for your speedy response @Alex Vanyo!!!
a
this is a unit test
With Robolectric perhaps?
I think I need to make the column scrollable for smaller devices.
That was going to be my next response: even if it was passing, I’d be suspicious of it not being scrollable. On smaller devices/landscape/multi-window/large fonts, you’re exactly right: that button might not be visible right away, and therefore the
assertIsDisplayed
is letting you know you have an issue. Thank you for doing your part and considering those cases!
I am not a designer, but you might want to try having that button always be initially visible so the user knows how to advance. If you just made it scrollable and the button isn’t visible at first, it might not be clear what to do (you have to scroll, then click) Probably makes sense to have the image shrink to some minimum size, and then allow scrolling, or something like that?
m
yeah I'll have to speak to my designer about a layout change because having the button too low will be problematic for sure.