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.keyguard.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.coroutines.collectLastValue
23 import com.android.systemui.keyguard.data.repository.fakeKeyguardClockRepository
24 import com.android.systemui.keyguard.data.repository.keyguardClockRepository
25 import com.android.systemui.keyguard.data.repository.keyguardSmartspaceRepository
26 import com.android.systemui.keyguard.shared.model.ClockSize
27 import com.android.systemui.kosmos.testScope
28 import com.android.systemui.plugins.clocks.ClockController
29 import com.android.systemui.testKosmos
30 import com.android.systemui.util.mockito.whenever
31 import com.google.common.truth.Truth.assertThat
32 import kotlinx.coroutines.test.runTest
33 import org.junit.Before
34 import org.junit.Test
35 import org.junit.runner.RunWith
36 import org.mockito.Answers
37 import org.mockito.Mock
38 import org.mockito.MockitoAnnotations
39 
40 @SmallTest
41 @RunWith(AndroidJUnit4::class)
42 class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
43     val kosmos = testKosmos()
44     val testScope = kosmos.testScope
45     val underTest = kosmos.keyguardSmartspaceViewModel
46     val res = context.resources
47 
48     @Mock(answer = Answers.RETURNS_DEEP_STUBS) private lateinit var clockController: ClockController
49 
50     @Before
setupnull51     fun setup() {
52         MockitoAnnotations.initMocks(this)
53         kosmos.fakeKeyguardClockRepository.setCurrentClock(clockController)
54     }
55 
56     @Test
testWhenWeatherEnabled_notCustomWeatherDataDisplay_isWeatherVisible_shouldBeTruenull57     fun testWhenWeatherEnabled_notCustomWeatherDataDisplay_isWeatherVisible_shouldBeTrue() =
58         testScope.runTest {
59             val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
60             whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay)
61                 .thenReturn(false)
62 
63             with(kosmos) {
64                 keyguardSmartspaceRepository.setIsWeatherEnabled(true)
65                 keyguardClockRepository.setClockSize(ClockSize.LARGE)
66             }
67 
68             assertThat(isWeatherVisible).isEqualTo(true)
69         }
70 
71     @Test
testWhenWeatherEnabled_hasCustomWeatherDataDisplay_isWeatherVisible_shouldBeFalsenull72     fun testWhenWeatherEnabled_hasCustomWeatherDataDisplay_isWeatherVisible_shouldBeFalse() =
73         testScope.runTest {
74             val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
75             whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay).thenReturn(true)
76 
77             with(kosmos) {
78                 keyguardSmartspaceRepository.setIsWeatherEnabled(true)
79                 keyguardClockRepository.setClockSize(ClockSize.LARGE)
80             }
81 
82             assertThat(isWeatherVisible).isEqualTo(false)
83         }
84 
85     @Test
testWhenWeatherEnabled_notCustomWeatherDataDisplay_notIsWeatherVisible_shouldBeFalsenull86     fun testWhenWeatherEnabled_notCustomWeatherDataDisplay_notIsWeatherVisible_shouldBeFalse() =
87         testScope.runTest {
88             val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
89             whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay)
90                 .thenReturn(false)
91 
92             with(kosmos) {
93                 keyguardSmartspaceRepository.setIsWeatherEnabled(false)
94                 keyguardClockRepository.setClockSize(ClockSize.LARGE)
95             }
96 
97             assertThat(isWeatherVisible).isEqualTo(false)
98         }
99 }
100