package com.cottondb.messages.warm import android.app.Application import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.test.junit4.createComposeRule 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 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() }")) } }