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

Commit c5793bb2 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Bind the new sliders to the state updates." into main

parents 8e583ef5 ac7a0d77
Loading
Loading
Loading
Loading
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.dialog.sliders.domain.interactor

import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.VolumeDialogController
import com.android.systemui.plugins.fakeVolumeDialogController
import com.android.systemui.testKosmos
import com.android.systemui.volume.dialog.sliders.domain.model.volumeDialogSliderType
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
class VolumeDialogSliderInteractorTest : SysuiTestCase() {

    private val kosmos = testKosmos()

    private lateinit var underTest: VolumeDialogSliderInteractor

    @Before
    fun setUp() {
        underTest = kosmos.volumeDialogSliderInteractor
    }

    @Test
    fun settingStreamVolume_setsActiveStream() =
        with(kosmos) {
            testScope.runTest {
                runCurrent()
                // initialize the stream model
                fakeVolumeDialogController.setStreamVolume(volumeDialogSliderType.audioStream, 0)

                val sliderModel by collectLastValue(underTest.slider)
                underTest.setStreamVolume(1)
                runCurrent()

                assertThat(sliderModel!!.isActive).isTrue()
            }
        }

    @Test
    fun streamVolumeIs_minMaxAreEnforced() =
        with(kosmos) {
            testScope.runTest {
                runCurrent()
                fakeVolumeDialogController.updateState {
                    states.put(
                        volumeDialogSliderType.audioStream,
                        VolumeDialogController.StreamState().apply {
                            levelMin = 0
                            level = 2
                            levelMax = 1
                        },
                    )
                }

                val sliderModel by collectLastValue(underTest.slider)
                runCurrent()

                assertThat(sliderModel!!.level).isEqualTo(1)
            }
        }
}
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
        android:showDividers="middle" />

    <LinearLayout
        android:id="@+id/volume_dialog"
        android:layout_width="@dimen/volume_dialog_width"
        android:layout_height="wrap_content"
        android:background="@drawable/volume_dialog_background"
@@ -50,9 +51,7 @@
            android:layout_width="@dimen/volume_dialog_button_size"
            android:layout_height="@dimen/volume_dialog_button_size" />

        <include
            android:id="@+id/volume_dialog_slider"
            layout="@layout/volume_dialog_slider" />
        <include layout="@layout/volume_dialog_slider" />

        <Button
            android:id="@+id/volume_dialog_settings"
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
        android:showDividers="middle" />

    <LinearLayout
        android:id="@+id/volume_dialog"
        android:layout_width="@dimen/volume_dialog_width"
        android:layout_height="wrap_content"
        android:background="@drawable/volume_dialog_background"
@@ -50,9 +51,7 @@
            android:layout_width="@dimen/volume_dialog_button_size"
            android:layout_height="@dimen/volume_dialog_button_size" />

        <include
            android:id="@+id/volume_dialog_slider"
            layout="@layout/volume_dialog_slider" />
        <include layout="@layout/volume_dialog_slider" />

        <Button
            android:id="@+id/volume_dialog_settings"
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
        android:showDividers="middle" />

    <LinearLayout
        android:id="@+id/volume_dialog"
        android:layout_width="@dimen/volume_dialog_width"
        android:layout_height="wrap_content"
        android:background="@drawable/volume_dialog_background"
@@ -50,9 +51,7 @@
            android:layout_width="@dimen/volume_dialog_button_size"
            android:layout_height="@dimen/volume_dialog_button_size" />

        <include
            android:id="@+id/volume_dialog_slider"
            layout="@layout/volume_dialog_slider" />
        <include layout="@layout/volume_dialog_slider" />

        <Button
            android:id="@+id/volume_dialog_settings"
+2 −2
Original line number Diff line number Diff line
@@ -105,8 +105,8 @@ constructor(
            scope.trySend(VolumeDialogEventModel.ShowSafetyWarning(flags))
        }

        override fun onAccessibilityModeChanged(showA11yStream: Boolean) {
            scope.trySend(VolumeDialogEventModel.AccessibilityModeChanged(showA11yStream))
        override fun onAccessibilityModeChanged(showA11yStream: Boolean?) {
            scope.trySend(VolumeDialogEventModel.AccessibilityModeChanged(showA11yStream == true))
        }

        // Captions button is remove from the Volume Dialog
Loading