Use increment and decrement inside test not in production code

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-08 10:10:20 +02:00 коммит произвёл Alper Öztürk
Родитель ab67cb923e
Коммит 6b8ea250b9
4 изменённых файлов: 29 добавлений и 28 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -52,7 +52,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)
@ -70,7 +74,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)
@ -88,7 +96,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)
@ -106,7 +118,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)
@ -124,7 +138,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)
@ -154,7 +170,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)

Просмотреть файл

@ -192,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
@ -209,8 +207,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
binding.swipeContainingList.visibility = View.GONE
binding.swipeContainingEmpty.visibility = View.VISIBLE
}
EspressoIdlingResource.decrement()
}
private fun fetchAndSetData() {
@ -296,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
@ -307,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() {

Просмотреть файл

@ -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) {