package com.cottondb.story import android.app.Application import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.dp import com.cottondb.story.ink.CastCell import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * RULE: at the largest text a cast name under its face breaks only between words. On the emulator at font scale 2, * "Joseph" stood as "Jose" / "ph" and "Meera" as "Meer" / "a" under their 70 dp faces (22 Nov 2026). */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class) class StoryCastNameTest { @get:Rule val compose = createComposeRule() private fun breaks(name: String): List { compose.setContent { val d = LocalDensity.current CompositionLocalProvider(LocalDensity provides Density(d.density, fontScale = 2f)) { CastCell(name, name, {}) { Box(Modifier.size(70.dp)) } } } val results = mutableListOf() compose.onNodeWithTag("story-cast-name", useUnmergedTree = true).fetchSemanticsNode().config[SemanticsActions.GetTextLayoutResult].action?.invoke(results) val layout = results.single() return (0 until layout.lineCount).map { layout.getLineEnd(it, visibleEnd = true) } } @Test fun a_one_word_name_stays_whole() { assertTrue(breaks("Joseph").size == 1) } @Test fun a_two_word_name_breaks_between_its_words() { val ends = breaks("Tea Seller") assertTrue("$ends", ends.all { it == 3 || it == "Tea Seller".length }) } }