Cotton code
98 lines · 4.8 KB · KotlinRaw
package com.cottondb.sitesimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.File/** What the emulator walk of 26 Nov 2026 found (light, night, the largest text, TalkBack), each held here. */class SitesWalkTest {    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/sites/kotlin/com/cottondb/sites/$name").readText()    /** "Open this page in…" never offers the site the page already stands in, nor after the hidden sites unlock. */    @Test    fun open_this_page_in_never_offers_the_site_it_is_in() {        val state = src("SitesState.kt")        assertTrue(state.contains("val here: String? = null) : Sheet"))        assertTrue(state.contains("here = if (moving) page?.id else null"))        val sheets = src("Sheets.kt")        assertTrue(sheets.split(".filter { it.id != s.here }").size == 4)        assertTrue(sheets.contains("state.choose(s.url, s.from, moving = s.here != null)"))    }    /** A page that didn't answer is not kept as where he left it (it would also clear "Sign in once"). */    @Test    fun a_failed_page_is_not_where_he_left_it() {        assertTrue(src("SitesState.kt").contains("if (page.url == url && page.failed == null) ask(\"sites.left\")"))    }    /** The sheet's veil darkens by night too (night's ink is light), and TalkBack can name it. */    @Test    fun the_veil_darkens_by_night_and_is_named() {        val bits = src("Bits.kt")        assertTrue(bits.contains("if (c.dark) Color.Black.copy(alpha = 0.55f) else c.ink.copy(alpha = 0.30f)"))        assertFalse(bits.contains("c.ink.copy(alpha = if (c.dark) 0.45f else 0.30f)"))        assertTrue(bits.contains(".semantics { contentDescription = closeName }"))    }    /** An empty ring and a switch that is off are drawn in faint, seen by night; never in the rule's near-ground. */    @Test    fun an_empty_ring_and_an_off_switch_are_seen_by_night() {        val bits = src("Bits.kt")        assertTrue(bits.contains("if (on) c.ink else c.faint, CircleShape"))        assertTrue(bits.contains("if (on) c.ink else c.faint, RoundedCornerShape(13.dp)"))    }    /** At the largest text: the search line's words take two lines, a value stands under its name, the size never wraps. */    @Test    fun the_largest_text_never_clips() {        val bits = src("Bits.kt")        assertTrue(bits.contains("T(placeholder, 16.sp, c.faint, lines = 2)"))        assertTrue(bits.contains("LocalDensity.current.fontScale >= 1.5f"))        val sheets = src("Sheets.kt")        assertTrue(sheets.contains("\"\${page.zoom}%\", 22.sp, weight = FontWeight.Bold, lines = 1"))        assertFalse(sheets.contains("modifier = Modifier.width(64.dp)"))        assertTrue(sheets.contains("Modifier.weight(1f).fillMaxHeight(), glyph = \"quick\""))        assertTrue(sheets.contains("Modifier.weight(1f).fillMaxHeight(), tag = \"sites-size-smaller\""))    }    /** A shared row under You opens the shell's page only while there is one (signed out there is no Privacy page). */    @Test    fun a_shared_row_never_opens_a_page_that_is_not_there() {        val you = src("You.kt")        assertTrue(you.contains("val opens = id == \"storage\" || id == \"backup\" || pages == null || id in pages"))        assertTrue(you.contains("chevron = opens"))    }    /** The Look page frames its preview once; Sites' preview adds no second frame. */    @Test    fun the_look_preview_has_one_frame() {        val you = src("You.kt")        assertFalse(you.contains("background(c.ground, shape).border(1.dp, c.rule, shape)"))    }    /** After Sign out, a site's settings measure again what it keeps on this phone. */    @Test    fun sign_out_measures_again() {        val edit = src("Edit.kt")        assertTrue(edit.contains("state.signOut(row) { measured++ }"))        assertTrue(edit.contains("LaunchedEffect(id, measured)"))    }    /** Going from the search line, the keyboard goes first, so the chooser stands whole and Back closes it. */    @Test    fun the_keyboard_goes_before_the_chooser_rises() {        assertTrue(src("ListScreen.kt").contains("keyboard?.hide(); focusManager.clearFocus()"))    }    /** At the largest text a row is twice as tall: a drag steps by the row it passes, and names and addresses wrap. */    @Test    fun arrange_steps_by_the_rows_own_height() {        val edit = src("Edit.kt")        assertTrue(edit.contains(".onSizeChanged { heights[r.id] = it.height.toFloat() }"))        assertTrue(edit.contains("if (dy > below * 0.6f && at < rows.lastIndex)") && edit.contains("if (dy < -above * 0.6f && at > 0)"))        assertFalse(edit.contains("dy -= rowPx }"))        assertTrue(src("Bits.kt").contains("lines = if (big) 4 else 2"))    }}