Skip to content

Commit 848dcd5

Browse files
committed
fix(drawer): use bundle-storable keys for the account list
1 parent f69a9b0 commit 848dcd5

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

  • feature/navigation/drawer/dropdown/src
    • main/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/account
    • test/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/account

‎feature/navigation/drawer/dropdown/src/main/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/account/AccountList.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal fun AccountList(
2929
) {
3030
items(
3131
items = accounts,
32-
key = { account -> account.id },
32+
key = { account -> account.id.toString() },
3333
) { account ->
3434
AccountListItem(
3535
account = account,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.thunderbird.feature.navigation.drawer.dropdown.ui.account
2+
3+
import androidx.compose.ui.test.junit4.StateRestorationTester
4+
import app.k9mail.core.ui.compose.testing.ComposeTest
5+
import kotlin.test.Test
6+
import kotlinx.collections.immutable.persistentListOf
7+
import net.thunderbird.components.ui.bolt.theme.thunderbird.ThunderbirdBoltTheme
8+
import net.thunderbird.feature.navigation.drawer.dropdown.ui.FakeData
9+
10+
internal class AccountListKtTest : ComposeTest() {
11+
12+
@Test
13+
fun `account list state should survive being saved and restored`() {
14+
// Arrange
15+
val stateRestorationTester = StateRestorationTester(composeTestRule)
16+
stateRestorationTester.setContent {
17+
ThunderbirdBoltTheme {
18+
AccountList(
19+
accounts = persistentListOf(FakeData.MAIL_DISPLAY_ACCOUNT),
20+
selectedAccount = null,
21+
onAccountClick = {},
22+
showStarredCount = false,
23+
)
24+
}
25+
}
26+
27+
// Act: item keys must be storable in a Bundle, otherwise saving the list state crashes
28+
stateRestorationTester.emulateSavedInstanceStateRestore()
29+
}
30+
}

0 commit comments

Comments
 (0)