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.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material3.Text import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.swipeLeft import com.cottondb.story.ink.InkSheet 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 sheet over a scene (a line's acts, Where and when, the direction) keeps a sideways swipe on it: the scenes' pager under * it stays on its scene. On the emulator a sideways swipe on a line's acts turned to the next scene and the sheet went. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class) class StorySceneSheetTest { @get:Rule val compose = createAndroidComposeRule() private lateinit var pager: PagerState /** Three invented scenes as ScenesPager pages them; the first shows a line's acts when [sheet]. */ private fun scenes(sheet: Boolean) { compose.setContent { pager = rememberPagerState { 3 } HorizontalPager(pager, Modifier.fillMaxSize().testTag("pager")) { at -> Box(Modifier.fillMaxSize()) { Text("Scene ${at + 1}") if (sheet && at == 0) InkSheet("Arlo", "Close", "acts", onClose = {}) { Text("Move later") } } } } } @Test fun a_sideways_swipe_on_a_sheet_keeps_its_scene() { scenes(sheet = true) compose.onNodeWithTag("acts").performTouchInput { swipeLeft(startX = right - 10f, endX = left + 10f, durationMillis = 250) } compose.waitForIdle() assertEquals(0, pager.currentPage) } @Test fun without_a_sheet_the_swipe_turns_the_scene() { scenes(sheet = false) compose.onNodeWithTag("pager").performTouchInput { swipeLeft(startX = right - 10f, endX = left + 10f, durationMillis = 250) } compose.waitForIdle() assertEquals(1, pager.currentPage) } }