Cotton code
50 lines · 2.3 KB · KotlinRaw
package com.cottondb.storyimport android.app.Applicationimport androidx.compose.ui.semantics.SemanticsPropertiesimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.text.font.FontWeightimport com.cottondb.story.ink.SceneTitleimport com.cottondb.story.ink.timeInimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertNullimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Time of day is not shown prominently on the scene list (DECISIONS, gate 3): the place stands in the row's weight, * the time in the plain one. The walk found "Lighthouse lamp room · night" all bold (first-run walk, 25 Nov 2026). */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w411dp-h891dp-mdpi", application = Application::class)class StorySceneTitleTest {    @get:Rule val compose = createComposeRule()    private val joined = "{place} · {time}"    @Test fun the_time_is_found_by_the_cores_own_join() {        val title = "Lighthouse lamp room · night"        assertEquals(" · night", title.substring(timeIn(title, joined)!!))        // A place holding the join itself: the time is the last part.        val dotted = "Kiosk · back room · dawn"        assertEquals(" · dawn", dotted.substring(timeIn(dotted, joined)!!))        // A language that says the time first.        val first = "nuit — phare"        assertEquals("nuit — ", first.substring(timeIn(first, "{time} — {place}")!!))        // A place alone, a time alone: no time part.        assertNull(timeIn("Lighthouse lamp room", joined))    }    @Test fun the_place_is_semibold_and_the_time_plain() {        val title = "Lighthouse lamp room · night"        compose.setContent { SceneTitle(title, joined) }        val text = compose.onNodeWithTag("story-scene-row-title", useUnmergedTree = true).fetchSemanticsNode().config[SemanticsProperties.Text].single()        fun weightAt(i: Int) = text.spanStyles.filter { i in it.start until it.end && it.item.fontWeight != null }.last().item.fontWeight        assertEquals(FontWeight.SemiBold, weightAt(title.indexOf("lamp")))        assertEquals(FontWeight.Normal, weightAt(title.indexOf("night")))    }}