package com.cottondb.story import android.app.Application import androidx.compose.foundation.layout.width import androidx.compose.material3.Text 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.sp import com.cottondb.story.ink.PageAndListen 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 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) class StoryReadFootTest { @get:Rule val 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.current CompositionLocalProvider(LocalDensity provides Density(d.density, fontScale = 2f)) { PageAndListen(line) { Text("▸ Listen from here a voice per character", fontSize = 13.sp) } } } val results = mutableListOf() 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() 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().boundsInRoot val 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) } }