package com.cottondb.story import android.app.Application import android.view.ViewGroup import androidx.activity.ComponentActivity import androidx.compose.material3.Text 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 androidx.core.graphics.Insets import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import com.cottondb.story.ink.InkPageFrame import com.cottondb.story.ink.InkSheet 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 /** * Turned to landscape, the camera's cutout stands at a side edge (the emulator: 136 px, 52 dp, at the left) and Story's * pages, sheets and home drew their words and marks under it. Here a 52 dp cutout at the left of a landscape screen: * a page's back and words, and a sheet's title and rows, stand clear of it. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w700dp-h400dp-land-mdpi", application = Application::class) class StoryCutoutTest { @get:Rule val compose = createAndroidComposeRule() private fun cutout(left: Int) { compose.runOnUiThread { val view = compose.activity.findViewById(android.R.id.content).getChildAt(0) val insets = WindowInsetsCompat.Builder() .setInsets(WindowInsetsCompat.Type.displayCutout(), Insets.of(left, 0, 0, 0)) .build() ViewCompat.dispatchApplyWindowInsets(view, insets) } compose.waitForIdle() } @Test fun a_page_stands_clear_of_the_cutout() { compose.runOnUiThread { WindowCompat.setDecorFitsSystemWindows(compose.activity.window, false) } compose.setContent { InkPageFrame("Back", "More", "Arlo", "page", onBack = {}) { Text("Five lines", Modifier.testTag("words")) } } cutout(52) val back = compose.onNodeWithTag("page-back").getBoundsInRoot().left val words = compose.onNodeWithTag("words").getBoundsInRoot().left assertTrue("the back mark under the cutout: $back", back >= 52.dp) assertTrue("the words under the cutout: $words", words >= 52.dp) } @Test fun a_sheet_stands_clear_of_the_cutout() { compose.runOnUiThread { WindowCompat.setDecorFitsSystemWindows(compose.activity.window, false) } compose.setContent { InkSheet("Your scripts", "Close", "sheet", onClose = {}) { Text("The Lantern Keepers", Modifier.testTag("row")) } } cutout(52) val row = compose.onNodeWithTag("row").getBoundsInRoot().left assertTrue("the sheet's row under the cutout: $row", row >= 52.dp) } }