Cotton code
102 lines · 4.5 KB · KotlinRaw
package com.cottondb.storyimport android.app.Applicationimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.material3.Textimport androidx.compose.ui.Modifierimport androidx.compose.ui.geometry.Offsetimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.performClickimport androidx.compose.ui.test.performTouchInputimport androidx.compose.ui.test.clickimport androidx.compose.ui.unit.dpimport com.cottondb.shell.controlimport com.cottondb.story.ink.Overimport com.cottondb.story.ink.hiddenUnderimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.onNodeWithContentDescriptionimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * A page over the home (a character, About, Read, a scene) takes every touch on it: a tap on its bare top bar opened * Your scripts from the home's title under it (the emulator, 21 Nov 2026). The home here is a title and a scene row * filling the screen; the page over it a back mark at the top left and one row at its foot. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class)class StoryOverTest {    @get:Rule val compose = createComposeRule()    private var home = 0    private var back = 0    private var row = 0    private fun page(over: Boolean, hidden: Boolean = over) {        compose.setContent {            Box(Modifier.fillMaxSize()) {                // As StorySurface draws it: the home's column hidden while a page stands, the home inside it.                Box(Modifier.fillMaxSize().hiddenUnder(hidden)) {                    Box(Modifier.fillMaxSize().testTag("home").control("home") { home++ }) { Text("The Lantern Keepers") }                }                val page = @androidx.compose.runtime.Composable {                    Column(Modifier.fillMaxSize()) {                        Box(Modifier.padding(8.dp).size(48.dp).testTag("back").control("back") { back++ })                        Spacer(Modifier.weight(1f))                        Box(Modifier.fillMaxWidth().height(56.dp).testTag("row").control("row") { row++ })                    }                }                if (over) Over(content = page) else Box(Modifier.fillMaxSize()) { page() }            }        }    }    @Test fun a_tap_on_a_bare_part_of_a_page_reaches_nothing_under_it() {        page(over = true)        // The top bar's middle, and the empty middle of the page.        compose.onNodeWithTag("story-over").performTouchInput { click(Offset(centerX, 30f)) }        compose.onNodeWithTag("story-over").performTouchInput { click(center) }        compose.waitForIdle()        assertEquals("the home under the page was tapped", 0, home)        compose.onNodeWithTag("back").performClick()        compose.onNodeWithTag("row").performClick()        compose.waitForIdle()        assertEquals(1, back)        assertEquals(1, row)    }    @Test fun without_it_the_home_under_a_page_takes_the_tap() {        // What the emulator showed, held so the test above means something.        page(over = false)        compose.onNodeWithTag("home").performTouchInput { click(Offset(centerX, 30f)) }        compose.waitForIdle()        assertEquals(1, home)    }    @Test fun talkback_finds_nothing_of_the_home_under_a_page() {        // TalkBack reached the home's title and New scene wherever a page drew nothing over them (emulator-5602, 26 Nov 2026).        page(over = true)        compose.onNodeWithContentDescription("home").assertDoesNotExist()        compose.onNodeWithText("The Lantern Keepers").assertDoesNotExist()        compose.onNodeWithContentDescription("back").assertExists()        compose.onNodeWithContentDescription("row").assertExists()    }    @Test fun with_no_page_the_home_is_read_out() {        page(over = false, hidden = false)        compose.onNodeWithContentDescription("home").assertExists()    }}