From dc0fa302d4ae3a555f5584039370c1512f7e962d Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Tue, 23 Nov 2021 15:43:40 +0200 Subject: [PATCH] Fixed some UI tests.| #1188 --- ...vityDisallowAttesterSearchForDomainTest.kt | 24 ++++++-------- ...ntactActivityDisallowAttesterSearchTest.kt | 24 ++++++-------- .../activity/ImportPgpContactActivityTest.kt | 31 +++++++------------ .../src/devTest/res/navigation/nav_graph.xml | 3 ++ .../jetpack/viewmodel/RecipientsViewModel.kt | 1 - .../fragment/ParseAndSavePubKeysFragment.kt | 5 +++ 6 files changed, 39 insertions(+), 49 deletions(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt index 4ad61bf84f..c41e5d9e41 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchForDomainTest.kt @@ -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 @@ -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 @@ -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( @@ -59,12 +59,11 @@ class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() { private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules) override val useIntents: Boolean = true - /*override val activityScenarioRule = activityScenarioRule( - intent = ImportRecipientsFromSourceActivity.newIntent( - context = getTargetContext(), - accountEntity = addAccountToDatabaseRule.account + override val activityScenarioRule = activityScenarioRule( + TestGeneralUtil.genIntentForNavigationComponent( + uri = "flowcrypt://email.flowcrypt.com/settings/contacts/import" ) - )*/ + ) @get:Rule var ruleChain: TestRule = RuleChain @@ -78,7 +77,6 @@ class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() { fun testCanLookupThisRecipientOnAttester() { onView(withId(R.id.eTKeyIdOrEmail)) .perform( - scrollTo(), clearText(), typeText("user@$DISALLOWED_DOMAIN"), closeSoftKeyboard() @@ -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 { diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt index 233ef06243..7f8ecdb526 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityDisallowAttesterSearchTest.kt @@ -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 @@ -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 @@ -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( @@ -59,12 +59,11 @@ class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() { private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules) override val useIntents: Boolean = true - /*override val activityScenarioRule = activityScenarioRule( - intent = ImportRecipientsFromSourceActivity.newIntent( - context = getTargetContext(), - accountEntity = addAccountToDatabaseRule.account + override val activityScenarioRule = activityScenarioRule( + TestGeneralUtil.genIntentForNavigationComponent( + uri = "flowcrypt://email.flowcrypt.com/settings/contacts/import" ) - )*/ + ) @get:Rule var ruleChain: TestRule = RuleChain @@ -78,7 +77,6 @@ class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() { fun testDisallowLookupOnAttester() { onView(withId(R.id.eTKeyIdOrEmail)) .perform( - scrollTo(), clearText(), typeText("user@$DISALLOWED_DOMAIN"), closeSoftKeyboard() @@ -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 { diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityTest.kt index d3ac28e259..03d128e869 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/ImportPgpContactActivityTest.kt @@ -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 @@ -34,6 +33,7 @@ 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 @@ -41,9 +41,6 @@ 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 @@ -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( - intent = ImportRecipientsFromSourceActivity.newIntent( - context = getTargetContext(), - accountEntity = addAccountToDatabaseRule.account + override val activityScenarioRule = activityScenarioRule( + TestGeneralUtil.genIntentForNavigationComponent( + uri = "flowcrypt://email.flowcrypt.com/settings/contacts/import" ) - )*/ + ) private lateinit var fileWithPublicKey: File private lateinit var publicKey: String @@ -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() @@ -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(), @@ -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() @@ -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( @@ -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("*/*") ) ) @@ -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))) diff --git a/FlowCrypt/src/devTest/res/navigation/nav_graph.xml b/FlowCrypt/src/devTest/res/navigation/nav_graph.xml index 86e211b622..a5d2df27bf 100644 --- a/FlowCrypt/src/devTest/res/navigation/nav_graph.xml +++ b/FlowCrypt/src/devTest/res/navigation/nav_graph.xml @@ -303,6 +303,9 @@ android:name="com.flowcrypt.email.ui.activity.fragment.ImportRecipientsFromSourceFragment" android:label="ImportRecipientsFromSourceFragment" tools:layout="@layout/fragment_import_recipients_from_source"> + diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RecipientsViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RecipientsViewModel.kt index 3c6b5b7ab8..bea471281a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RecipientsViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RecipientsViewModel.kt @@ -71,7 +71,6 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati val recipientsCcLiveData: MutableLiveData>> = MutableLiveData() val recipientsBccLiveData: MutableLiveData>> = MutableLiveData() - val pubKeysFromServerLiveData: MutableLiveData> = MutableLiveData() private val lookUpPubKeysMutableStateFlow: MutableStateFlow> = MutableStateFlow(Result.loading()) val lookUpPubKeysStateFlow: StateFlow> = diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ParseAndSavePubKeysFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ParseAndSavePubKeysFragment.kt index 3820327da9..2f068f42a1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ParseAndSavePubKeysFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ParseAndSavePubKeysFragment.kt @@ -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 @@ -109,6 +111,7 @@ class ParseAndSavePubKeysFragment : BaseFragment(), ListProgressBehaviour { importPubKeysFromSourceSharedViewModel.pgpKeyDetailsListStateFlow.collect { when (it.status) { Result.Status.LOADING -> { + baseActivity.countingIdlingResource.incrementSafely() showProgress() } @@ -121,6 +124,7 @@ class ParseAndSavePubKeysFragment : BaseFragment(), ListProgressBehaviour { pubKeysAdapter.submitList(pgpKeyDetailsList) showContent() } + baseActivity.countingIdlingResource.decrementSafely() } Result.Status.EXCEPTION -> { @@ -128,6 +132,7 @@ class ParseAndSavePubKeysFragment : BaseFragment(), ListProgressBehaviour { getString(R.string.source_has_wrong_pgp_structure, getString(R.string.public_)) ) showInfoDialogWithExceptionDetails(it.exception) + baseActivity.countingIdlingResource.decrementSafely() } else -> {