From 1c142876d0f63df09999a45d33338233f0bbf590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montwe=CC=81?= Date: Tue, 27 Jun 2023 18:58:16 +0200 Subject: [PATCH] Add AccountOptions and state mapper --- .../com/fsck/k9/account/AccountCreator.kt | 2 +- .../account/setup/domain/entity/Account.kt | 2 +- .../setup/domain/entity/AccountOptions.kt | 10 +++++ .../ui/options/AccountOptionsStateMapper.kt | 14 +++++++ .../AccountOptionsStateMapperKtTest.kt | 37 +++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AccountOptions.kt create mode 100644 feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapper.kt create mode 100644 feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapperKtTest.kt diff --git a/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt b/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt index d6959deda..c343866c3 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt @@ -18,11 +18,11 @@ class AccountCreator( val newAccount = preferences.newAccount() newAccount.email = account.emailAddress - newAccount.senderName = account.senderName newAccount.incomingServerSettings = account.incomingServerSettings newAccount.outgoingServerSettings = account.outgoingServerSettings + newAccount.senderName = account.options.accountName newAccount.deletePolicy = accountCreatorHelper.getDefaultDeletePolicy(newAccount.incomingServerSettings.type) newAccount.chipColor = accountCreatorHelper.pickColor() diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/Account.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/Account.kt index f97c12452..8eb90c170 100644 --- a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/Account.kt +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/Account.kt @@ -6,5 +6,5 @@ data class Account( val emailAddress: String, val incomingServerSettings: ServerSettings, val outgoingServerSettings: ServerSettings, - val senderName: String, + val options: AccountOptions, ) diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AccountOptions.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AccountOptions.kt new file mode 100644 index 000000000..403af527a --- /dev/null +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/domain/entity/AccountOptions.kt @@ -0,0 +1,10 @@ +package app.k9mail.feature.account.setup.domain.entity + +data class AccountOptions( + val accountName: String, + val displayName: String, + val emailSignature: String?, + val checkFrequencyInMinutes: Int, + val messageDisplayCount: Int, + val showNotification: Boolean, +) diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapper.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapper.kt new file mode 100644 index 000000000..623f7dc52 --- /dev/null +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapper.kt @@ -0,0 +1,14 @@ +package app.k9mail.feature.account.setup.ui.options + +import app.k9mail.feature.account.setup.domain.entity.AccountOptions + +internal fun AccountOptionsContract.State.toAccountOptions(): AccountOptions { + return AccountOptions( + accountName = accountName.value, + displayName = displayName.value, + emailSignature = emailSignature.value, + checkFrequencyInMinutes = checkFrequency.minutes, + messageDisplayCount = messageDisplayCount.count, + showNotification = showNotification, + ) +} diff --git a/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapperKtTest.kt b/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapperKtTest.kt new file mode 100644 index 000000000..30fe41939 --- /dev/null +++ b/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/options/AccountOptionsStateMapperKtTest.kt @@ -0,0 +1,37 @@ +package app.k9mail.feature.account.setup.ui.options + +import app.k9mail.feature.account.setup.domain.entity.AccountOptions +import app.k9mail.feature.account.setup.domain.entity.EmailCheckFrequency +import app.k9mail.feature.account.setup.domain.entity.EmailDisplayCount +import app.k9mail.feature.account.setup.domain.input.StringInputField +import assertk.assertThat +import assertk.assertions.isEqualTo +import org.junit.Test + +class AccountOptionsStateMapperKtTest { + + @Test + fun `should map state to account options`() { + val state = AccountOptionsContract.State( + accountName = StringInputField("accountName"), + displayName = StringInputField("displayName"), + emailSignature = StringInputField("emailSignature"), + checkFrequency = EmailCheckFrequency.EVERY_2_HOURS, + messageDisplayCount = EmailDisplayCount.MESSAGES_100, + showNotification = true, + ) + + val result = state.toAccountOptions() + + assertThat(result).isEqualTo( + AccountOptions( + accountName = "accountName", + displayName = "displayName", + emailSignature = "emailSignature", + checkFrequencyInMinutes = 120, + messageDisplayCount = 100, + showNotification = true, + ), + ) + } +}