75 lines · 3.1 KB · KotlinRaw
package com.cottondb.notesimport android.app.Applicationimport 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.material3.Textimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.setValueimport androidx.compose.ui.Modifierimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.unit.dpimport java.io.Fileimport 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/** * The loading line, come in above a list that stood at its top, is seen there. In landscape on the emulator (big * invented account, 21 Nov 2026) it came in above the list's top edge and the notes stood without it at 0% and 24%. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w800dp-h360dp-mdpi", application = Application::class)class NotesLineAtTopTest { @get:Rule val compose = createComposeRule() private var loading by mutableStateOf(false) private val rows = (1..40).map { "Invented note $it" } private lateinit var list: LazyListState private fun show() { compose.setContent { list = androidx.compose.foundation.lazy.rememberLazyListState() LineAtTop(list, loading) LazyColumn(Modifier.fillMaxSize(), state = list) { if (loading) item(key = "loading") { Text("Loading your data… 24%", Modifier.fillMaxWidth().height(40.dp)) } items(rows, key = { it }) { Text(it, Modifier.fillMaxWidth().height(80.dp)) } } } compose.waitForIdle() } @Test fun the_line_come_in_above_a_list_at_its_top_is_seen() { show() compose.runOnIdle { loading = true } compose.waitForIdle() compose.runOnIdle { assertEquals(0, list.firstVisibleItemIndex) assertEquals("loading", list.layoutInfo.visibleItemsInfo.first().key) } } @Test fun a_list_scrolled_down_keeps_its_place_when_the_line_comes() { show() compose.runOnIdle { kotlinx.coroutines.runBlocking { list.scrollToItem(10) } } compose.waitForIdle() compose.runOnIdle { loading = true } compose.waitForIdle() compose.runOnIdle { assertEquals("Invented note 11", list.layoutInfo.visibleItemsInfo.first().key) } } @Test fun the_note_list_follows_the_line() { val app = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "src/notes/kotlin/com/cottondb/notes").isDirectory } val surface = File(app, "src/notes/kotlin/com/cottondb/notes/NotesSurface.kt").readText() assertTrue(surface.contains("LineAtTop(listState, com.cottondb.shell.Loading.of(shell.home) != null)")) }}