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 24, 2021
1 parent b7fdee2 commit 09724be
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 95 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
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import java.io.File
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@Ignore("fix me")
//todo-denbond7 need to fix it
class ImportPublicKeyActivityTest : BaseTest() {
override val useIntents: Boolean = true
override val activityScenarioRule = activityScenarioRule<ImportPublicKeyActivity>(
Expand All @@ -82,6 +80,7 @@ class ImportPublicKeyActivityTest : BaseTest() {
.around(ScreenshotTestRule())

@Test
@Ignore("Review this test after migration to NavController")
fun testImportKeyFromFile() {
val resultData = TestGeneralUtil.genIntentWithPersistedReadPermissionForFile(fileWithPublicKey)
intending(
Expand Down Expand Up @@ -131,6 +130,7 @@ class ImportPublicKeyActivityTest : BaseTest() {
}

@Test
@Ignore("Review this test after migration to NavController")
fun testImportKeyFromClipboard() {
addTextToClipboard("public key", publicKey)
onView(withId(R.id.buttonLoadFromClipboard))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ import org.junit.runner.RunWith
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@Ignore("fix me")
//todo-denbond7 need to fix it
@Ignore("We've migrated this functionality to NavController. Need to review this class.")
class PreviewImportPgpContactActivityTest : BaseTest() {
/*override val activeActivityRule =
lazyActivityScenarioRule<PreviewImportPgpContactActivity>(launchActivity = false)*/
Expand Down
Loading

0 comments on commit 09724be

Please sign in to comment.