Cotton code
45 lines · 2.0 KB · KotlinRaw
package com.cottondb.daysimport android.app.Applicationimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport com.cottondb.days.pen.DaysCardLookimport com.cottondb.days.pen.penFontsimport com.cottondb.shell.LocalCardLookimport com.cottondb.shell.ReportSheetimport 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/** * Share a report's preview in Days' pen: the report is read in Days' small words. On the emulator (21 Nov 2026) it was * drawn in the look's Code style, a code's 34 sp figures, four words a line, the report a long scroll of a few words. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w411dp-h914dp-xhdpi", application = Application::class)class DaysReportPreviewTest {    @get:Rule val compose = createComposeRule()    @Test fun the_report_reads_in_days_small_words() {        val share = CottonCore.json.parseToJsonElement(            """{"preview_title":"This is the whole report","preview_share":"Share","preview_close":"Close"}""",        ).jsonObject        // Eight short invented lines, none wrapping at Days' small words.        val text = (1..8).joinToString("\n") { "Line $it: 0 MB" }        compose.setContent {            CompositionLocalProvider(LocalCardLook provides DaysCardLook(penFonts(LocalContext.current))) {                ReportSheet(share, text, onClose = {}, onShare = {})            }        }        val words = compose.onNodeWithTag("settings-report-text").getBoundsInRoot()        assertTrue("eight lines stand ${words.bottom - words.top} tall", (words.bottom - words.top).value <= 8 * 24f)    }}