Cotton code
45 lines · 2.0 KB · KotlinRaw
package com.cottondb.mailimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.File/** * ANDROID READY 2 C: Post's gaps against the iPhone. A pull reads Mail, a place, Files, Senders and a domain again (the * iPhone's `.refreshable`); offline, the home says what still works, in the core's words (`post` `fail.offline`). */class PostPullTest {    private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile }    private fun mail(name: String) = File(repo, "apps/android/app/src/mail/kotlin/com/cottondb/mail/$name").readText()    @Test    fun online_while_any_network_stands() {        val said = mutableListOf<Boolean>()        val nets = Networks { said += it }        nets.up("wifi")        nets.up("cell")        nets.lost("wifi")        nets.lost("cell")        nets.up("wifi")        assertEquals(listOf(true, true, true, false, true), said)    }    @Test    fun every_list_the_iphone_refreshes_pulls() {        for (name in listOf("Home.kt", "Place.kt", "Files.kt", "Senders.kt")) {            assertTrue("$name pulls", mail(name).contains("Pull({ state.reread() }, Modifier.weight(1f).fillMaxWidth()) {"))        }        val domain = mail("Domains.kt")        assertTrue(domain.contains("YouPage(state, \"post-domain\", back = state.w(\"domain.title\"), refresh = check)"))        assertTrue(domain.substringAfter("val check: suspend () -> Unit").contains("state.ask(\"mail.domain.check\")"))    }    @Test    fun the_home_says_offline_in_the_cores_words() {        val home = mail("Home.kt")        assertTrue(home.contains("if (!online) item(key = \"offline\") { Offline(state.w(\"fail.offline\")) }"))        val lines = File(repo, "crates/cotton-core/kits/shell/lines/post.json").readText()        assertTrue(lines.contains("\"offline\": \"Offline. Read, write and archive as usual. It all goes through when you're back.\""))    }}