package com.cottondb.story import android.app.Application import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.Text import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.click import androidx.compose.ui.unit.dp import com.cottondb.shell.control import com.cottondb.story.ink.Over import com.cottondb.story.ink.hiddenUnder import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onNodeWithContentDescription import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import 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() } }