yschimke
03/23/2022, 8:57 AM@Test
fun testAutoHide() {
composeTestRule.setContent {
VolumePositionIndicator(
modifier = Modifier.testTag(TEST_TAG),
volumeState = { volumeState },
autoHide = true
)
}
val positionIndicator = composeTestRule.onNodeWithTag(TEST_TAG)
positionIndicator.assertDoesNotExist()
volumeState = volumeState.copy(current = 51)
composeTestRule.mainClock.advanceTimeByFrame()
composeTestRule.mainClock.advanceTimeBy(500L)
composeTestRule.onRoot(useUnmergedTree = true).printToLog("testAutoHide")
positionIndicator.assertIsDisplayed()
}
yschimke
03/23/2022, 8:57 AMyschimke
03/23/2022, 8:58 AMyschimke
03/23/2022, 9:11 AMyschimke
03/23/2022, 9:13 AMJohn Nichol
03/23/2022, 5:55 PMSteve Bower [G]
03/24/2022, 11:17 AMcomposeTestRule.mainClock.autoAdvance = false
at the start of the test if the clock is going to be manually driven. In which case, yes, the clock will be fixed and the animations won't run until the clock is advanced manually.
For (2), could you be more specific about the tests you want to run against PositionIndicator? There are a number of overloads for which the scroll state is public (e.g. ScalingLazyListState) or you can add your own PositionIndicatorState implementation.yschimke
03/24/2022, 11:25 AM@get:Rule
val composeTestRule = createComposeRule().apply {
mainClock.autoAdvance = false
}
yschimke
03/24/2022, 11:27 AM@Composable
public fun PositionIndicator(
value: () -> Float,
modifier: Modifier = Modifier,
range: ClosedFloatingPointRange<Float> = 0f..1f,
color: Color = MaterialTheme.colors.onBackground,
reverseDirection: Boolean = false
) = PositionIndicator(
state = FractionPositionIndicatorState {
(value() - range.start) / (range.endInclusive - range.start)
},
yschimke
03/24/2022, 11:27 AMyschimke
03/24/2022, 11:31 AMSteve Bower [G]
03/24/2022, 1:58 PM