Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: denbond7
*/

package com.flowcrypt.email.ui.gmailapi.passwordprotected

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.flowcrypt.email.R
import com.flowcrypt.email.TestConstants
import com.flowcrypt.email.database.entity.AccountEntity
import com.flowcrypt.email.matchers.CustomMatchers.Companion.withTextViewDrawable
import com.flowcrypt.email.matchers.TextViewDrawableMatcher
import com.flowcrypt.email.rules.FlowCryptMockWebServerRule
import com.flowcrypt.email.ui.base.BaseComposeGmailFlow
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
import org.junit.Before

/**
* @author Denys Bondarenko
*/
open class BaseComposeScreenPasswordProtectedDisallowedTermsTest(
accountEntity: AccountEntity = BASE_ACCOUNT_ENTITY
) : BaseComposeGmailFlow(accountEntity) {
override val mockWebServerRule =
FlowCryptMockWebServerRule(TestConstants.MOCK_WEB_SERVER_PORT, object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return handleCommonAPICalls(request)
}
})

@Before
fun setUp() {
onView(withId(R.id.editTextEmailAddress))
.perform(
typeText(TestConstants.RECIPIENT_WITHOUT_PUBLIC_KEY_ON_ATTESTER),
pressImeActionButton(),
closeSoftKeyboard()
)
//need to leave focus from 'To' field. move the focus to the next view
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo(), click(), replaceText(MATCHING_SUBJECTS.first()))

onView(withId(R.id.btnSetWebPortalPassword))
.check(matches(isDisplayed()))
.check(matches(withText(getResString(R.string.tap_to_protect_with_web_portal_password))))
.check(
matches(
withTextViewDrawable(
resourceId = R.drawable.ic_password_not_protected_white_24,
drawablePosition = TextViewDrawableMatcher.DrawablePosition.LEFT
)
)
).perform(click())

onView(withId(R.id.eTPassphrase))
.perform(
replaceText(PASSWORD),
closeSoftKeyboard()
)

onView(withId(R.id.btSetPassword))
.perform(click())
}

companion object {
private const val PASSWORD = "Qwerty1234@"
const val URL = "https://flowcrypt.com"

val MATCHING_SUBJECTS = listOf(
"[Classification: Data Control: Internal Data Control] Quarter results",
"Conference information [Classification: Data Control: Internal Data Control]",
"[Classification: Data Control: Internal Data Control]",
"aaaa[Classification: Data Control: Internal Data Control]bbb",
"[droid]",
"check -droid- case",
)

val NON_MATCHING_SUBJECTS = listOf(
"[1Classification: Data Control: Internal Data Control] Quarter results",
"Conference information [1Classification: Data Control: Internal Data Control]",
"[1Classification: Data Control: Internal Data Control]",
"aaaa[1Classification: Data Control: Internal Data Control]bbb",
"Microdroid androids",
)

const val ERROR_TEXT =
"Password-protected messages are disabled, please check $URL"

val TERMS = listOf(
"droid",
"[Classification: Data Control: Internal Data Control]",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: denbond7
*/

package com.flowcrypt.email.ui.gmailapi.passwordprotected

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
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.junit.annotations.OutgoingMessageConfiguration
import com.flowcrypt.email.rules.AddRecipientsToDatabaseRule
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 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)
@OutgoingMessageConfiguration(
to = [],
cc = [],
bcc = [],
message = "",
subject = "",
isNew = true
)
class ComposeScreenPasswordProtectedDisallowedTermsErrorTextMissingFlowTest :
BaseComposeScreenPasswordProtectedDisallowedTermsTest(
ACCOUNT_ENTITY_WITH_MISSING_ERROR_TEXT
) {

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

@Test
fun testMissingOptionalPropertiesInClientConfiguration() {
onView(withId(R.id.menuActionSend))
.check(matches(isDisplayed()))
.perform(click())
onView(withText(ERROR_TEXT)).check(doesNotExist())
}

companion object {
val ACCOUNT_ENTITY_WITH_MISSING_ERROR_TEXT =
BASE_ACCOUNT_ENTITY.copy(
clientConfiguration = BASE_ACCOUNT_ENTITY.clientConfiguration?.copy(
disallowPasswordMessagesErrorText = null,
disallowPasswordMessagesForTerms = TERMS
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: denbond7
*/

package com.flowcrypt.email.ui.gmailapi.passwordprotected

import android.app.Instrumentation
import android.content.Intent
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.openLinkWithText
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasData
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
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.junit.annotations.OutgoingMessageConfiguration
import com.flowcrypt.email.rules.AddRecipientsToDatabaseRule
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 org.hamcrest.Matchers.allOf
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, useIntents = true)
@OutgoingMessageConfiguration(
to = [],
cc = [],
bcc = [],
message = "",
subject = "",
isNew = true
)
class ComposeScreenPasswordProtectedDisallowedTermsFlowTest :
BaseComposeScreenPasswordProtectedDisallowedTermsTest(
ACCOUNT_ENTITY_WITH_EXISTING_OPTIONAL_PARAMETERS
) {

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

@Test
fun testDialogWithErrorText() {
intentsRelease()

MATCHING_SUBJECTS.forEach { subject ->
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo(), click(), replaceText(subject))

onView(withId(R.id.menuActionSend))
.check(matches(isDisplayed()))
.perform(click())

isDialogWithTextDisplayed(
decorView,
ERROR_TEXT
)

Intents.init()
//test that URL is openable
val expectingIntent = allOf(hasAction(Intent.ACTION_VIEW), hasData(URL))
//mocking intent to prevent actual navigation during test
Intents.intending(expectingIntent).respondWith(Instrumentation.ActivityResult(0, null))
//performing action
onView(withText(ERROR_TEXT))
.perform(openLinkWithText(URL))
//asserting our expected intent was recorded
Intents.intended(expectingIntent)
Thread.sleep(1000)
Intents.release()

onView(withId(android.R.id.button1))
.check(matches(isDisplayed()))
.perform(click())
}
}

@Test
fun testDialogWithoutErrorText() {
NON_MATCHING_SUBJECTS.forEach { subject ->
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo(), click(), replaceText(subject))
Thread.sleep(1000)

onView(withId(R.id.menuActionSend))
.check(matches(isDisplayed()))
.perform(click())

onView(
withText(getResString(R.string.sending_message_must_not_be_empty))
).check(matches(isDisplayed()))
}
}

companion object {
val ACCOUNT_ENTITY_WITH_EXISTING_OPTIONAL_PARAMETERS =
BASE_ACCOUNT_ENTITY.copy(
clientConfiguration = BASE_ACCOUNT_ENTITY.clientConfiguration?.copy(
disallowPasswordMessagesErrorText = ERROR_TEXT,
disallowPasswordMessagesForTerms = TERMS
)
)
}
}
Loading
Loading