Skip to content

Commit

Permalink
Fixed some UI tests.| #1188
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Nov 23, 2021
1 parent b7fdee2 commit dc0fa30
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.clearText
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
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 androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
Expand All @@ -23,9 +24,9 @@ import com.flowcrypt.email.rules.AddAccountToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.settings.SettingsActivity
import com.flowcrypt.email.util.AccountDaoManager
import org.hamcrest.CoreMatchers.not
import org.junit.Ignore
import com.flowcrypt.email.util.TestGeneralUtil
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -40,7 +41,6 @@ import org.junit.runner.RunWith
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@Ignore("fix me")
class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() {
private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules(
OrgRules(
Expand All @@ -59,12 +59,11 @@ class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() {
private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules)

override val useIntents: Boolean = true
/*override val activityScenarioRule = activityScenarioRule<ImportRecipientsFromSourceActivity>(
intent = ImportRecipientsFromSourceActivity.newIntent(
context = getTargetContext(),
accountEntity = addAccountToDatabaseRule.account
override val activityScenarioRule = activityScenarioRule<SettingsActivity>(
TestGeneralUtil.genIntentForNavigationComponent(
uri = "flowcrypt://email.flowcrypt.com/settings/contacts/import"
)
)*/
)

@get:Rule
var ruleChain: TestRule = RuleChain
Expand All @@ -78,7 +77,6 @@ class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() {
fun testCanLookupThisRecipientOnAttester() {
onView(withId(R.id.eTKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText("user@$DISALLOWED_DOMAIN"),
closeSoftKeyboard()
Expand All @@ -87,10 +85,8 @@ class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() {
.check(matches(isDisplayed()))
.perform(click())

onView(withId(R.id.layoutProgress))
.check(matches(not((isDisplayed()))))

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

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.clearText
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
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 androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
Expand All @@ -23,9 +24,9 @@ import com.flowcrypt.email.rules.AddAccountToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.settings.SettingsActivity
import com.flowcrypt.email.util.AccountDaoManager
import org.hamcrest.CoreMatchers
import org.junit.Ignore
import com.flowcrypt.email.util.TestGeneralUtil
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -40,7 +41,6 @@ import org.junit.runner.RunWith
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@Ignore("fix me")
class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() {
private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules(
OrgRules(
Expand All @@ -59,12 +59,11 @@ class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() {
private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules)

override val useIntents: Boolean = true
/*override val activityScenarioRule = activityScenarioRule<ImportRecipientsFromSourceActivity>(
intent = ImportRecipientsFromSourceActivity.newIntent(
context = getTargetContext(),
accountEntity = addAccountToDatabaseRule.account
override val activityScenarioRule = activityScenarioRule<SettingsActivity>(
TestGeneralUtil.genIntentForNavigationComponent(
uri = "flowcrypt://email.flowcrypt.com/settings/contacts/import"
)
)*/
)

@get:Rule
var ruleChain: TestRule = RuleChain
Expand All @@ -78,7 +77,6 @@ class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() {
fun testDisallowLookupOnAttester() {
onView(withId(R.id.eTKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText("user@$DISALLOWED_DOMAIN"),
closeSoftKeyboard()
Expand All @@ -87,10 +85,8 @@ class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() {
.check(matches(isDisplayed()))
.perform(click())

onView(withId(R.id.layoutProgress))
.check(matches(CoreMatchers.not((isDisplayed()))))

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

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import androidx.test.espresso.action.ViewActions.clearText
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.scrollTo
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intending
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasCategories
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.intent.matcher.IntentMatchers.hasType
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.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
Expand All @@ -34,16 +33,14 @@ import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.FlowCryptMockWebServerRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.settings.SettingsActivity
import com.flowcrypt.email.util.TestGeneralUtil
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.hasItem
import org.hamcrest.CoreMatchers.not
import org.junit.After
import org.junit.Before
import org.junit.Ignore
Expand All @@ -63,17 +60,15 @@ import java.net.HttpURLConnection
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@Ignore("fix me")
class ImportPgpContactActivityTest : BaseTest() {
private val addAccountToDatabaseRule = AddAccountToDatabaseRule()

override val useIntents: Boolean = true
/*override val activityScenarioRule = activityScenarioRule<ImportRecipientsFromSourceActivity>(
intent = ImportRecipientsFromSourceActivity.newIntent(
context = getTargetContext(),
accountEntity = addAccountToDatabaseRule.account
override val activityScenarioRule = activityScenarioRule<SettingsActivity>(
TestGeneralUtil.genIntentForNavigationComponent(
uri = "flowcrypt://email.flowcrypt.com/settings/contacts/import"
)
)*/
)

private lateinit var fileWithPublicKey: File
private lateinit var publicKey: String
Expand Down Expand Up @@ -137,7 +132,6 @@ class ImportPgpContactActivityTest : BaseTest() {
fun testFetchKeyFromAttesterForExistedUser() {
onView(withId(R.id.eTKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText(TestConstants.RECIPIENT_WITH_PUBLIC_KEY_ON_ATTESTER),
closeSoftKeyboard()
Expand All @@ -153,7 +147,6 @@ class ImportPgpContactActivityTest : BaseTest() {
fun testFetchKeyFromAttesterForExistedUserImeAction() {
onView(withId(R.id.eTKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText(TestConstants.RECIPIENT_WITH_PUBLIC_KEY_ON_ATTESTER),
closeSoftKeyboard(),
Expand All @@ -168,7 +161,6 @@ class ImportPgpContactActivityTest : BaseTest() {
fun testFetchKeyFromAttesterForNotExistedUser() {
onView(withId(R.id.eTKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText(TestConstants.RECIPIENT_WITHOUT_PUBLIC_KEY_ON_ATTESTER),
closeSoftKeyboard()
Expand All @@ -177,13 +169,13 @@ class ImportPgpContactActivityTest : BaseTest() {
.check(matches(isDisplayed()))
.perform(click())

onView(withId(R.id.layoutProgress))
.check(matches(not((isDisplayed()))))
//due to realization of MockWebServer I can't produce the same response.
isToastDisplayed("API error: code = 404, message = ")
isDialogWithTextDisplayed(decorView, "API error: code = 404, message = ")
}

@Test
@Ignore("temporary disabled due to arhitecture changes")
//https://developer.android.com/training/basics/intents/result#test
fun testImportKeyFromFile() {
val resultData = TestGeneralUtil.genIntentWithPersistedReadPermissionForFile(fileWithPublicKey)
intending(
Expand All @@ -192,8 +184,7 @@ class ImportPgpContactActivityTest : BaseTest() {
hasExtra(
`is`(Intent.EXTRA_INTENT),
allOf(
hasAction(Intent.ACTION_OPEN_DOCUMENT),
hasCategories(hasItem(equalTo(Intent.CATEGORY_OPENABLE))),
hasAction(Intent.ACTION_GET_CONTENT),
hasType("*/*")
)
)
Expand All @@ -209,7 +200,7 @@ class ImportPgpContactActivityTest : BaseTest() {
@Test
fun testImportKeyFromClipboard() {
addTextToClipboard("public key", publicKey)
onView(withId(R.id.buttonLoadFromClipboard))
onView(withId(R.id.btLoadFromClipboard))
.check(matches(isDisplayed()))
.perform(click())
onView(withText(containsString(TestConstants.RECIPIENT_WITHOUT_PUBLIC_KEY_ON_ATTESTER)))
Expand Down
3 changes: 3 additions & 0 deletions FlowCrypt/src/devTest/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@
android:name="com.flowcrypt.email.ui.activity.fragment.ImportRecipientsFromSourceFragment"
android:label="ImportRecipientsFromSourceFragment"
tools:layout="@layout/fragment_import_recipients_from_source">
<deepLink
android:id="@+id/deepLink"
app:uri="flowcrypt://email.flowcrypt.com/settings/contacts/import" />
<action
android:id="@+id/action_importRecipientsFromSourceFragment_to_parseAndSavePubKeysFragment"
app:destination="@id/parseAndSavePubKeysFragment" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati
val recipientsCcLiveData: MutableLiveData<Result<List<RecipientWithPubKeys>>> = MutableLiveData()
val recipientsBccLiveData: MutableLiveData<Result<List<RecipientWithPubKeys>>> = MutableLiveData()

val pubKeysFromServerLiveData: MutableLiveData<Result<PubResponse?>> = MutableLiveData()
private val lookUpPubKeysMutableStateFlow: MutableStateFlow<Result<PubResponse?>> =
MutableStateFlow(Result.loading())
val lookUpPubKeysStateFlow: StateFlow<Result<PubResponse?>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import com.flowcrypt.email.R
import com.flowcrypt.email.api.retrofit.response.base.Result
import com.flowcrypt.email.database.entity.PublicKeyEntity
import com.flowcrypt.email.databinding.FragmentParseAndSavePubKeysBinding
import com.flowcrypt.email.extensions.decrementSafely
import com.flowcrypt.email.extensions.incrementSafely
import com.flowcrypt.email.extensions.navController
import com.flowcrypt.email.extensions.showInfoDialogWithExceptionDetails
import com.flowcrypt.email.extensions.toast
Expand Down Expand Up @@ -109,6 +111,7 @@ class ParseAndSavePubKeysFragment : BaseFragment(), ListProgressBehaviour {
importPubKeysFromSourceSharedViewModel.pgpKeyDetailsListStateFlow.collect {
when (it.status) {
Result.Status.LOADING -> {
baseActivity.countingIdlingResource.incrementSafely()
showProgress()
}

Expand All @@ -121,13 +124,15 @@ class ParseAndSavePubKeysFragment : BaseFragment(), ListProgressBehaviour {
pubKeysAdapter.submitList(pgpKeyDetailsList)
showContent()
}
baseActivity.countingIdlingResource.decrementSafely()
}

Result.Status.EXCEPTION -> {
showStatus(
getString(R.string.source_has_wrong_pgp_structure, getString(R.string.public_))
)
showInfoDialogWithExceptionDetails(it.exception)
baseActivity.countingIdlingResource.decrementSafely()
}

else -> {
Expand Down

0 comments on commit dc0fa30

Please sign in to comment.