package com.cottondb.story import android.app.Application import androidx.activity.ComponentActivity import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Text import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.getBoundsInRoot import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.unit.dp import com.cottondb.story.ink.Ink import com.cottondb.story.ink.InkSheet import com.cottondb.story.ink.Over import com.cottondb.story.ink.storyColumn import org.junit.Assert.assertEquals 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: on a tablet Story's column stands in the middle at most [Ink.widest] wide, as StorySurface draws the home and the * page over it, and its sheets the same: at 800 dp the scene lengths, ⋯, › and Send stood far from their words at the * screen's right edge (the store pass, 1600×2560 at 320 dpi, 26 Nov 2026). On a phone nothing changes. */ @RunWith(RobolectricTestRunner::class) class StoryTabletTest { @get:Rule val compose = createAndroidComposeRule() private fun surface() { compose.setContent { Box(Modifier.fillMaxSize().testTag("screen")) { Box(Modifier.align(Alignment.TopCenter).storyColumn().fillMaxSize().testTag("home")) Over(Modifier.align(Alignment.TopCenter).storyColumn()) { Box(Modifier.fillMaxSize().testTag("page")) } InkSheet("Your scripts", "Close", "sheet", onClose = {}) { Text("The Lantern Keepers") } } } } @Config(sdk = [35], qualifiers = "w800dp-h1280dp-mdpi", application = Application::class) @Test fun on_a_tablet_the_column_and_its_sheets_stand_in_the_middle() { surface() val screen = compose.onNodeWithTag("screen").getBoundsInRoot() for (tag in listOf("home", "page", "sheet")) { val b = compose.onNodeWithTag(tag, useUnmergedTree = true).getBoundsInRoot() assertEquals("$tag width", Ink.widest.value, (b.right - b.left).value, 1f) assertEquals("$tag centred", (b.left - screen.left).value, (screen.right - b.right).value, 1f) } } @Config(sdk = [35], qualifiers = "w400dp-h800dp-mdpi", application = Application::class) @Test fun on_a_phone_it_takes_the_whole_width() { surface() for (tag in listOf("home", "page", "sheet")) { val b = compose.onNodeWithTag(tag, useUnmergedTree = true).getBoundsInRoot() assertTrue("$tag: $b", (b.right - b.left) >= 400.dp - 1.dp) } } }