• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.systemui.statusbar.notification.row.ui.viewmodel
18 
19 import androidx.test.ext.junit.runners.AndroidJUnit4
20 import androidx.test.filters.SmallTest
21 import com.android.systemui.SysuiTestCase
22 import com.android.systemui.accessibility.data.repository.FakeAccessibilityRepository
23 import com.android.systemui.accessibility.domain.interactor.AccessibilityInteractor
24 import com.android.systemui.coroutines.collectLastValue
25 import com.google.common.truth.Truth.assertThat
26 import kotlinx.coroutines.test.runCurrent
27 import kotlinx.coroutines.test.runTest
28 import org.junit.Test
29 import org.junit.runner.RunWith
30 
31 @RunWith(AndroidJUnit4::class)
32 @SmallTest
33 class ActivatableNotificationViewModelTest : SysuiTestCase() {
34 
35     // fakes
36     private val a11yRepo = FakeAccessibilityRepository()
37 
38     // real impls
39     private val a11yInteractor = AccessibilityInteractor(a11yRepo)
40     private val underTest = ActivatableNotificationViewModel(a11yInteractor)
41 
42     @Test
<lambda>null43     fun isTouchable_whenA11yTouchExplorationDisabled() = runTest {
44         a11yRepo.isTouchExplorationEnabled.value = false
45         val isTouchable: Boolean? by collectLastValue(underTest.isTouchable)
46         assertThat(isTouchable).isTrue()
47     }
48 
49     @Test
<lambda>null50     fun isNotTouchable_whenA11yTouchExplorationEnabled() = runTest {
51         a11yRepo.isTouchExplorationEnabled.value = true
52         val isTouchable: Boolean? by collectLastValue(underTest.isTouchable)
53         assertThat(isTouchable).isFalse()
54     }
55 
56     @Test
<lambda>null57     fun isTouchable_whenA11yTouchExplorationChangesToDisabled() = runTest {
58         a11yRepo.isTouchExplorationEnabled.value = true
59         val isTouchable: Boolean? by collectLastValue(underTest.isTouchable)
60         runCurrent()
61         a11yRepo.isTouchExplorationEnabled.value = false
62         assertThat(isTouchable).isTrue()
63     }
64 
65     @Test
<lambda>null66     fun isNotTouchable_whenA11yTouchExplorationChangesToEnabled() = runTest {
67         a11yRepo.isTouchExplorationEnabled.value = false
68         val isTouchable: Boolean? by collectLastValue(underTest.isTouchable)
69         runCurrent()
70         a11yRepo.isTouchExplorationEnabled.value = true
71         assertThat(isTouchable).isFalse()
72     }
73 }
74