package com.cottondb.notes import android.app.Application import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items import androidx.compose.material3.Text import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.unit.dp import java.io.File import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import 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)")) } }