Cotton code
106 lines · 6.8 KB · KotlinRaw
package com.cottondb.mailimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.File/** POST Android, the slices left (coordinator, 26 Nov 2026): what the iPhone and the contract say, wired here. */class PostFinishTest {    private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile }    private fun src(name: String) = File(repo, "apps/android/app/src/mail/kotlin/com/cottondb/mail/$name").readText()    private val words by lazy { Json.parseToJsonElement(File(repo, "crates/cotton-core/kits/shell/lines/post.json").readText()).jsonObject }    /** Remove domain (CONTRACT row 15): asked once in the core's words, then removed with `sure`. */    @Test    fun a_domain_is_removed_after_one_ask() {        val domains = src("Domains.kt")        assertTrue(domains.contains("a.obj(\"remove\")"))        assertTrue(domains.contains("state.ask(\"mail.domain.remove\") { put(\"domain\", JsonPrimitive(domain)) }"))        assertTrue(domains.contains("put(\"sure\", JsonPrimitive(true))"))        // An address is removed by its own named minus, not by a tap on the row that says nothing of it.        // Its name is the act (Remove address, hello@…), not the sheet's question.        assertTrue(domains.contains("MarkButton(\"minus\", \"\${state.w(\"domain.remove_go\")}, \$address\""))        assertTrue(everyMarkParses())    }    /** The words the iPhone reads: Save on the account pages, Photo and Remove {name} in the writer. */    @Test    fun the_new_post_words_are_read() {        listOf("edit" to "save", "write" to "remove_file", "write" to "photo").forEach { (set, key) ->            assertTrue("$set.$key", words[set]!!.jsonObject.containsKey(key))        }        assertTrue(src("YouPages.kt").split("state.w(\"edit.save\")").size == 3)        val write = src("Write.kt")        assertTrue(write.contains("state.w(\"write.remove_file\", mapOf(\"name\" to name))"))        assertTrue(write.contains("Tool(\"image\", word(\"photo\")"))    }    /** Read here is Post's own reader, which keeps nothing; no Custom Tab, nothing handed to another app to view. */    @Test    fun links_are_read_in_posts_own_reader() {        val reading = src("Reading.kt")        assertTrue(reading.contains("state.sheet = Sheet.Reader(url, back)"))        assertTrue(reading.contains("removeAllCookies") && reading.contains("clearCache(true)") && reading.contains("WebStorage.getInstance().deleteAllData()"))        val all = File(repo, "apps/android/app/src/mail/kotlin/com/cottondb/mail").listFiles()!!.joinToString("\n") { it.readText() }        assertFalse(all.contains("CustomTabsIntent"))        assertFalse(all.contains("ACTION_VIEW).setDataAndType"))    }    /** A kind that runs code is offered only to Save; rows that do nothing are no buttons. */    @Test    fun code_files_save_only_and_no_dead_buttons() {        assertTrue(src("PostState.kt").contains("val saveOnly: Boolean = false"))        assertTrue(src("Files.kt").contains("if (sheet.saveOnly) T(state.w(\"thread.attachment_code\")"))        assertFalse(src("Thread.kt").contains("enabled = opens"))        assertFalse(src("YouPages.kt").contains("chevron = false, tag = \"post-account-log-\$i\") {}"))        assertFalse(src("SharedPages.kt").contains("chevron = false, tag = tag) {}"))        assertFalse(src("Write.kt").contains("tag = \"post-write-attachment-\$index\", trailing = {\n                        MarkButton(\"x\", word(\"discard\")"))    }    /** The hand walk of 26 Nov 2026 (POST WALK 2): what a person found doing the whole app by hand. */    @Test    fun the_hand_walk_finds_its_way_back() {        val state = src("PostState.kt")        // A result opened from Search comes back to Search with its words; a file opened there too.        assertTrue(state.contains("if (top is Screen.Thread && top.fromSearch) sheet = Sheet.Search"))        assertTrue(state.contains("val then = (sheet as? Sheet.File)?.then"))        val files = src("Files.kt")        assertTrue(files.contains("state.openThread(it, fromSearch = true)"))        assertTrue(files.contains("then = Sheet.Search"))        assertTrue(src("Thread.kt").contains("if (fromSearch) state.w(\"home.search.zero\")"))        // Back finds each list where he left it, drawn at once from its last answer.        listOf("Home.kt", "You.kt", "Senders.kt", "Files.kt", "Place.kt").forEach { f ->            assertTrue(f, (src(f).contains("state = state.list(") || src(f).contains("state = state.root(")) && src(f).contains("state.kept["))        }        // A tap on the tab standing at its first screen lifts its list to the top.        assertTrue(state.contains("else -> roots[to]?.let { key -> go { list(key).scrollToItem(0) } }"))        // A pushed list opens at its top; only Back restores a place.        assertTrue(state.contains("is Screen.Sender -> fresh(\"sender/\${screen.key}\")"))    }    @Test    fun the_hand_walk_leaves_no_dead_or_cut_controls() {        // An open earlier mail folds again by its head, which TalkBack calls expanded.        val thread = src("Thread.kt")        assertTrue(thread.contains("opened.remove(email)") && thread.contains(".foldState(true) { fold() }"))        // One address to write from: no button that does nothing; its why is heard.        val write = src("Write.kt")        assertTrue(write.contains("if (choices.size <= 1) Modifier.semantics(mergeDescendants = true) {} else Modifier.control(heard)"))        // Addresses wrap at the largest text instead of running off the edge; a new file scrolls into view.        assertFalse(write.contains("singleLine = keyboard == KeyboardType.Email"))        assertTrue(write.contains("pageScope.launch { delay(400); scroll.animateScrollTo(scroll.maxValue) }"))        // The sender's own address on its page is said, not offered as a tap that leads nowhere.        assertTrue(src("Senders.kt").contains("else InfoRow(a.str(\"address\")"))        // Chips reach the screen's edges and never cut a word; DNS records can be copied.        val parts = src("Parts.kt")        assertTrue(parts.contains(".horizontalScroll(scroll).padding(horizontal = SIDE)") && parts.contains("scroll: androidx.compose.foundation.ScrollState = rememberScrollState()") && parts.contains("lines = 2)"))        assertTrue(src("Domains.kt").contains("SelectionContainer {"))        // A page risen over the app takes every touch on its paper: nothing reaches the thread beneath it.        assertTrue(src("PostApp.kt").contains(".background(sage.c.ground).pointerInput(Unit) { awaitPointerEventScope { while (true) awaitPointerEvent() } }"))        // A save-only kind draws no empty frame.        assertTrue(src("Files.kt").contains("if (!sheet.saveOnly) Box("))    }}