Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47d84c25 authored by Nikhil Sharma's avatar Nikhil Sharma
Browse files

Added tests to VolumeSlidersComponentMotionTest

Bug: b/364012613
Test: VolumeSlidersComponentMotionTest
Flag: TEST_ONLY
Change-Id: I4b0540cdcfc9da3122b74ad84e8158bf3014eda7
parent e8d0c310
Loading
Loading
Loading
Loading
+30 −3
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.ProgressBarRangeInfo
@@ -83,6 +84,7 @@ import com.android.systemui.volume.ui.compose.slider.AccessibilityParams
import com.android.systemui.volume.ui.compose.slider.Haptics
import com.android.systemui.volume.ui.compose.slider.Slider
import com.android.systemui.volume.ui.compose.slider.SliderIcon
import com.google.common.annotations.VisibleForTesting
import kotlin.math.round
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
@@ -163,7 +165,15 @@ fun VolumeSlider(
                                    { iconsState ->
                                        SliderIcon(
                                            icon = {
                                                Icon(icon = icon, modifier = Modifier.size(24.dp))
                                                Icon(
                                                    icon = icon,
                                                    modifier =
                                                        Modifier.size(24.dp)
                                                            .testTag(
                                                                VolumeSlidersMotionTestKeys
                                                                    .ACTIVE_ICON_TAG
                                                            ),
                                                )
                                            },
                                            isVisible = !iconsState.isInactiveTrackEndIconVisible,
                                        )
@@ -174,7 +184,15 @@ fun VolumeSlider(
                                    { iconsState ->
                                        SliderIcon(
                                            icon = {
                                                Icon(icon = icon, modifier = Modifier.size(24.dp))
                                                Icon(
                                                    icon = icon,
                                                    modifier =
                                                        Modifier.size(24.dp)
                                                            .testTag(
                                                                VolumeSlidersMotionTestKeys
                                                                    .INACTIVE_ICON_TAG
                                                            ),
                                                )
                                            },
                                            isVisible = iconsState.isInactiveTrackEndIconVisible,
                                        )
@@ -211,7 +229,9 @@ fun VolumeSlider(
        state.disabledMessage?.let { disabledMessage ->
            AnimatedVisibility(visible = !state.isEnabled) {
                Row(
                    modifier = Modifier.padding(bottom = 12.dp),
                    modifier =
                        Modifier.padding(bottom = 12.dp)
                            .testTag(VolumeSlidersMotionTestKeys.DISABLED_MESSAGE_TAG),
                    horizontalArrangement = Arrangement.spacedBy(8.dp),
                    verticalAlignment = Alignment.CenterVertically,
                ) {
@@ -407,3 +427,10 @@ private fun setUpHapticsViewModel(
}

private fun ClosedFloatingPointRange<Float>.stepSize(): Float = 1f / (endInclusive - start)

@VisibleForTesting
object VolumeSlidersMotionTestKeys {
    const val ACTIVE_ICON_TAG = "Volume_Slider_activeStartIcon"
    const val INACTIVE_ICON_TAG = "Volume_Slider_inactiveStartIcon"
    const val DISABLED_MESSAGE_TAG = "disabledMessage"
}
+326 −0
Original line number Diff line number Diff line
{
  "frame_ids": [
    "before",
    0,
    16,
    32,
    48,
    64,
    80,
    96,
    112,
    128,
    144,
    160,
    176,
    192,
    208,
    224,
    240,
    256,
    272,
    288,
    304,
    320,
    336,
    352,
    368,
    384,
    400,
    416,
    432,
    448,
    464,
    480,
    496,
    512,
    528,
    544,
    "after"
  ],
  "features": [
    {
      "name": "Media_position_activeStartIcon",
      "type": "dpOffset",
      "data_points": [
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "x": 357.7143,
          "y": 497.42856
        },
        {
          "x": 344.57144,
          "y": 497.42856
        },
        {
          "x": 344.57144,
          "y": 497.42856
        },
        {
          "x": 330.85715,
          "y": 497.42856
        },
        {
          "x": 317.7143,
          "y": 497.42856
        },
        {
          "x": 304.57144,
          "y": 497.42856
        },
        {
          "x": 291.42856,
          "y": 497.42856
        },
        {
          "x": 278.2857,
          "y": 497.42856
        },
        {
          "x": 265.42856,
          "y": 497.42856
        },
        {
          "x": 252.28572,
          "y": 497.42856
        },
        {
          "x": 239.14285,
          "y": 497.42856
        },
        {
          "x": 239.14285,
          "y": 497.42856
        },
        {
          "x": 225.14285,
          "y": 497.42856
        },
        {
          "x": 212,
          "y": 497.42856
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        }
      ]
    },
    {
      "name": "Media_position_inactiveStartIcon",
      "type": "dpOffset",
      "data_points": [
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        },
        {
          "x": 377.42856,
          "y": 497.42856
        }
      ]
    }
  ]
}
 No newline at end of file
+316 −0
Original line number Diff line number Diff line
{
  "frame_ids": [
    "before",
    0,
    16,
    32,
    48,
    64,
    80,
    96,
    112,
    128,
    144,
    160,
    176,
    192,
    208,
    224,
    240,
    256,
    272,
    288,
    304,
    320,
    336,
    352,
    368,
    384,
    400,
    416,
    432,
    448,
    464,
    480,
    496,
    512,
    528,
    544,
    "after"
  ],
  "features": [
    {
      "name": "disabled_message_position",
      "type": "dpOffset",
      "data_points": [
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "type": "not_found"
        },
        {
          "x": 0,
          "y": 775.4286
        },
        {
          "x": 0,
          "y": 775.4286
        },
        {
          "x": 0,
          "y": 775.4286
        }
      ]
    },
    {
      "name": "ring_slider_position",
      "type": "dpOffset",
      "data_points": [
        {
          "type": "not_found"
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 659.4286
        },
        {
          "x": -10,
          "y": 631.4286
        }
      ]
    }
  ]
}
 No newline at end of file
+103 −0
Original line number Diff line number Diff line
@@ -25,7 +25,10 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasAnySibling
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.swipeLeft
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.android.settingslib.volume.shared.model.AudioStream
@@ -45,6 +48,7 @@ import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor
import com.android.systemui.volume.panel.component.mediaoutput.domain.model.MediaControllerChangeModel
import com.android.systemui.volume.panel.component.volume.slider.ui.viewmodel.AudioStreamSliderTestTags
import com.android.systemui.volume.panel.component.volume.ui.composable.ColumnVolumeSlidersMotionTestKeys
import com.android.systemui.volume.panel.component.volume.ui.composable.VolumeSlidersMotionTestKeys
import com.android.systemui.volume.panel.component.volume.volumeSlidersComponent
import com.android.systemui.volume.panel.ui.composable.VolumePanelComposeScope
import com.android.systemui.volume.panel.ui.viewmodel.volumePanelViewModel
@@ -127,6 +131,105 @@ class VolumeSlidersComponentMotionTest : SysuiTestCase() {
                .timeSeriesMatchesGolden("VolumePanel_VolumeSliders_testCollapsedToExpanded")
        }

    @Test
    fun recordMediaIconPosition() =
        motionTestRule.runTest() {
            val tag =
                checkNotNull(
                    AudioStreamSliderTestTags.testTagsByStream[
                            AudioStream(AudioManager.STREAM_MUSIC)]
                )

            val motion =
                recordMotion(
                    content = { kosmos.Sliders() },
                    recordingSpec =
                        ComposeRecordingSpec(
                            MotionControl(
                                recording = {
                                    performTouchInputAsync(
                                        onNode(hasTestTag(resIdToTestTag(tag)))
                                    ) {
                                        swipeLeft(startX = right, endX = left, durationMillis = 500)
                                    }
                                }
                            )
                        ) {
                            feature(
                                hasTestTag(VolumeSlidersMotionTestKeys.ACTIVE_ICON_TAG)
                                    .and(hasAnyAncestor(hasTestTag(resIdToTestTag(tag)))),
                                positionInRoot,
                                "${tag}_position_activeStartIcon",
                                true,
                            )
                            feature(
                                hasTestTag(VolumeSlidersMotionTestKeys.INACTIVE_ICON_TAG)
                                    .and(hasAnyAncestor(hasTestTag(resIdToTestTag(tag)))),
                                positionInRoot,
                                "${tag}_position_inactiveStartIcon",
                                true,
                            )
                        },
                )
            assertThat(motion)
                .timeSeriesMatchesGolden("VolumePanel_VolumeSliders_recordMediaIconPosition")
        }

    @Test
    fun testMuteRingerMutesNotification() =
        motionTestRule.runTest() {
            val ringTag =
                checkNotNull(
                    AudioStreamSliderTestTags.testTagsByStream[
                            AudioStream(AudioManager.STREAM_RING)]
                )
            val notificationTag =
                checkNotNull(
                    AudioStreamSliderTestTags.testTagsByStream[
                            AudioStream(AudioManager.STREAM_NOTIFICATION)]
                )
            val motion =
                recordMotion(
                    content = { kosmos.Sliders() },
                    recordingSpec =
                        ComposeRecordingSpec(
                            MotionControl(
                                recording = {
                                    performTouchInputAsync(
                                        onNode(hasTestTag(resIdToTestTag(ringTag)))
                                    ) {
                                        swipeLeft(
                                            startX = right / 5,
                                            endX = left,
                                            durationMillis = 500,
                                        )
                                    }
                                }
                            )
                        ) {
                            feature(
                                hasTestTag(VolumeSlidersMotionTestKeys.DISABLED_MESSAGE_TAG)
                                    .and(
                                        hasAnySibling(hasTestTag(resIdToTestTag(notificationTag)))
                                    ),
                                positionInRoot,
                                "disabled_message_position",
                                true,
                            )
                            feature(
                                hasTestTag(resIdToTestTag(ringTag)),
                                positionInRoot,
                                "ring_slider_position",
                                true,
                            )
                        },
                )
            assertThat(motion)
                .timeSeriesMatchesGolden(
                    "VolumePanel_VolumeSliders_testMuteRingerMutesNotification"
                )
        }

    @Test
    fun testExpandedToCollapsed() =
        motionTestRule.runTest {