Cotton code
52 lines · 2.3 KB · KotlinRaw
package com.cottondb.daysimport android.app.Applicationimport android.view.Viewimport android.view.ViewGroupimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxSizeimport 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.WindowInsetsCompatimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Days on its side with the camera's cutout at the left (the emulator's punch hole, 136 px of cutout inset at 2.625, * 21 Nov 2026): the times and marks at the start of every row stood under the hole. Days now stands clear of the * sides' cutout and navigation buttons. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w800dp-h400dp-land-mdpi", application = Application::class)class DaysSidesTest {    @get:Rule val compose = createAndroidComposeRule<androidx.activity.ComponentActivity>()    @Test fun days_stands_clear_of_a_cutout_at_its_side() {        compose.setContent {            Box(Modifier.fillMaxSize().clearOfSides()) { Box(Modifier.fillMaxSize().testTag("inside")) }        }        compose.runOnIdle {            val content = compose.activity.findViewById<ViewGroup>(android.R.id.content)            val view: View = content.getChildAt(0)            val insets = WindowInsetsCompat.Builder()                .setInsets(WindowInsetsCompat.Type.displayCutout(), Insets.of(48, 0, 0, 0))                .setInsets(WindowInsetsCompat.Type.navigationBars(), Insets.of(0, 0, 32, 0))                .build()            ViewCompat.dispatchApplyWindowInsets(view, insets)        }        compose.waitForIdle()        val inside = compose.onNodeWithTag("inside").getBoundsInRoot()        assertEquals("clear of the cutout at the left", 48.dp, inside.left)        assertEquals("clear of the navigation buttons at the right", 800.dp - 32.dp, inside.right)    }}