Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54a7debb authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Show ! on mobile triangle if the connection failed.

Fixes: 276884397
Test: atest MobileIconViewModelTest
Change-Id: Ic4928725a0b33dc39d78841825174a1e829ba2b4
parent f304ffc9
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.stateIn

/** Common interface for all of the location-based mobile icon view models. */
@@ -80,7 +79,12 @@ constructor(
) : MobileIconViewModelCommon {
    /** Whether or not to show the error state of [SignalDrawable] */
    private val showExclamationMark: Flow<Boolean> =
        iconInteractor.isDefaultDataEnabled.mapLatest { !it }
        combine(
            iconInteractor.isDefaultDataEnabled,
            iconInteractor.isDefaultConnectionFailed,
        ) { isDefaultDataEnabled, isDefaultConnectionFailed ->
            !isDefaultDataEnabled || isDefaultConnectionFailed
        }

    override val isVisible: StateFlow<Boolean> =
        if (!constants.hasDataCapabilities) {
+63 −9
Original line number Diff line number Diff line
@@ -179,15 +179,71 @@ class MobileIconViewModelTest : SysuiTestCase() {
        }

    @Test
    fun iconId_cutout_whenDefaultDataDisabled() =
    fun icon_usesLevelFromInteractor() =
        testScope.runTest {
            var latest: SignalIconModel? = null
            val job = underTest.icon.onEach { latest = it }.launchIn(this)

            interactor.level.value = 3
            assertThat(latest!!.level).isEqualTo(3)

            interactor.level.value = 1
            assertThat(latest!!.level).isEqualTo(1)

            job.cancel()
        }

    @Test
    fun icon_usesNumberOfLevelsFromInteractor() =
        testScope.runTest {
            var latest: SignalIconModel? = null
            val job = underTest.icon.onEach { latest = it }.launchIn(this)

            interactor.numberOfLevels.value = 5
            assertThat(latest!!.numberOfLevels).isEqualTo(5)

            interactor.numberOfLevels.value = 2
            assertThat(latest!!.numberOfLevels).isEqualTo(2)

            job.cancel()
        }

    @Test
    fun icon_defaultDataDisabled_showExclamationTrue() =
        testScope.runTest {
            interactor.setIsDefaultDataEnabled(false)

            var latest: SignalIconModel? = null
            val job = underTest.icon.onEach { latest = it }.launchIn(this)
            val expected = defaultSignal(level = 1, connected = false)

            assertThat(latest).isEqualTo(expected)
            assertThat(latest!!.showExclamationMark).isTrue()

            job.cancel()
        }

    @Test
    fun icon_defaultConnectionFailed_showExclamationTrue() =
        testScope.runTest {
            interactor.isDefaultConnectionFailed.value = true

            var latest: SignalIconModel? = null
            val job = underTest.icon.onEach { latest = it }.launchIn(this)

            assertThat(latest!!.showExclamationMark).isTrue()

            job.cancel()
        }

    @Test
    fun icon_enabledAndNotFailed_showExclamationFalse() =
        testScope.runTest {
            interactor.setIsDefaultDataEnabled(true)
            interactor.isDefaultConnectionFailed.value = false

            var latest: SignalIconModel? = null
            val job = underTest.icon.onEach { latest = it }.launchIn(this)

            assertThat(latest!!.showExclamationMark).isFalse()

            job.cancel()
        }
@@ -572,16 +628,14 @@ class MobileIconViewModelTest : SysuiTestCase() {

    companion object {
        private const val SUB_1_ID = 1
        private const val NUM_LEVELS = 4

        /** Convenience constructor for these tests */
        fun defaultSignal(
            level: Int = 1,
            connected: Boolean = true,
        ): SignalIconModel {
            return SignalIconModel(level, numberOfLevels = 4, showExclamationMark = !connected)
        fun defaultSignal(level: Int = 1): SignalIconModel {
            return SignalIconModel(level, NUM_LEVELS, showExclamationMark = false)
        }

        fun emptySignal(): SignalIconModel =
            SignalIconModel(level = 0, numberOfLevels = 4, showExclamationMark = true)
            SignalIconModel(level = 0, numberOfLevels = NUM_LEVELS, showExclamationMark = true)
    }
}