Cotton code
68 lines · 3.0 KB · KotlinRaw
package com.cottondb.storyimport android.app.Applicationimport android.view.ViewGroupimport androidx.activity.ComponentActivityimport androidx.compose.material3.Textimport 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 androidx.core.graphics.Insetsimport androidx.core.view.ViewCompatimport androidx.core.view.WindowCompatimport androidx.core.view.WindowInsetsCompatimport com.cottondb.story.ink.InkPageFrameimport com.cottondb.story.ink.InkSheetimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport 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<ComponentActivity>()    private fun cutout(left: Int) {        compose.runOnUiThread {            val view = compose.activity.findViewById<ViewGroup>(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)    }}