Cotton code
45 lines · 1.9 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.setValueimport androidx.compose.ui.test.junit4.createComposeRuleimport 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 chat list is asked again on every change the shell hears of. On the emulator (big invented account, 21 Nov 2026) * a new phone said "No chats yet." under "Loading your data… 1%" for seven seconds. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)class ChatListFollowsTest {    @get:Rule val compose = createComposeRule()    @Test fun the_list_is_asked_again_on_each_change_and_not_before() {        var asked = 0        var revision by mutableIntStateOf(3)        compose.setContent { ListFollowsChanges(revision) { asked++ } }        compose.waitForIdle()        assertEquals("the list the model asked at its start is not asked twice", 0, asked)        compose.runOnIdle { revision++ }        compose.waitForIdle()        assertEquals(1, asked)        compose.runOnIdle { revision++ }        compose.waitForIdle()        assertEquals(2, asked)    }    @Test fun the_root_follows_while_signed_in() {        val app = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "src/messages/kotlin/com/cottondb/messages/warm").isDirectory }        val root = File(app, "src/messages/kotlin/com/cottondb/messages/warm/ChatRoot.kt").readText()        assertTrue(root.contains("if (signedIn) ListFollowsChanges(shell.revision) { model.dataChanged() }"))    }}