1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.volume.ui.navigation 18 19 import androidx.test.ext.junit.runners.AndroidJUnit4 20 import androidx.test.filters.SmallTest 21 import com.android.internal.logging.uiEventLoggerFake 22 import com.android.systemui.SysuiTestCase 23 import com.android.systemui.coroutines.collectLastValue 24 import com.android.systemui.kosmos.testDispatcher 25 import com.android.systemui.kosmos.testScope 26 import com.android.systemui.plugins.ActivityStarter 27 import com.android.systemui.plugins.activityStarter 28 import com.android.systemui.testKosmos 29 import com.android.systemui.volume.domain.model.VolumePanelRoute 30 import com.android.systemui.volume.panel.domain.interactor.volumePanelGlobalStateInteractor 31 import com.android.systemui.volume.panel.ui.viewmodel.volumePanelViewModelFactory 32 import com.google.common.truth.Truth.assertThat 33 import kotlinx.coroutines.ExperimentalCoroutinesApi 34 import kotlinx.coroutines.test.runCurrent 35 import kotlinx.coroutines.test.runTest 36 import org.junit.Test 37 import org.junit.runner.RunWith 38 import org.mockito.ArgumentMatchers.anyBoolean 39 import org.mockito.ArgumentMatchers.anyInt 40 import org.mockito.kotlin.any 41 import org.mockito.kotlin.mock 42 import org.mockito.kotlin.whenever 43 44 @OptIn(ExperimentalCoroutinesApi::class) 45 @SmallTest 46 @RunWith(AndroidJUnit4::class) 47 class VolumeNavigatorTest : SysuiTestCase() { 48 49 private val kosmos = testKosmos() 50 51 private val underTest: VolumeNavigator = <lambda>null52 with(kosmos) { 53 VolumeNavigator( 54 testScope.backgroundScope, 55 testDispatcher, 56 mock {}, 57 activityStarter, 58 volumePanelViewModelFactory, 59 mock { 60 on { create(any(), anyInt(), anyBoolean(), any()) }.thenReturn(mock {}) 61 on { applicationContext }.thenReturn(context) 62 }, 63 uiEventLoggerFake, 64 volumePanelGlobalStateInteractor, 65 ) 66 } 67 68 @Test showNewVolumePanel_keyguardLocked_notShownnull69 fun showNewVolumePanel_keyguardLocked_notShown() = 70 with(kosmos) { 71 testScope.runTest { 72 val panelState by collectLastValue(volumePanelGlobalStateInteractor.globalState) 73 74 underTest.openVolumePanel(VolumePanelRoute.COMPOSE_VOLUME_PANEL) 75 runCurrent() 76 77 assertThat(panelState!!.isVisible).isFalse() 78 } 79 } 80 81 @Test showNewVolumePanel_keyguardUnlocked_shownnull82 fun showNewVolumePanel_keyguardUnlocked_shown() = 83 with(kosmos) { 84 testScope.runTest { 85 whenever(activityStarter.dismissKeyguardThenExecute(any(), any(), anyBoolean())) 86 .then { (it.arguments[0] as ActivityStarter.OnDismissAction).onDismiss() } 87 val panelState by collectLastValue(volumePanelGlobalStateInteractor.globalState) 88 89 underTest.openVolumePanel(VolumePanelRoute.COMPOSE_VOLUME_PANEL) 90 runCurrent() 91 92 assertThat(panelState!!.isVisible).isTrue() 93 } 94 } 95 } 96