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

Commit fb88bc79 authored by Lyn's avatar Lyn
Browse files

Clear previousHunKey when removing last avalanche HUN

Fixes: 339345382
Test: AvalancheControllerTest
Test: adb logcat
Change-Id: Ia5795f77505da4a82bdab0e47c02955f2815a477
parent ca066bcd
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -249,22 +249,40 @@ class AvalancheControllerTest : SysuiTestCase() {


    @Test
    fun testDelete_showingEntryKeyBecomesPreviousHunKey() {
    fun testDelete_deleteSecondToLastEntry_showingEntryKeyBecomesPreviousHunKey() {
        mAvalancheController.previousHunKey = ""

        // Entry is showing
        val showingEntry = createHeadsUpEntry(id = 0)
        mAvalancheController.headsUpEntryShowing = showingEntry
        val firstEntry = createHeadsUpEntry(id = 0)
        mAvalancheController.headsUpEntryShowing = firstEntry

        // There's another entry waiting to show next
        val nextEntry = createHeadsUpEntry(id = 1)
        mAvalancheController.addToNext(nextEntry, runnableMock!!)
        val secondEntry = createHeadsUpEntry(id = 1)
        mAvalancheController.addToNext(secondEntry, runnableMock!!)

        // Delete
        mAvalancheController.delete(showingEntry, runnableMock, "testLabel")
        mAvalancheController.delete(firstEntry, runnableMock, "testLabel")

        // Next entry is shown
        assertThat(mAvalancheController.previousHunKey).isEqualTo(firstEntry.mEntry!!.key)
    }

    @Test
    fun testDelete_deleteLastEntry_previousHunKeyCleared() {
        mAvalancheController.previousHunKey = "key"

        // Nothing waiting to show
        mAvalancheController.clearNext()

        // One entry is showing
        val showingEntry = createHeadsUpEntry(id = 0)
        mAvalancheController.headsUpEntryShowing = showingEntry

        // Delete
        mAvalancheController.delete(showingEntry, runnableMock!!, "testLabel")

        // Next entry is shown
        assertThat(mAvalancheController.previousHunKey).isEqualTo(showingEntry.mEntry!!.key)
        assertThat(mAvalancheController.previousHunKey).isEqualTo("");
    }

    @Test
+1 −0
Original line number Diff line number Diff line
@@ -253,6 +253,7 @@ class AvalancheController @Inject constructor(

        if (nextList.isEmpty()) {
            log { "NO MORE TO SHOW" }
            previousHunKey = ""
            return
        }