1 package com.android.customization.picker.clock.domain.interactor 2 3 import androidx.test.filters.SmallTest 4 import com.android.customization.picker.clock.data.repository.FakeClockPickerRepository 5 import com.android.customization.picker.clock.shared.ClockSize 6 import com.android.wallpaper.testing.FakeSnapshotStore 7 import com.android.wallpaper.testing.collectLastValue 8 import com.google.common.truth.Truth 9 import kotlinx.coroutines.Dispatchers 10 import kotlinx.coroutines.ExperimentalCoroutinesApi 11 import kotlinx.coroutines.runBlocking 12 import kotlinx.coroutines.test.StandardTestDispatcher 13 import kotlinx.coroutines.test.resetMain 14 import kotlinx.coroutines.test.runTest 15 import kotlinx.coroutines.test.setMain 16 import org.junit.After 17 import org.junit.Before 18 import org.junit.Test 19 import org.junit.runner.RunWith 20 import org.robolectric.RobolectricTestRunner 21 22 @OptIn(ExperimentalCoroutinesApi::class) 23 @SmallTest 24 @RunWith(RobolectricTestRunner::class) 25 class ClockPickerInteractorTest { 26 27 private lateinit var underTest: ClockPickerInteractor 28 29 @Before setUpnull30 fun setUp() { 31 val testDispatcher = StandardTestDispatcher() 32 Dispatchers.setMain(testDispatcher) 33 val repository = FakeClockPickerRepository() 34 underTest = 35 ClockPickerInteractor( 36 repository = repository, 37 snapshotRestorer = 38 ClockPickerSnapshotRestorer(repository = repository).apply { 39 runBlocking { setUpSnapshotRestorer(store = FakeSnapshotStore()) } 40 }, 41 ) 42 } 43 44 @After tearDownnull45 fun tearDown() { 46 Dispatchers.resetMain() 47 } 48 49 @Test <lambda>null50 fun setSelectedClock() = runTest { 51 val observedSelectedClockId = collectLastValue(underTest.selectedClockId) 52 underTest.setSelectedClock(FakeClockPickerRepository.fakeClocks[1].clockId) 53 Truth.assertThat(observedSelectedClockId()) 54 .isEqualTo(FakeClockPickerRepository.fakeClocks[1].clockId) 55 } 56 57 @Test <lambda>null58 fun setClockSize() = runTest { 59 val observedClockSize = collectLastValue(underTest.selectedClockSize) 60 underTest.setClockSize(ClockSize.DYNAMIC) 61 Truth.assertThat(observedClockSize()).isEqualTo(ClockSize.DYNAMIC) 62 63 underTest.setClockSize(ClockSize.SMALL) 64 Truth.assertThat(observedClockSize()).isEqualTo(ClockSize.SMALL) 65 } 66 67 @Test <lambda>null68 fun setColor() = runTest { 69 val observedSelectedColor = collectLastValue(underTest.selectedColorId) 70 val observedColorToneProgress = collectLastValue(underTest.colorToneProgress) 71 val observedSeedColor = collectLastValue(underTest.seedColor) 72 underTest.setClockColor( 73 FakeClockPickerRepository.CLOCK_COLOR_ID, 74 FakeClockPickerRepository.CLOCK_COLOR_TONE_PROGRESS, 75 FakeClockPickerRepository.SEED_COLOR, 76 ) 77 Truth.assertThat(observedSelectedColor()) 78 .isEqualTo(FakeClockPickerRepository.CLOCK_COLOR_ID) 79 Truth.assertThat(observedColorToneProgress()) 80 .isEqualTo(FakeClockPickerRepository.CLOCK_COLOR_TONE_PROGRESS) 81 Truth.assertThat(observedSeedColor()).isEqualTo(FakeClockPickerRepository.SEED_COLOR) 82 } 83 84 @Test <lambda>null85 fun setFontAxisSettings() = runTest { 86 val axisSettings = collectLastValue(underTest.axisSettings) 87 val fakeSettings = listOf(FakeClockPickerRepository.buildFakeAxis(10).toSetting()) 88 89 underTest.setClockFontAxes(fakeSettings) 90 91 Truth.assertThat(axisSettings()).isEqualTo(fakeSettings) 92 } 93 } 94