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.customization.model.picker.settings.domain.interactor
18 
19 import android.app.UiModeManager.ContrastUtils
20 import androidx.test.filters.SmallTest
21 import com.android.customization.picker.settings.domain.interactor.ColorContrastSectionInteractor
22 import com.android.wallpaper.testing.FakeUiModeManager
23 import com.google.common.truth.Truth.assertThat
24 import dagger.hilt.android.testing.HiltAndroidRule
25 import dagger.hilt.android.testing.HiltAndroidTest
26 import javax.inject.Inject
27 import kotlinx.coroutines.flow.first
28 import kotlinx.coroutines.test.runTest
29 import org.junit.Before
30 import org.junit.Rule
31 import org.junit.Test
32 import org.junit.runner.RunWith
33 import org.robolectric.RobolectricTestRunner
34 
35 @SmallTest
36 @HiltAndroidTest
37 @RunWith(RobolectricTestRunner::class)
38 class ColorContrastSectionInteractorTest {
39     @get:Rule var hiltRule = HiltAndroidRule(this)
40 
41     @Inject lateinit var uiModeManager: FakeUiModeManager
42     @Inject lateinit var interactor: ColorContrastSectionInteractor
43 
44     @Before
setUpnull45     fun setUp() {
46         hiltRule.inject()
47     }
48 
49     @Test
<lambda>null50     fun contrastEmitCorrectValuesFromRepository() = runTest {
51         val contrastVal = 0.5f
52         val expectedContrastVal = ContrastUtils.toContrastLevel(contrastVal)
53         uiModeManager.setContrast(contrastVal)
54 
55         val result = interactor.contrast.first()
56 
57         assertThat(result).isEqualTo(expectedContrastVal)
58     }
59 }
60