65 lines · 2.9 KB · KotlinRaw
package com.cottondb.storyimport android.app.Applicationimport androidx.activity.ComponentActivityimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.material3.Textimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.unit.dpimport com.cottondb.story.ink.Inkimport com.cottondb.story.ink.InkSheetimport com.cottondb.story.ink.Overimport com.cottondb.story.ink.storyColumnimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport 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<ComponentActivity>() 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) } }}