Cotton code
51 lines · 2.8 KB · KotlinRaw
package com.cottondb.daysimport android.app.Applicationimport androidx.compose.foundation.layout.Columnimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.platform.LocalContextimport com.cottondb.days.pen.DaysCardLookimport com.cottondb.days.pen.penFontsimport com.cottondb.shell.AboutPartimport com.cottondb.shell.LocalCardLookimport com.cottondb.shell.core.CottonCoreimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * About's rows in Days' pen: a long said (Database, the database's first eight and the server's host) wraps in its share of the row * and the label stays whole. On the emulator (Days, 21 Nov 2026) "Database" stood as "Da / ta / ba / se", the said * taking the whole row. The database and host here are invented. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h800dp-mdpi", application = Application::class)class DaysAboutRowTest {    @get:Rule val compose = createComposeRule()    @Test fun a_long_said_never_squeezes_its_label() {        val settings = CottonCore.json.parseToJsonElement(            """{"about":{"title":"About","version":{"label":"Version","said":"1.0.0 (10468)"},               "facts":[{"id":"database","label":"Database","said":"f00dbabe · cotton-made-up-server-for-a-walk.invented-host-somewhere-far.example.workers.dev"}]}}""",        ).jsonObject        compose.setContent {            CompositionLocalProvider(LocalCardLook provides DaysCardLook(penFonts(LocalContext.current))) { Column { AboutPart(settings) } }        }        val version = compose.onNodeWithTag("settings-about-version-label").getBoundsInRoot()        val database = compose.onNodeWithTag("settings-about-database-label").getBoundsInRoot()        // Whole: one line as tall as Version's, and at least as wide (eight letters to its seven).        assertTrue("Database stands on one line: $database against $version", database.bottom - database.top == version.bottom - version.top)        assertTrue("Database is whole: $database against $version", database.right - database.left >= version.right - version.left)        // And what a row says stands at its right edge, a short one too.        val row = compose.onNodeWithTag("settings-about-version").getBoundsInRoot()        val said = compose.onNodeWithTag("settings-about-version-said").getBoundsInRoot()        assertTrue("Version's said ($said) stands at the row's right ($row)", (row.right - said.right).value <= 1f)    }}