Cotton code
56 lines · 2.4 KB · KotlinRaw
package com.cottondb.daysimport android.app.Applicationimport android.view.Viewimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalViewimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.unit.dpimport androidx.core.graphics.Insetsimport androidx.core.view.ViewCompatimport androidx.core.view.WindowInsetsCompatimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Days on its side at the largest text, adding with the keyboard up: the adding bar is taller than the room left * between the status bar and the keyboard, and on the emulator it rose over the clock (21 Nov 2026). The foot now * stops at the status bar. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w800dp-h400dp-land-mdpi", application = Application::class)class DaysFootTopTest {    @get:Rule val compose = createAndroidComposeRule<androidx.activity.ComponentActivity>()    @Test fun the_foot_never_rises_over_the_status_bar() {        lateinit var view: View        compose.setContent {            view = LocalView.current            Footed(Modifier.fillMaxSize(), content = { Box(Modifier.fillMaxSize()) }) {                Box(Modifier.fillMaxWidth().height(300.dp).testTag("adding-bar"))            }        }        compose.runOnIdle {            val insets = WindowInsetsCompat.Builder()                .setInsets(WindowInsetsCompat.Type.statusBars(), Insets.of(0, 30, 0, 0))                .setInsets(WindowInsetsCompat.Type.ime(), Insets.of(0, 0, 0, 160))                .build()            ViewCompat.dispatchApplyWindowInsets(view, insets)        }        compose.waitForIdle()        val foot = compose.onNodeWithTag("days-foot").getBoundsInRoot()        assertTrue("the foot (${foot.top}) stops at the status bar (30 dp)", foot.top >= 30.dp)        assertTrue("and stands on the keyboard (${foot.bottom})", foot.bottom <= 400.dp)    }}