Skip to content

Commit

Permalink
Issue 2712 add email signatures support (#2769)
Browse files Browse the repository at this point in the history
* Updated AccountAliasesEntity.| #2712

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Added UpdateSignatureDialogFragment.| #2712

* Added appending a signature to outgoing messages.| #2712

* wip

* wip

* wip

* wip

* wip

* Added some tests.| #2712

* Added some tests for Gmail API.| #2712

* Added some tests.| #2712

* Fixed the database migration.| #2712

* Fixed lint warnings.| #2712
  • Loading branch information
DenBond7 authored Jun 25, 2024
1 parent 59c3ec0 commit fa28437
Show file tree
Hide file tree
Showing 44 changed files with 3,134 additions and 190 deletions.
1,200 changes: 1,200 additions & 0 deletions FlowCrypt/schemas/com.flowcrypt.email.database.FlowCryptRoomDatabase/45.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MigrationTest {
FlowCryptRoomDatabase.MIGRATION_41_42,
FlowCryptRoomDatabase.Migration42to43(InstrumentationRegistry.getInstrumentation().targetContext),
FlowCryptRoomDatabase.MIGRATION_43_44,
FlowCryptRoomDatabase.MIGRATION_44_45,
)

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ package com.flowcrypt.email.rules

import com.flowcrypt.email.database.FlowCryptRoomDatabase
import com.flowcrypt.email.database.entity.AccountAliasesEntity
import kotlinx.coroutines.runBlocking

/**
* @author Denys Bondarenko
*/
class AddAccountAliasToDatabaseRule constructor(val alias: AccountAliasesEntity) : BaseRule() {
class AddAccountAliasToDatabaseRule(private val aliases: List<AccountAliasesEntity>) : BaseRule() {
override fun execute() {
saveAliasToDatabase()
}

private fun saveAliasToDatabase() {
FlowCryptRoomDatabase.getDatabase(targetContext).accountAliasesDao().insert(alias)
runBlocking {
FlowCryptRoomDatabase.getDatabase(targetContext).accountAliasesDao()
.insertSuspend(aliases)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui


import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.model.MessageType
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.GrantPermissionRuleChooser
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.fragment.CreateMessageFragmentArgs
import com.flowcrypt.email.ui.base.BaseComposeScreenWithCustomSignatureFlowTest
import org.hamcrest.core.StringStartsWith
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denys Bondarenko
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class ComposeScreenForwardWithCustomSignatureFlowTest :
BaseComposeScreenWithCustomSignatureFlowTest() {
override val createMessageFragmentArgs: CreateMessageFragmentArgs
get() = CreateMessageFragmentArgs(
incomingMessageInfo = getMsgInfo(
path = "messages/info/standard_msg_reply_to_header.json",
mimeMsgPath = "messages/mime/standard_msg_reply_to_header.txt",
accountEntity = BASE_ADD_ACCOUNT_RULE.apply { execute() }.accountEntityWithDecryptedInfo
),
encryptedByDefault = false,
messageType = MessageType.FORWARD
)

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(RetryRule.DEFAULT)
.around(ClearAppSettingsRule())
.around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS))
.around(addAccountToDatabaseRule)
.around(addPrivateKeyToDatabaseRule)
.around(activityScenarioRule)
.around(ScreenshotTestRule())

@Test
fun testAddingSignatureAfterStart() {
Thread.sleep(1000)
onView(withId(R.id.editTextEmailMessage))
.perform(scrollTo())
.check(matches(withText(StringStartsWith.startsWith("\n\n$SIGNATURE"))))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.junit.annotations.FlowCryptTestSettings
import com.flowcrypt.email.model.MessageType
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.GrantPermissionRuleChooser
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.fragment.CreateMessageFragmentArgs
import com.flowcrypt.email.ui.base.BaseComposeScreenWithCustomSignatureFlowTest
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denys Bondarenko
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@FlowCryptTestSettings(useCommonIdling = false)
class ComposeScreenNewMessageWithCustomSignatureFlowTest :
BaseComposeScreenWithCustomSignatureFlowTest() {
override val createMessageFragmentArgs: CreateMessageFragmentArgs
get() = CreateMessageFragmentArgs(
encryptedByDefault = true,
messageType = MessageType.NEW
)

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(RetryRule.DEFAULT)
.around(ClearAppSettingsRule())
.around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS))
.around(addAccountToDatabaseRule)
.around(addPrivateKeyToDatabaseRule)
.around(activityScenarioRule)
.around(ScreenshotTestRule())

@Test
fun testAddingSignatureAfterStart() {
Thread.sleep(1000)

onView(withId(R.id.editTextEmailMessage))
.perform(scrollTo())
.check(matches(withText("\n\n$SIGNATURE")))
}

companion object {
const val SIGNATURE = "My great signature"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui


import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.model.MessageType
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.GrantPermissionRuleChooser
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.fragment.CreateMessageFragmentArgs
import com.flowcrypt.email.ui.base.BaseComposeScreenWithCustomSignatureFlowTest
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denys Bondarenko
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class ComposeScreenReplyWithCustomSignatureFlowTest :
BaseComposeScreenWithCustomSignatureFlowTest() {
override val createMessageFragmentArgs: CreateMessageFragmentArgs
get() = CreateMessageFragmentArgs(
incomingMessageInfo = getMsgInfo(
path = "messages/info/standard_msg_reply_to_header.json",
mimeMsgPath = "messages/mime/standard_msg_reply_to_header.txt",
accountEntity = BASE_ADD_ACCOUNT_RULE.apply { execute() }.accountEntityWithDecryptedInfo
),
encryptedByDefault = false,
messageType = MessageType.REPLY
)

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(RetryRule.DEFAULT)
.around(ClearAppSettingsRule())
.around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS))
.around(addAccountToDatabaseRule)
.around(addPrivateKeyToDatabaseRule)
.around(activityScenarioRule)
.around(ScreenshotTestRule())

@Test
fun testAddingSignatureAfterStart() {
Thread.sleep(1000)
onView(withId(R.id.editTextEmailMessage))
.perform(scrollTo())
.check(matches(withText("\n\n$SIGNATURE")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.flowcrypt.email.matchers.CustomMatchers.Companion.hasItem
import com.flowcrypt.email.matchers.CustomMatchers.Companion.withRecyclerViewItemCount
import com.flowcrypt.email.model.MessageEncryptionType
import com.flowcrypt.email.model.MessageType
import com.flowcrypt.email.rules.AddGmailAliasToDatabaseRule
import com.flowcrypt.email.rules.AddAccountAliasToDatabaseRule
import com.flowcrypt.email.rules.AddPrivateKeyToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.GrantPermissionRuleChooser
Expand All @@ -45,14 +45,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class CreateMessageTestRecipientsDuringReplyAllFlowTest : BaseComposeScreenTest() {
private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule()
private val addGmailAliasToDatabaseRule = AddGmailAliasToDatabaseRule(
AccountAliasesEntity(
private val addAccountAliasToDatabaseRule = AddAccountAliasToDatabaseRule(
listOf(
AccountAliasesEntity(
email = addAccountToDatabaseRule.account.email,
accountType = requireNotNull(addAccountToDatabaseRule.account.accountType),
sendAsEmail = ALIAS.lowercase(),
displayName = ALIAS,
isDefault = false,
verificationStatus = "accepted"
)
)
)
private val INBOX = LocalFolder(
Expand All @@ -70,7 +72,7 @@ class CreateMessageTestRecipientsDuringReplyAllFlowTest : BaseComposeScreenTest(
.around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS))
.around(addAccountToDatabaseRule)
.around(addPrivateKeyToDatabaseRule)
.around(addGmailAliasToDatabaseRule)
.around(addAccountAliasToDatabaseRule)
.around(activeActivityRule)
.around(ScreenshotTestRule())

Expand Down
Loading

0 comments on commit fa28437

Please sign in to comment.