1 /* 2 * Copyright (C) 2023 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 @file:OptIn(ExperimentalCoroutinesApi::class) 18 19 package com.android.systemui.statusbar.notification.row.ui.viewmodel 20 21 import androidx.test.ext.junit.runners.AndroidJUnit4 22 import androidx.test.filters.SmallTest 23 import com.android.systemui.SysuiTestCase 24 import com.android.systemui.accessibility.data.repository.FakeAccessibilityRepository 25 import com.android.systemui.accessibility.domain.interactor.AccessibilityInteractor 26 import com.android.systemui.coroutines.collectLastValue 27 import com.google.common.truth.Truth.assertThat 28 import kotlinx.coroutines.ExperimentalCoroutinesApi 29 import kotlinx.coroutines.test.runCurrent 30 import kotlinx.coroutines.test.runTest 31 import org.junit.Test 32 import org.junit.runner.RunWith 33 34 @RunWith(AndroidJUnit4::class) 35 @SmallTest 36 class ActivatableNotificationViewModelTest : SysuiTestCase() { 37 38 // fakes 39 private val a11yRepo = FakeAccessibilityRepository() 40 41 // real impls 42 private val a11yInteractor = AccessibilityInteractor(a11yRepo) 43 private val underTest = ActivatableNotificationViewModel(a11yInteractor) 44 45 @Test <lambda>null46 fun isTouchable_whenA11yTouchExplorationDisabled() = runTest { 47 a11yRepo.isTouchExplorationEnabled.value = false 48 val isTouchable: Boolean? by collectLastValue(underTest.isTouchable) 49 assertThat(isTouchable).isTrue() 50 } 51 52 @Test <lambda>null53 fun isNotTouchable_whenA11yTouchExplorationEnabled() = runTest { 54 a11yRepo.isTouchExplorationEnabled.value = true 55 val isTouchable: Boolean? by collectLastValue(underTest.isTouchable) 56 assertThat(isTouchable).isFalse() 57 } 58 59 @Test <lambda>null60 fun isTouchable_whenA11yTouchExplorationChangesToDisabled() = runTest { 61 a11yRepo.isTouchExplorationEnabled.value = true 62 val isTouchable: Boolean? by collectLastValue(underTest.isTouchable) 63 runCurrent() 64 a11yRepo.isTouchExplorationEnabled.value = false 65 assertThat(isTouchable).isTrue() 66 } 67 68 @Test <lambda>null69 fun isNotTouchable_whenA11yTouchExplorationChangesToEnabled() = runTest { 70 a11yRepo.isTouchExplorationEnabled.value = false 71 val isTouchable: Boolean? by collectLastValue(underTest.isTouchable) 72 runCurrent() 73 a11yRepo.isTouchExplorationEnabled.value = true 74 assertThat(isTouchable).isFalse() 75 } 76 } 77