Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/composefragment/viewmodel/AbstractQSFragmentComposeViewModelTest.kt +9 −5 Original line number Diff line number Diff line Loading @@ -16,11 +16,13 @@ package com.android.systemui.qs.composefragment.viewmodel import androidx.compose.runtime.snapshots.Snapshot import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.testing.TestLifecycleOwner import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.lifecycle.activateIn Loading @@ -36,7 +38,6 @@ import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.junit.After import org.junit.Before import org.junit.runner.RunWith Loading @@ -58,11 +59,14 @@ abstract class AbstractQSFragmentComposeViewModelTest : SysuiTestCase() { @Before fun setUp() { Dispatchers.setMain(kosmos.testDispatcher) } onTeardown { Dispatchers.resetMain() } @After fun teardown() { Dispatchers.resetMain() val globalWriteObserverHandle = Snapshot.registerGlobalWriteObserver { Snapshot.sendApplyNotifications() kosmos.runCurrent() } onTeardown { globalWriteObserverHandle.dispose() } } protected inline fun TestScope.testWithinLifecycle( Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/composefragment/viewmodel/QSFragmentComposeViewModelTest.kt +0 −27 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.app.StatusBarManager import android.content.testableContext import android.graphics.Rect import android.testing.TestableLooper.RunWithLooper import androidx.compose.runtime.snapshots.Snapshot import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository Loading Loading @@ -186,15 +185,12 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() val squishiness by collectLastValue(tileSquishinessInteractor.squishiness) underTest.squishinessFraction = 0.3f Snapshot.sendApplyNotifications() assertThat(squishiness).isWithin(epsilon).of(0.3f.constrainSquishiness()) underTest.squishinessFraction = 0f Snapshot.sendApplyNotifications() assertThat(squishiness).isWithin(epsilon).of(0f.constrainSquishiness()) underTest.squishinessFraction = 1f Snapshot.sendApplyNotifications() assertThat(squishiness).isWithin(epsilon).of(1f.constrainSquishiness()) } } Loading Loading @@ -328,13 +324,9 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setConfigurationForMediaInRow(mediaInRow = false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) setConfigurationForMediaInRow(mediaInRow = true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.COLLAPSED) } } Loading @@ -347,13 +339,9 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setConfigurationForMediaInRow(mediaInRow = false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) setConfigurationForMediaInRow(mediaInRow = true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) } } Loading @@ -366,13 +354,9 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setCollapsedMediaInLandscape(false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) setCollapsedMediaInLandscape(true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.COLLAPSED) } } Loading Loading @@ -401,13 +385,11 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() underTest.squishinessFraction = 0.3f underTest.shouldUpdateSquishinessOnMedia = true Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(0.01f).of(0.3f) underTest.shouldUpdateSquishinessOnMedia = false Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(0.01f).of(1f) } Loading @@ -421,20 +403,15 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() underTest.squishinessFraction = 0.3f sysuiStatusBarStateController.setState(StatusBarState.SHADE) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(epsilon).of(0.3f) sysuiStatusBarStateController.setState(StatusBarState.KEYGUARD) runCurrent() Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(epsilon).of(1f) sysuiStatusBarStateController.setState(StatusBarState.SHADE_LOCKED) runCurrent() Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(epsilon).of(1f) } } Loading @@ -446,8 +423,6 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setConfigurationForMediaInRow(false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.disappearParameters) .isEqualTo(disappearParamsColumn) Loading @@ -455,8 +430,6 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() .isEqualTo(disappearParamsColumn) setConfigurationForMediaInRow(true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.disappearParameters).isEqualTo(disappearParamsRow) assertThat(underTest.qsMediaHost.disappearParameters).isEqualTo(disappearParamsRow) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/composefragment/viewmodel/AbstractQSFragmentComposeViewModelTest.kt +9 −5 Original line number Diff line number Diff line Loading @@ -16,11 +16,13 @@ package com.android.systemui.qs.composefragment.viewmodel import androidx.compose.runtime.snapshots.Snapshot import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.testing.TestLifecycleOwner import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.lifecycle.activateIn Loading @@ -36,7 +38,6 @@ import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.junit.After import org.junit.Before import org.junit.runner.RunWith Loading @@ -58,11 +59,14 @@ abstract class AbstractQSFragmentComposeViewModelTest : SysuiTestCase() { @Before fun setUp() { Dispatchers.setMain(kosmos.testDispatcher) } onTeardown { Dispatchers.resetMain() } @After fun teardown() { Dispatchers.resetMain() val globalWriteObserverHandle = Snapshot.registerGlobalWriteObserver { Snapshot.sendApplyNotifications() kosmos.runCurrent() } onTeardown { globalWriteObserverHandle.dispose() } } protected inline fun TestScope.testWithinLifecycle( Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/composefragment/viewmodel/QSFragmentComposeViewModelTest.kt +0 −27 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.app.StatusBarManager import android.content.testableContext import android.graphics.Rect import android.testing.TestableLooper.RunWithLooper import androidx.compose.runtime.snapshots.Snapshot import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository Loading Loading @@ -186,15 +185,12 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() val squishiness by collectLastValue(tileSquishinessInteractor.squishiness) underTest.squishinessFraction = 0.3f Snapshot.sendApplyNotifications() assertThat(squishiness).isWithin(epsilon).of(0.3f.constrainSquishiness()) underTest.squishinessFraction = 0f Snapshot.sendApplyNotifications() assertThat(squishiness).isWithin(epsilon).of(0f.constrainSquishiness()) underTest.squishinessFraction = 1f Snapshot.sendApplyNotifications() assertThat(squishiness).isWithin(epsilon).of(1f.constrainSquishiness()) } } Loading Loading @@ -328,13 +324,9 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setConfigurationForMediaInRow(mediaInRow = false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) setConfigurationForMediaInRow(mediaInRow = true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.COLLAPSED) } } Loading @@ -347,13 +339,9 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setConfigurationForMediaInRow(mediaInRow = false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) setConfigurationForMediaInRow(mediaInRow = true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) } } Loading @@ -366,13 +354,9 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setCollapsedMediaInLandscape(false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.EXPANDED) setCollapsedMediaInLandscape(true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.expansion).isEqualTo(MediaHostState.COLLAPSED) } } Loading Loading @@ -401,13 +385,11 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() underTest.squishinessFraction = 0.3f underTest.shouldUpdateSquishinessOnMedia = true Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(0.01f).of(0.3f) underTest.shouldUpdateSquishinessOnMedia = false Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(0.01f).of(1f) } Loading @@ -421,20 +403,15 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() underTest.squishinessFraction = 0.3f sysuiStatusBarStateController.setState(StatusBarState.SHADE) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(epsilon).of(0.3f) sysuiStatusBarStateController.setState(StatusBarState.KEYGUARD) runCurrent() Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(epsilon).of(1f) sysuiStatusBarStateController.setState(StatusBarState.SHADE_LOCKED) runCurrent() Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qsMediaHost.squishFraction).isWithin(epsilon).of(1f) } } Loading @@ -446,8 +423,6 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() setMediaState(ACTIVE_MEDIA) setConfigurationForMediaInRow(false) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.disappearParameters) .isEqualTo(disappearParamsColumn) Loading @@ -455,8 +430,6 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest() .isEqualTo(disappearParamsColumn) setConfigurationForMediaInRow(true) Snapshot.sendApplyNotifications() runCurrent() assertThat(underTest.qqsMediaHost.disappearParameters).isEqualTo(disappearParamsRow) assertThat(underTest.qsMediaHost.disappearParameters).isEqualTo(disappearParamsRow) Loading