Repository: thunderbird/thunderbird-android (language: kotlin)

Issue:
Add account top view
Implement the account top view highlighted in this design:

![Image](https://github.com/user-attachments/assets/2deb4b6e-37f4-4d29-8721-28847601ab37)




Discussion hints:

Pull request: Add drawer account view
Add new drawer `AccountView`.

![AccountView](https://github.com/user-attachments/assets/a498675b-d92c-4871-a55c-f0c6b78208cb)

Resolves #8120 


Test command: ./gradlew :feature:navigation:drawer:testDebugUnitTest --tests "app.k9mail.feature.navigation.drawer.ui.DrawerViewModelTest"

Fix patch:
diff --git a/core/ui/compose/theme2/common/src/main/kotlin/app/k9mail/core/ui/compose/theme2/SelectThemeColorScheme.kt b/core/ui/compose/theme2/common/src/main/kotlin/app/k9mail/core/ui/compose/theme2/SelectThemeColorScheme.kt
index ee9b3519cba..d1f44da6d8a 100644
--- a/core/ui/compose/theme2/common/src/main/kotlin/app/k9mail/core/ui/compose/theme2/SelectThemeColorScheme.kt
+++ b/core/ui/compose/theme2/common/src/main/kotlin/app/k9mail/core/ui/compose/theme2/SelectThemeColorScheme.kt
@@ -113,4 +113,4 @@ private fun ColorScheme.toDynamicThemeColorScheme(
     )
 }
 
-private fun Color.toHarmonizedColor(target: Color) = Color(MaterialColors.harmonize(toArgb(), target.toArgb()))
+fun Color.toHarmonizedColor(target: Color) = Color(MaterialColors.harmonize(toArgb(), target.toArgb()))
diff --git a/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContentPreview.kt b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContentPreview.kt
index b3c598e25d3..0d377461317 100644
--- a/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContentPreview.kt
+++ b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContentPreview.kt
@@ -3,11 +3,30 @@ package app.k9mail.feature.navigation.drawer.ui
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.tooling.preview.Preview
 import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
+import app.k9mail.feature.navigation.drawer.ui.account.FakeData.DISPLAY_ACCOUNT
 
 @Composable
 @Preview(showBackground = true)
 internal fun DrawerContentPreview() {
     PreviewWithTheme {
-        DrawerContent()
+        DrawerContent(
+            state = DrawerContract.State(
+                accounts = emptyList(),
+                currentAccount = null,
+            ),
+        )
+    }
+}
+
+@Composable
+@Preview(showBackground = true)
+fun DrawerContentWithAccountPreview() {
+    PreviewWithTheme {
+        DrawerContent(
+            state = DrawerContract.State(
+                accounts = listOf(DISPLAY_ACCOUNT),
+                currentAccount = DISPLAY_ACCOUNT,
+            ),
+        )
     }
 }
diff --git a/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountIndicatorPreview.kt b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountIndicatorPreview.kt
new file mode 100644
index 00000000000..dd9930c2123
--- /dev/null
+++ b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountIndicatorPreview.kt
@@ -0,0 +1,43 @@
+package app.k9mail.feature.navigation.drawer.ui.account
+
+import androidx.compose.foundation.layout.height
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.tooling.preview.Preview
+import app.k9mail.core.ui.compose.designsystem.PreviewWithThemes
+import app.k9mail.core.ui.compose.theme2.MainTheme
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountIndicatorPreview() {
+    PreviewWithThemes {
+        AccountIndicator(
+            accountColor = 0,
+            modifier = Modifier.height(MainTheme.spacings.double),
+        )
+    }
+}
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountIndicatorPreviewWithYellowAccountColor() {
+    PreviewWithThemes {
+        AccountIndicator(
+            accountColor = Color.Yellow.toArgb(),
+            modifier = Modifier.height(MainTheme.spacings.double),
+        )
+    }
+}
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountIndicatorPreviewWithGrayAccountColor() {
+    PreviewWithThemes {
+        AccountIndicator(
+            accountColor = Color.Gray.toArgb(),
+            modifier = Modifier.height(MainTheme.spacings.double),
+        )
+    }
+}
diff --git a/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountViewPreview.kt b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountViewPreview.kt
new file mode 100644
index 00000000000..b268f894894
--- /dev/null
+++ b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountViewPreview.kt
@@ -0,0 +1,56 @@
+package app.k9mail.feature.navigation.drawer.ui.account
+
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.tooling.preview.Preview
+import app.k9mail.core.ui.compose.designsystem.PreviewWithThemes
+import app.k9mail.feature.navigation.drawer.ui.account.FakeData.DISPLAY_NAME
+import app.k9mail.feature.navigation.drawer.ui.account.FakeData.EMAIL_ADDRESS
+import app.k9mail.feature.navigation.drawer.ui.account.FakeData.LONG_TEXT
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountViewPreview() {
+    PreviewWithThemes {
+        AccountView(
+            displayName = DISPLAY_NAME,
+            emailAddress = EMAIL_ADDRESS,
+            accountColor = 0,
+        )
+    }
+}
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountViewWithColorPreview() {
+    PreviewWithThemes {
+        AccountView(
+            displayName = DISPLAY_NAME,
+            emailAddress = EMAIL_ADDRESS,
+            accountColor = 0xFF0000,
+        )
+    }
+}
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountViewWithLongDisplayName() {
+    PreviewWithThemes {
+        AccountView(
+            displayName = "$LONG_TEXT $DISPLAY_NAME",
+            emailAddress = EMAIL_ADDRESS,
+            accountColor = 0,
+        )
+    }
+}
+
+@Composable
+@Preview(showBackground = true)
+internal fun AccountViewWithLongEmailPreview() {
+    PreviewWithThemes {
+        AccountView(
+            displayName = DISPLAY_NAME,
+            emailAddress = "$LONG_TEXT@example.com",
+            accountColor = 0,
+        )
+    }
+}
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt
index 0c17eb6c327..edb1f961952 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt
@@ -39,5 +39,9 @@ val navigationDrawerModule: Module = module {
         )
     }
 
-    viewModel { DrawerViewModel() }
+    viewModel {
+        DrawerViewModel(
+            getDisplayAccounts = get(),
+        )
+    }
 }
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt
index 61d6fcc9bd1..dec8f13f825 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt
@@ -7,7 +7,7 @@ interface DomainContract {
 
     interface UseCase {
         fun interface GetDisplayAccounts {
-            fun execute(): Flow<List<DisplayAccount>>
+            operator fun invoke(): Flow<List<DisplayAccount>>
         }
     }
 }
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/GetDisplayAccounts.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/GetDisplayAccounts.kt
index 7327e90c478..17e1435a003 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/GetDisplayAccounts.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/GetDisplayAccounts.kt
@@ -27,7 +27,7 @@ class GetDisplayAccounts(
 ) : UseCase.GetDisplayAccounts {
 
     @OptIn(ExperimentalCoroutinesApi::class)
-    override fun execute(): Flow<List<DisplayAccount>> {
+    override fun invoke(): Flow<List<DisplayAccount>> {
         return accountManager.getAccountsFlow()
             .flatMapLatest { accounts ->
                 val messageCountsFlows: List<Flow<MessageCounts>> = accounts.map { account ->
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/legacy/AccountsViewModel.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/legacy/AccountsViewModel.kt
index ca630d6baba..351a9107d0c 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/legacy/AccountsViewModel.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/legacy/AccountsViewModel.kt
@@ -9,5 +9,5 @@ import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
 class AccountsViewModel(
     getDisplayAccounts: UseCase.GetDisplayAccounts,
 ) : ViewModel() {
-    val displayAccountsLiveData: LiveData<List<DisplayAccount>> = getDisplayAccounts.execute().asLiveData()
+    val displayAccountsLiveData: LiveData<List<DisplayAccount>> = getDisplayAccounts().asLiveData()
 }
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContent.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContent.kt
index b0319911310..fd765cacfee 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContent.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContent.kt
@@ -1,17 +1,23 @@
 package app.k9mail.feature.navigation.drawer.ui
 
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.fillMaxSize
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.lazy.LazyColumn
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.platform.testTag
+import app.k9mail.core.ui.compose.designsystem.atom.DividerHorizontal
 import app.k9mail.core.ui.compose.designsystem.atom.Surface
 import app.k9mail.core.ui.compose.designsystem.organism.drawer.NavigationDrawerItem
 import app.k9mail.core.ui.compose.theme2.MainTheme
+import app.k9mail.feature.navigation.drawer.ui.DrawerContract.State
+import app.k9mail.feature.navigation.drawer.ui.account.AccountView
 
 @Composable
 fun DrawerContent(
+    state: State,
     modifier: Modifier = Modifier,
 ) {
     Surface(
@@ -19,33 +25,48 @@ fun DrawerContent(
             .fillMaxSize()
             .testTag("DrawerContent"),
     ) {
-        LazyColumn(
+        Column(
             modifier = Modifier
                 .fillMaxSize()
                 .padding(
                     vertical = MainTheme.spacings.oneHalf,
                 ),
+            verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.default),
         ) {
-            item {
-                NavigationDrawerItem(
-                    label = "Folder1",
-                    selected = true,
-                    onClick = {},
-                )
-            }
-            item {
-                NavigationDrawerItem(
-                    label = "Folder2",
-                    selected = false,
-                    onClick = {},
+            state.currentAccount?.let {
+                AccountView(
+                    displayName = it.account.displayName,
+                    emailAddress = it.account.email,
+                    accountColor = it.account.chipColor,
                 )
+
+                DividerHorizontal()
             }
-            item {
-                NavigationDrawerItem(
-                    label = "Folder3",
-                    selected = false,
-                    onClick = {},
-                )
+            LazyColumn(
+                modifier = Modifier
+                    .fillMaxSize(),
+            ) {
+                item {
+                    NavigationDrawerItem(
+                        label = "Folder1",
+                        selected = true,
+                        onClick = {},
+                    )
+                }
+                item {
+                    NavigationDrawerItem(
+                        label = "Folder2",
+                        selected = false,
+                        onClick = {},
+                    )
+                }
+                item {
+                    NavigationDrawerItem(
+                        label = "Folder3",
+                        selected = false,
+                        onClick = {},
+                    )
+                }
             }
         }
     }
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContract.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContract.kt
index d06a981cd02..3f1cf11f9e8 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContract.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContract.kt
@@ -1,12 +1,15 @@
 package app.k9mail.feature.navigation.drawer.ui
 
 import app.k9mail.core.ui.compose.common.mvi.UnidirectionalViewModel
+import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
 
 interface DrawerContract {
 
     interface ViewModel : UnidirectionalViewModel<State, Event, Effect>
 
     data class State(
+        val currentAccount: DisplayAccount? = null,
+        val accounts: List<DisplayAccount> = emptyList(),
         val isLoading: Boolean = false,
     )
 
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerView.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerView.kt
index 22411299d59..01a4b5b6ce0 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerView.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerView.kt
@@ -15,6 +15,8 @@ fun DrawerView(
         isRefreshing = state.value.isLoading,
         onRefresh = { dispatch(DrawerContract.Event.OnRefresh) },
     ) {
-        DrawerContent()
+        DrawerContent(
+            state = state.value,
+        )
     }
 }
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModel.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModel.kt
index 945e20eac8e..65b43bb4740 100644
--- a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModel.kt
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModel.kt
@@ -2,6 +2,8 @@ package app.k9mail.feature.navigation.drawer.ui
 
 import androidx.lifecycle.viewModelScope
 import app.k9mail.core.ui.compose.common.mvi.BaseViewModel
+import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase
+import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
 import app.k9mail.feature.navigation.drawer.ui.DrawerContract.Effect
 import app.k9mail.feature.navigation.drawer.ui.DrawerContract.Event
 import app.k9mail.feature.navigation.drawer.ui.DrawerContract.State
@@ -11,12 +13,35 @@ import kotlinx.coroutines.launch
 
 @Suppress("MagicNumber")
 class DrawerViewModel(
+    private val getDisplayAccounts: UseCase.GetDisplayAccounts,
     initialState: State = State(),
 ) : BaseViewModel<State, Event, Effect>(
     initialState = initialState,
 ),
     ViewModel {
 
+    init {
+        viewModelScope.launch {
+            getDisplayAccounts().collect { accounts -> updateAccounts(accounts) }
+        }
+    }
+
+    private fun updateAccounts(accounts: List<DisplayAccount>) {
+        val currentAccountUuid = state.value.currentAccount?.account?.uuid
+        val isCurrentAccountAvailable = accounts.any { currentAccountUuid == it.account.uuid }
+
+        updateState {
+            if (isCurrentAccountAvailable) {
+                it.copy(accounts = accounts)
+            } else {
+                it.copy(
+                    currentAccount = accounts.firstOrNull(),
+                    accounts = accounts,
+                )
+            }
+        }
+    }
+
     override fun event(event: Event) {
         when (event) {
             Event.OnRefresh -> refresh()
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountIndicator.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountIndicator.kt
new file mode 100644
index 00000000000..fadd7734756
--- /dev/null
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountIndicator.kt
@@ -0,0 +1,32 @@
+package app.k9mail.feature.navigation.drawer.ui.account
+
+import androidx.compose.foundation.layout.defaultMinSize
+import androidx.compose.foundation.layout.width
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import app.k9mail.core.ui.compose.designsystem.atom.Surface
+import app.k9mail.core.ui.compose.theme2.MainTheme
+import app.k9mail.core.ui.compose.theme2.toHarmonizedColor
+
+@Composable
+fun AccountIndicator(
+    accountColor: Int,
+    modifier: Modifier = Modifier,
+) {
+    val color = if (accountColor == 0) {
+        MainTheme.colors.primary
+    } else {
+        Color(accountColor).toHarmonizedColor(MainTheme.colors.surface)
+    }
+
+    Surface(
+        modifier = modifier
+            .width(MainTheme.spacings.half)
+            .defaultMinSize(
+                minHeight = MainTheme.spacings.default,
+            ),
+        color = color,
+        shape = MainTheme.shapes.medium,
+    ) {}
+}
diff --git a/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountView.kt b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountView.kt
new file mode 100644
index 00000000000..d4d16d78894
--- /dev/null
+++ b/feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/account/AccountView.kt
@@ -0,0 +1,58 @@
+package app.k9mail.feature.navigation.drawer.ui.account
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.IntrinsicSize
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyLarge
+import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyMedium
+import app.k9mail.core.ui.compose.theme2.MainTheme
+
+@Composable
+fun AccountView(
+    displayName: String,
+    emailAddress: String,
+    accountColor: Int,
+    modifier: Modifier = Modifier,
+) {
+    Row(
+        modifier = modifier
+            .fillMaxWidth()
+            .height(intrinsicSize = IntrinsicSize.Max)
+            .padding(
+                top = MainTheme.spacings.default,
+                start = MainTheme.spacings.double,
+                end = MainTheme.spacings.triple,
+                bottom = MainTheme.spacings.oneHalf,
+            ),
+        verticalAlignment = Alignment.CenterVertically,
+    ) {
+        AccountIndicator(
+            accountColor = accountColor,
+            modifier = Modifier
+                .fillMaxHeight()
+                .padding(
+                    end = MainTheme.spacings.default,
+                ),
+        )
+        Column(
+            verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.half),
+        ) {
+            TextBodyLarge(
+                text = displayName,
+                color = MainTheme.colors.onSurface,
+            )
+            TextBodyMedium(
+                text = emailAddress,
+                color = MainTheme.colors.onSurfaceVariant,
+            )
+        }
+    }
+}


Test patch:
diff --git a/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/FakeData.kt b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/FakeData.kt
new file mode 100644
index 00000000000..3bcbd017480
--- /dev/null
+++ b/feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/account/FakeData.kt
@@ -0,0 +1,37 @@
+package app.k9mail.feature.navigation.drawer.ui.account
+
+import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
+import app.k9mail.legacy.account.Account
+import app.k9mail.legacy.account.Identity
+
+internal object FakeData {
+
+    const val ACCOUNT_UUID = "uuid"
+    const val DISPLAY_NAME = "Account Name"
+    const val EMAIL_ADDRESS = "test@example.com"
+
+    const val LONG_TEXT = "loremipsumdolorsitametconsetetursadipscingelitr" +
+        "seddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiamvoluptua"
+
+    val ACCOUNT = Account(
+        uuid = ACCOUNT_UUID,
+    ).apply {
+        identities = ArrayList()
+
+        val identity = Identity(
+            signatureUse = false,
+            signature = "",
+            description = "",
+        )
+        identities.add(identity)
+
+        name = DISPLAY_NAME
+        email = EMAIL_ADDRESS
+    }
+
+    val DISPLAY_ACCOUNT = DisplayAccount(
+        account = ACCOUNT,
+        unreadMessageCount = 0,
+        starredMessageCount = 0,
+    )
+}
diff --git a/feature/navigation/drawer/src/test/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModelTest.kt b/feature/navigation/drawer/src/test/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModelTest.kt
index a0f39c6bfab..c1d0725bc4f 100644
--- a/feature/navigation/drawer/src/test/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModelTest.kt
+++ b/feature/navigation/drawer/src/test/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModelTest.kt
@@ -2,12 +2,18 @@ package app.k9mail.feature.navigation.drawer.ui
 
 import app.k9mail.core.ui.compose.testing.MainDispatcherRule
 import app.k9mail.core.ui.compose.testing.mvi.eventStateTest
+import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
 import app.k9mail.feature.navigation.drawer.ui.DrawerContract.Event
 import app.k9mail.feature.navigation.drawer.ui.DrawerContract.State
+import app.k9mail.legacy.account.Account
+import app.k9mail.legacy.account.Identity
 import assertk.assertThat
 import assertk.assertions.isEqualTo
 import kotlin.test.Test
 import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.flow
 import kotlinx.coroutines.test.advanceUntilIdle
 import kotlinx.coroutines.test.runTest
 import org.junit.Rule
@@ -18,10 +24,10 @@ class DrawerViewModelTest {
     @get:Rule
     val mainDispatcherRule = MainDispatcherRule()
 
-    private val testSubject = DrawerViewModel()
-
     @Test
     fun `should change loading state when OnRefresh event is received`() = runTest {
+        val testSubject = createTestSubject()
+
         eventStateTest(
             viewModel = testSubject,
             initialState = State(isLoading = false),
@@ -34,4 +40,98 @@ class DrawerViewModelTest {
 
         assertThat(testSubject.state.value.isLoading).isEqualTo(false)
     }
+
+    @Test
+    fun `should collect display accounts when created and select first as current`() = runTest {
+        val displayAccounts = createDisplayAccountList(3)
+        val getDisplayAccountsFlow = MutableStateFlow(displayAccounts)
+        val testSubject = createTestSubject(
+            getDisplayAccountsFlow = getDisplayAccountsFlow,
+        )
+
+        advanceUntilIdle()
+
+        assertThat(testSubject.state.value.accounts.size).isEqualTo(displayAccounts.size)
+        assertThat(testSubject.state.value.accounts).isEqualTo(displayAccounts)
+        assertThat(testSubject.state.value.currentAccount).isEqualTo(displayAccounts.first())
+    }
+
+    @Test
+    fun `should reselect current account when old not present anymore`() = runTest {
+        val displayAccounts = createDisplayAccountList(3)
+        val getDisplayAccountsFlow = MutableStateFlow(displayAccounts)
+        val testSubject = createTestSubject(
+            getDisplayAccountsFlow = getDisplayAccountsFlow,
+        )
+
+        advanceUntilIdle()
+
+        val newDisplayAccounts = displayAccounts.drop(1)
+        getDisplayAccountsFlow.emit(newDisplayAccounts)
+
+        advanceUntilIdle()
+
+        assertThat(testSubject.state.value.accounts.size).isEqualTo(newDisplayAccounts.size)
+        assertThat(testSubject.state.value.accounts).isEqualTo(newDisplayAccounts)
+        assertThat(testSubject.state.value.currentAccount).isEqualTo(newDisplayAccounts.first())
+    }
+
+    @Test
+    fun `should set current account to null when no accounts are present`() = runTest {
+        val getDisplayAccountsFlow = MutableStateFlow(emptyList<DisplayAccount>())
+        val testSubject = createTestSubject(
+            getDisplayAccountsFlow = getDisplayAccountsFlow,
+        )
+
+        advanceUntilIdle()
+
+        assertThat(testSubject.state.value.accounts.size).isEqualTo(0)
+        assertThat(testSubject.state.value.currentAccount).isEqualTo(null)
+    }
+
+    private fun createTestSubject(
+        getDisplayAccountsFlow: Flow<List<DisplayAccount>> = flow { emit(emptyList()) },
+    ): DrawerViewModel {
+        return DrawerViewModel(
+            getDisplayAccounts = { getDisplayAccountsFlow },
+        )
+    }
+
+    private fun createDisplayAccount(
+        uuid: String = "uuid",
+        name: String = "name",
+        email: String = "test@example.com",
+        unreadCount: Int = 0,
+        starredCount: Int = 0,
+    ): DisplayAccount {
+        val account = Account(
+            uuid = uuid,
+        ).also {
+            it.identities = ArrayList()
+
+            val identity = Identity(
+                signatureUse = false,
+                signature = "",
+                description = "",
+            )
+            it.identities.add(identity)
+
+            it.name = name
+            it.email = email
+        }
+
+        return DisplayAccount(
+            account = account,
+            unreadMessageCount = unreadCount,
+            starredMessageCount = starredCount,
+        )
+    }
+
+    private fun createDisplayAccountList(count: Int): List<DisplayAccount> {
+        return List(count) { index ->
+            createDisplayAccount(
+                uuid = "uuid-$index",
+            )
+        }
+    }
 }