-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8541 from shamim-emon/fix-issue-8531
Fix of "QR code import does not update unified inbox"
- Loading branch information
Showing
6 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
legacy/core/src/main/java/com/fsck/k9/preferences/UnifiedInboxConfigurator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.fsck.k9.preferences | ||
|
||
import app.k9mail.legacy.account.AccountManager | ||
import com.fsck.k9.K9 | ||
|
||
/** | ||
* Configures the unified inbox after an account has been added. | ||
*/ | ||
class UnifiedInboxConfigurator( | ||
private val accountManager: AccountManager, | ||
) { | ||
fun configureUnifiedInbox() { | ||
if (accountManager.getAccounts().size > 1) { | ||
K9.isShowUnifiedInbox = true | ||
K9.saveSettingsAsync() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.fsck.k9.preferences | ||
|
||
import app.k9mail.legacy.di.DI.get | ||
import assertk.all | ||
import assertk.assertFailure | ||
import assertk.assertThat | ||
|
@@ -16,10 +17,23 @@ import com.fsck.k9.Preferences | |
import java.util.UUID | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.koin.test.inject | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.times | ||
import org.mockito.kotlin.verify | ||
|
||
class SettingsImporterTest : K9RobolectricTest() { | ||
private val settingsImporter: SettingsImporter by inject() | ||
private val unifiedInboxConfigurator = mock<UnifiedInboxConfigurator>() | ||
private val settingsImporter = SettingsImporter( | ||
settingsFileParser = get(), | ||
generalSettingsValidator = get(), | ||
accountSettingsValidator = get(), | ||
generalSettingsUpgrader = get(), | ||
accountSettingsWriter = get(), | ||
accountSettingsUpgrader = get(), | ||
generalSettingsWriter = get(), | ||
unifiedInboxConfigurator = unifiedInboxConfigurator, | ||
) | ||
|
||
@Before | ||
fun before() { | ||
|
@@ -154,6 +168,93 @@ class SettingsImporterTest : K9RobolectricTest() { | |
} | ||
} | ||
|
||
@Test | ||
fun `importSettings() configures unifiedInbox when globalSettingsImported is false`() { | ||
val accountUuid = UUID.randomUUID().toString() | ||
val inputStream = | ||
""" | ||
<k9settings format="1" version="1"> | ||
<accounts> | ||
<account uuid="$accountUuid"> | ||
<name>Account</name> | ||
<incoming-server type="IMAP"> | ||
<connection-security>SSL_TLS_REQUIRED</connection-security> | ||
<username>[email protected]</username> | ||
<authentication-type>CRAM_MD5</authentication-type> | ||
<host>googlemail.com</host> | ||
</incoming-server> | ||
<outgoing-server type="SMTP"> | ||
<connection-security>SSL_TLS_REQUIRED</connection-security> | ||
<username>[email protected]</username> | ||
<authentication-type>CRAM_MD5</authentication-type> | ||
<host>googlemail.com</host> | ||
</outgoing-server> | ||
<settings> | ||
<value key="a">b</value> | ||
</settings> | ||
<identities> | ||
<identity> | ||
<email>[email protected]</email> | ||
</identity> | ||
</identities> | ||
</account> | ||
</accounts> | ||
</k9settings> | ||
""".trimIndent().byteInputStream() | ||
val accountUuids = listOf("uuid-1") | ||
|
||
val results = settingsImporter.importSettings(inputStream, globalSettings = false, accountUuids) | ||
|
||
assertThat(results.globalSettings).isFalse() | ||
verify(unifiedInboxConfigurator, times(1)).configureUnifiedInbox() | ||
} | ||
|
||
@Test | ||
fun `importSettings() does not not configure unifiedInbox when globalSettingsImported is true`() { | ||
val accountUuid = UUID.randomUUID().toString() | ||
val inputStream = | ||
""" | ||
<k9settings format="1" version="101"> | ||
<global> | ||
<value key="confirmDelete">false</value> | ||
<value key="changeRegisteredNameColor">false</value> | ||
<value key="confirmSpam">false</value> | ||
</global> | ||
<accounts> | ||
<account uuid="$accountUuid"> | ||
<name>Account</name> | ||
<incoming-server type="IMAP"> | ||
<connection-security>SSL_TLS_REQUIRED</connection-security> | ||
<username>[email protected]</username> | ||
<authentication-type>CRAM_MD5</authentication-type> | ||
<host>googlemail.com</host> | ||
</incoming-server> | ||
<outgoing-server type="SMTP"> | ||
<connection-security>SSL_TLS_REQUIRED</connection-security> | ||
<username>[email protected]</username> | ||
<authentication-type>CRAM_MD5</authentication-type> | ||
<host>googlemail.com</host> | ||
</outgoing-server> | ||
<settings> | ||
<value key="a">b</value> | ||
</settings> | ||
<identities> | ||
<identity> | ||
<email>[email protected]</email> | ||
</identity> | ||
</identities> | ||
</account> | ||
</accounts> | ||
</k9settings> | ||
""".trimIndent().byteInputStream() | ||
val accountUuids = listOf("uuid-1") | ||
|
||
val results = settingsImporter.importSettings(inputStream, globalSettings = true, accountUuids) | ||
|
||
assertThat(results.globalSettings).isTrue() | ||
verify(unifiedInboxConfigurator, never()).configureUnifiedInbox() | ||
} | ||
|
||
@Test | ||
fun `getImportStreamContents() should return list of accounts`() { | ||
val accountUuid = UUID.randomUUID().toString() | ||
|