package com.cottondb.story import android.app.Application import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.test.getBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onRoot import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.unit.Density import com.cottondb.story.ink.WritingAfter 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 (DECISIONS "Write after this"): at the largest text the bar says where it writes without breaking a word, and the * way back to the end stays whole on the screen. On the emulator at font scale 2 it stood "remembe" / "r the" (22 Nov 2026). */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w332dp-h700dp-mdpi", application = Application::class) class StoryWritingAfterTest { @get:Rule val compose = createComposeRule() @Test fun where_it_writes_breaks_only_between_words() { val said = "Writing after: Do you remember the cinema before it clo…" compose.setContent { val d = LocalDensity.current CompositionLocalProvider(LocalDensity provides Density(d.density, fontScale = 2f)) { WritingAfter(said, "Write at the end") {} } } val results = mutableListOf() compose.onNodeWithTag("story-writing-after", 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 { said[it - 1] == ' ' }) val end = compose.onNodeWithTag("story-writing-end", useUnmergedTree = true).getBoundsInRoot() val root = compose.onRoot().getBoundsInRoot() assertTrue("the way back off the screen: $end", end.right <= root.right && end.right > end.left) // Not squeezed: the words have most of the row, or the way back stands on its own line beneath them. val words = compose.onNodeWithTag("story-writing-after", useUnmergedTree = true).getBoundsInRoot() assertTrue("squeezed to $words beside $end", end.top >= words.bottom || (words.right - words.left) >= (root.right - root.left) * 0.6f) } }