11package com.w2sv.composed.material3.extensions
22
3+ import androidx.compose.foundation.layout.width
34import androidx.compose.material3.DrawerState
45import androidx.compose.material3.DrawerValue
6+ import androidx.compose.material3.ModalDrawerSheet
57import androidx.compose.material3.ModalNavigationDrawer
6- import androidx.compose.runtime.getValue
8+ import androidx.compose.runtime.State
9+ import androidx.compose.ui.Modifier
710import androidx.compose.ui.test.junit4.createComposeRule
8- import com.w2sv.composed.material3.extensions.visibilityPercentage
9- import kotlin.properties.Delegates
10- import kotlinx.coroutines.test.runTest
11+ import androidx.compose.ui.unit.dp
12+ import kotlinx.coroutines.runBlocking
1113import org.junit.Assert.assertEquals
12- import org.junit.Ignore
1314import org.junit.Rule
1415import org.junit.Test
1516import org.junit.runner.RunWith
@@ -21,29 +22,29 @@ class DrawerStateKtTest {
2122 @get:Rule
2223 val composeTestRule = createComposeRule()
2324
24- private var maxWidthPx by Delegates .notNull<Float >()
25-
26- @Ignore(" Mysteriously not working anymore after update of compose dependencies. DrawerState.currentOffset always null." )
2725 @Test
28- fun visibilityPercentage () =
29- runTest {
30- val drawerState = DrawerState (initialValue = DrawerValue .Closed )
26+ fun visibilityProgress () {
27+ val drawerState = DrawerState (initialValue = DrawerValue .Closed )
28+ lateinit var visibilityProgress: State <Float >
29+ val sheetWidth = 300 .dp
30+
31+ with (composeTestRule) {
32+ setContent {
33+ visibilityProgress = drawerState.rememberVisibilityProgress(sheetWidth)
3134
32- composeTestRule.setContent {
33- maxWidthPx = 120f
3435 ModalNavigationDrawer (
35- drawerContent = { /* TODO*/ },
3636 drawerState = drawerState,
37+ drawerContent = { ModalDrawerSheet (modifier = Modifier .width(sheetWidth)) {} },
3738 content = {}
3839 )
3940 }
4041
41- val visibilityPercentage by drawerState.visibilityPercentage(maxWidthPx)
42-
43- assertEquals(0f , visibilityPercentage)
42+ runOnIdle {
43+ assertEquals(0f , visibilityProgress.value)
4444
45- drawerState.snapTo(DrawerValue .Open )
46-
47- assertEquals( 1f , visibilityPercentage)
45+ runBlocking { drawerState.snapTo(DrawerValue .Open ) }
46+ assertEquals( 1f , visibilityProgress.value)
47+ }
4848 }
49+ }
4950}
0 commit comments