Cotton code
45 lines · 2.1 KB · KotlinRaw
package com.cottondb.daysimport android.app.Applicationimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.platform.LocalDensityimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.onRootimport androidx.compose.ui.unit.Densityimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * RULE (DECISIONS "Show"): with a long group chosen at the largest text, search and "more" stay wholly on the screen. * On the emulator at text size 2.0 the group's name pushed the magnifier off the right edge (22 Nov 2026). */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w360dp-h700dp-mdpi", application = Application::class)class DaysTopBarTest {    @get:Rule val compose = createComposeRule()    @Test fun a_long_group_never_pushes_search_or_more_off_the_screen() {        compose.setContent {            val d = LocalDensity.current            CompositionLocalProvider(LocalDensity provides Density(d.density, fontScale = 2f)) {                TopBar(                    "Things for the long-planned trip to the Western Ghats in the monsoon", chosen = true,                    showName = "Show", searchName = "Search", more = "more" to "Settings",                    onShow = {}, onSearch = {}, onMore = {},                )            }        }        val edge = compose.onRoot().getBoundsInRoot().right        val glass = compose.onNodeWithTag("days-search-open").getBoundsInRoot()        val more = compose.onNodeWithTag("days-more-settings").getBoundsInRoot()        assertTrue("search at ${glass.left}..${glass.right} inside $edge", glass.right <= edge && glass.right > glass.left)        assertTrue("more at ${more.left}..${more.right} inside $edge", more.right <= edge && more.left >= glass.right)        assertTrue(compose.onNodeWithTag("days-filter").getBoundsInRoot().right <= glass.left)    }}