Cotton code
83 lines · 4.0 KB · KotlinRaw
package com.cottondb.daysimport android.app.Applicationimport androidx.compose.foundation.gestures.scrollByimport androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.PaddingValuesimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.foundation.lazy.itemsimport androidx.compose.foundation.lazy.rememberLazyListStateimport androidx.compose.material3.Textimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.clickimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.performTouchInputimport androidx.compose.ui.unit.dpimport kotlinx.coroutines.runBlockingimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Sometime's sixty invented to-dos under a foot taller than the fixed 96 dp the lists used to leave (the foot at the * largest text, or the adding bar with the keyboard): scrolled to its end, the last row stands wholly above the foot. * On the emulator it stood under the foot and could not be scrolled out (21 Nov 2026). And a tap on the foot stays on * the foot, never reaching a row scrolled under it. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class)class DaysFootTest {    @get:Rule val compose = createComposeRule()    private fun check(footHeight: Int) {        lateinit var list: LazyListState        compose.setContent {            Box(Modifier.fillMaxSize()) {                Footed(Modifier.fillMaxSize(), content = { room ->                    list = rememberLazyListState()                    LazyColumn(Modifier.fillMaxSize(), state = list, contentPadding = PaddingValues(bottom = room)) {                        items((1..60).toList()) { Text("Invented task $it", Modifier.fillMaxWidth().height(48.dp).testTag("row-$it")) }                    }                }) { Box(Modifier.fillMaxWidth().height(footHeight.dp).testTag("foot-body")) }            }        }        compose.waitForIdle()        compose.runOnIdle { runBlocking { list.scrollToItem(59) } }        compose.runOnIdle { runBlocking { list.scrollBy(100_000f) } }        compose.waitForIdle()        val last = compose.onNodeWithTag("row-60").getBoundsInRoot()        val foot = compose.onNodeWithTag("days-foot").getBoundsInRoot()        assertTrue("the last row ($last) stands above the foot ($foot)", last.bottom <= foot.top)    }    @Test fun the_last_row_clears_a_tall_foot() = check(footHeight = 180)    @Test fun the_last_row_clears_the_adding_bar_and_keyboard() = check(footHeight = 420)    /** On the emulator a tap beside the switch ticked "Invented chore 31", scrolled under the foot (21 Nov 2026). */    @Test fun a_tap_on_the_foot_reaches_no_row_under_it() {        var tapped = 0        compose.setContent {            Footed(Modifier.fillMaxSize(), content = { room ->                LazyColumn(Modifier.fillMaxSize(), contentPadding = PaddingValues(bottom = room)) {                    items((1..60).toList()) { Text("Invented chore $it", Modifier.fillMaxWidth().height(48.dp).clickable { tapped++ }) }                }            }) { Box(Modifier.fillMaxWidth().height(90.dp).testTag("foot-body")) }        }        compose.onNodeWithTag("days-foot").performTouchInput { click(androidx.compose.ui.geometry.Offset(20f, centerY)) }        compose.waitForIdle()        assertEquals("no row under the foot was tapped", 0, tapped)    }}