package com.cottondb.storyimport android.app.Applicationimport androidx.compose.foundation.layout.widthimport androidx.compose.material3.Textimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalDensityimport androidx.compose.ui.semantics.SemanticsActionsimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.text.TextLayoutResultimport androidx.compose.ui.unit.Densityimport androidx.compose.ui.unit.spimport com.cottondb.story.ink.PageAndListenimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * RULE: at the largest text Read's page line breaks only between words. On the emulator at font scale 2 it stood as * "Pag" / "e 1" / "of" / "2 ·" beside a whole "Listen from here" (22 Nov 2026). */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w360dp-h700dp-mdpi", application = Application::class)classStoryReadFootTest { @get:Ruleval compose = createComposeRule() @Test fun the_page_line_breaks_only_between_words() {val line = "Page 1 of 2 · about 2 minutes" compose.setContent {val d = LocalDensity.currentCompositionLocalProvider(LocalDensity provides Density(d.density, fontScale = 2f)) {PageAndListen(line) { Text("▸ Listen from here a voice per character", fontSize = 13.sp) } } }val results = mutableListOf<TextLayoutResult>() compose.onNodeWithTag("story-read-page", useUnmergedTree = true).fetchSemanticsNode().config[SemanticsActions.GetTextLayoutResult].action?.invoke(results)val layout = results.single()val ends = (0 until layout.lineCount - 1).map { layout.getLineEnd(it) } assertTrue("broke inside a word at $ends", ends.all { it == line.length || line[it - 1] == ' ' }) }/** * At the default size "Page 1 of 1 · about a minute" stands whole on its line, and "a voice per character" starts * under "Listen from here", not under its mark. Both wrapped and stood off-line (first-run walk, 25 Nov 2026). */ @Test fun the_page_line_stands_whole_and_the_voice_line_under_listens_words() {val line = "Page 1 of 1 · about a minute" compose.setContent {PageAndListen(line) { com.cottondb.story.ink.ListenFromHere("Listen from here", "a voice per character", listening = false) } }val results = mutableListOf<TextLayoutResult>() compose.onNodeWithTag("story-read-page", useUnmergedTree = true).fetchSemanticsNode().config[SemanticsActions.GetTextLayoutResult].action?.invoke(results) assertTrue("the page line wrapped", results.single().lineCount == 1)val words = compose.onNodeWithTag("story-listen-words", useUnmergedTree = true).fetchSemanticsNode().boundsInRootval voice = compose.onNodeWithTag("story-listen-voice", useUnmergedTree = true).fetchSemanticsNode().boundsInRoot org.junit.Assert.assertEquals("the voice line stands off Listen's words", words.left, voice.left, 0.5f) assertTrue("the voice line is not under Listen's words", voice.top >= words.bottom - 0.5f) }}