Эх сурвалжийг харах

Use increment and decrement inside test not in production code

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 11 сар өмнө
parent
commit
d843794d26

+ 6 - 0
app/src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt

@@ -45,7 +45,9 @@ class NotificationsActivityIT : AbstractIT() {
         launchActivity<NotificationsActivity>().use { scenario ->
             scenario.onActivity { sut ->
                 onIdleSync {
+                    EspressoIdlingResource.increment()
                     sut.populateList(ArrayList())
+                    EspressoIdlingResource.decrement()
                     val screenShotName = createName(testClassName + "_" + "empty", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)
@@ -140,7 +142,9 @@ class NotificationsActivityIT : AbstractIT() {
         launchActivity<NotificationsActivity>().use { scenario ->
             scenario.onActivity { sut ->
                 onIdleSync {
+                    EspressoIdlingResource.increment()
                     sut.populateList(notifications)
+                    EspressoIdlingResource.decrement()
                     val screenShotName = createName(testClassName + "_" + "showNotifications", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)
@@ -156,7 +160,9 @@ class NotificationsActivityIT : AbstractIT() {
         launchActivity<NotificationsActivity>().use { scenario ->
             scenario.onActivity { sut ->
                 onIdleSync {
+                    EspressoIdlingResource.increment()
                     sut.setEmptyContent("Error", "Error! Please try again later!")
+                    EspressoIdlingResource.decrement()
                     val screenShotName = createName(testClassName + "_" + "error", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)

+ 21 - 3
app/src/androidTest/java/com/owncloud/android/ui/trashbin/TrashbinActivityIT.kt

@@ -54,7 +54,11 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.ERROR)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.loadFolder()
+                    EspressoIdlingResource.increment()
+                    sut.loadFolder(
+                        onComplete = { EspressoIdlingResource.decrement() },
+                        onError = { EspressoIdlingResource.decrement() }
+                    )
                     val screenShotName = createName(testClassName + "_" + "error", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)
@@ -72,7 +76,11 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.FILES)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.loadFolder()
+                    EspressoIdlingResource.increment()
+                    sut.loadFolder(
+                        onComplete = { EspressoIdlingResource.decrement() },
+                        onError = { EspressoIdlingResource.decrement() }
+                    )
                     onView(isRoot()).check(matches(isDisplayed()))
                     val screenShotName = createName(testClassName + "_" + "files", "")
                     screenshotViaName(sut, screenShotName)
@@ -90,7 +98,11 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.loadFolder()
+                    EspressoIdlingResource.increment()
+                    sut.loadFolder(
+                        onComplete = { EspressoIdlingResource.decrement() },
+                        onError = { EspressoIdlingResource.decrement() }
+                    )
                     onView(isRoot()).check(matches(isDisplayed()))
                     val screenShotName = createName(testClassName + "_" + "empty", "")
                     screenshotViaName(sut, screenShotName)
@@ -108,7 +120,9 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
+                    EspressoIdlingResource.increment()
                     sut.showInitialLoading()
+                    EspressoIdlingResource.decrement()
                     val screenShotName = createName(testClassName + "_" + "loading", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)
@@ -126,7 +140,9 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
+                    EspressoIdlingResource.increment()
                     sut.showUser()
+                    EspressoIdlingResource.decrement()
                     val screenShotName = createName(testClassName + "_" + "normalUser", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)
@@ -156,7 +172,9 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
+                    EspressoIdlingResource.increment()
                     sut.showUser()
+                    EspressoIdlingResource.decrement()
                     val screenShotName = createName(testClassName + "_" + "differentUser", "")
                     onView(isRoot()).check(matches(isDisplayed()))
                     screenshotViaName(sut, screenShotName)

+ 0 - 9
app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt

@@ -20,7 +20,6 @@ import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.jobs.NotificationWork
 import com.nextcloud.client.network.ClientFactory.CreationException
 import com.nextcloud.common.NextcloudClient
-import com.nextcloud.utils.EspressoIdlingResource
 import com.owncloud.android.R
 import com.owncloud.android.databinding.NotificationsLayoutBinding
 import com.owncloud.android.datamodel.ArbitraryDataProvider
@@ -193,8 +192,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
 
     @VisibleForTesting
     fun populateList(notifications: List<Notification>?) {
-        EspressoIdlingResource.increment()
-
         initializeAdapter()
         adapter?.setNotificationItems(notifications)
         binding.loadingContent.visibility = View.GONE
@@ -210,8 +207,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
             binding.swipeContainingList.visibility = View.GONE
             binding.swipeContainingEmpty.visibility = View.VISIBLE
         }
-
-        EspressoIdlingResource.decrement()
     }
 
     private fun fetchAndSetData() {
@@ -297,8 +292,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
 
     @VisibleForTesting
     fun setEmptyContent(headline: String?, message: String?) {
-        EspressoIdlingResource.increment()
-
         binding.swipeContainingList.visibility = View.GONE
         binding.loadingContent.visibility = View.GONE
         binding.swipeContainingEmpty.visibility = View.VISIBLE
@@ -308,8 +301,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
         binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_notification)
         binding.emptyList.emptyListViewText.visibility = View.VISIBLE
         binding.emptyList.emptyListIcon.visibility = View.VISIBLE
-
-        EspressoIdlingResource.decrement()
     }
 
     override fun onResume() {

+ 2 - 17
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt

@@ -25,7 +25,6 @@ import com.nextcloud.client.account.CurrentAccountProvider
 import com.nextcloud.client.di.Injectable
 import com.nextcloud.client.network.ClientFactory
 import com.nextcloud.client.preferences.AppPreferences
-import com.nextcloud.utils.EspressoIdlingResource
 import com.owncloud.android.R
 import com.owncloud.android.databinding.TrashbinActivityBinding
 import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
@@ -177,9 +176,7 @@ class TrashbinActivity :
         )
     }
 
-    fun loadFolder() {
-        EspressoIdlingResource.increment()
-
+    fun loadFolder(onComplete: () -> Unit = {}, onError: () -> Unit = {}) {
         trashbinListAdapter?.let {
             if (it.itemCount > EMPTY_LIST_COUNT) {
                 binding.swipeContainingList.isRefreshing = true
@@ -187,11 +184,7 @@ class TrashbinActivity :
                 showInitialLoading()
             }
 
-            trashbinPresenter?.loadFolder(onCompleted = {
-                EspressoIdlingResource.decrement()
-            }, onError = {
-                EspressoIdlingResource.decrement()
-            })
+            trashbinPresenter?.loadFolder(onComplete, onError)
         }
     }
 
@@ -292,27 +285,19 @@ class TrashbinActivity :
 
     @VisibleForTesting
     fun showInitialLoading() {
-        EspressoIdlingResource.increment()
-
         binding.emptyList.emptyListView.visibility = View.GONE
         binding.list.visibility = View.GONE
         binding.loadingContent.visibility = View.VISIBLE
-
-        EspressoIdlingResource.decrement()
     }
 
     @VisibleForTesting
     fun showUser() {
-        EspressoIdlingResource.increment()
-
         binding.loadingContent.visibility = View.GONE
         binding.list.visibility = View.VISIBLE
         binding.swipeContainingList.isRefreshing = false
         binding.emptyList.emptyListViewText.text = user.get().accountName
         binding.emptyList.emptyListViewText.visibility = View.VISIBLE
         binding.emptyList.emptyListView.visibility = View.VISIBLE
-
-        EspressoIdlingResource.decrement()
     }
 
     override fun showError(message: Int) {