Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisplaySizeRule does not consistently set back the previous emulator state #2334

Open
adavis opened this issue Jan 26, 2025 · 1 comment
Open
Assignees

Comments

@adavis
Copy link

adavis commented Jan 26, 2025

Actual

The emulator remains with the display size modified. Wiping the device is required to restore the original state.
Image

Full test code (if helpful)

@OptIn(ExperimentalTestApi::class)
@RunWith(AndroidJUnit4::class)
class AppNavigationTests {

    @get:Rule(order = 0)
    val koinRule = KoinTestRule(
        modules = listOf(
            module {
                singleOf(::FakeConferenceRepository) bind ConferenceRepository::class
                viewModelOf(::MainViewModel)
            }
        )
    )

    @get:Rule(order = 1)
    val composeRule = createAndroidComposeRule<ComponentActivity>()

    @get:Rule(order = 2)
    var displaySizeRule: DisplaySizeRule = DisplaySizeRule()

    @Test
    fun should_display_bottom_bar_when_compact() {
        onDevice().setDisplaySize(
            widthSizeClass = WidthSizeClass.COMPACT,
            heightSizeClass = HeightSizeClass.MEDIUM
        )

        composeRule.setContent {
            Red30TechApp()
        }

        composeRule
            .onNodeWithTag("ui:bottomBar").assertIsDisplayed()
    }

    @Test
    fun should_display_rail_when_medium() {
        onDevice().setDisplaySize(
            widthSizeClass = WidthSizeClass.MEDIUM,
            heightSizeClass = HeightSizeClass.MEDIUM
        )

        composeRule.setContent {
            Red30TechApp()
        }

        composeRule
            .onNodeWithTag("ui:navigationRail").assertIsDisplayed()
    }
}

Expected

The emulator is restored to its original state.

@kmcauliffe6
Copy link
Collaborator

Hi Annyce, thank you for filing this issue!

Are the test cases in the sample you shared failing? I'm able to reproduce this issue of the emulator not being set back to it's original state when a test case fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants