Fix code analytics

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-06 12:00:52 +02:00 committed by Alper Öztürk
parent 1859aad087
commit e713bef9d2
3 changed files with 74 additions and 21 deletions

View file

@ -8,19 +8,27 @@
package com.owncloud.android.ui.activity
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import com.nextcloud.utils.EspressoIdlingResource
import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.notifications.models.Action
import com.owncloud.android.lib.resources.notifications.models.Notification
import com.owncloud.android.lib.resources.notifications.models.RichObject
import com.owncloud.android.utils.ScreenshotTest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.util.GregorianCalendar
class NotificationsActivityIT : AbstractIT() {
private val scope = CoroutineScope(Dispatchers.IO)
private val testClassName = "com.owncloud.android.ui.activity.NotificationsActivityIT"
@Before
@ -41,7 +49,14 @@ class NotificationsActivityIT : AbstractIT() {
onIdleSync {
sut.runOnUiThread { sut.populateList(ArrayList()) }
val screenShotName = createName(testClassName + "_" + "empty", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}
@ -133,7 +148,13 @@ class NotificationsActivityIT : AbstractIT() {
scenario.onActivity { sut ->
sut.runOnUiThread { sut.populateList(notifications) }
val screenShotName = createName(testClassName + "_" + "showNotifications", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}
@ -145,7 +166,14 @@ class NotificationsActivityIT : AbstractIT() {
scenario.onActivity { sut ->
sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
val screenShotName = createName(testClassName + "_" + "error", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}

View file

@ -11,17 +11,25 @@ import android.accounts.Account
import android.accounts.AccountManager
import android.content.Intent
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import com.nextcloud.utils.EspressoIdlingResource
import com.owncloud.android.AbstractIT
import com.owncloud.android.MainApp
import com.owncloud.android.lib.common.accounts.AccountUtils
import com.owncloud.android.utils.ScreenshotTest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.junit.After
import org.junit.Before
import org.junit.Test
class TrashbinActivityIT : AbstractIT() {
private val scope = CoroutineScope(Dispatchers.IO)
private val testClassName = "com.owncloud.android.ui.trashbin.TrashbinActivityIT"
enum class TestCase {
@ -50,7 +58,13 @@ class TrashbinActivityIT : AbstractIT() {
onIdleSync {
sut.runOnUiThread { sut.loadFolder() }
val screenShotName = createName(testClassName + "_" + "error", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}
@ -82,7 +96,13 @@ class TrashbinActivityIT : AbstractIT() {
onIdleSync {
sut.runOnUiThread { sut.loadFolder() }
val screenShotName = createName(testClassName + "_" + "empty", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}
@ -98,7 +118,13 @@ class TrashbinActivityIT : AbstractIT() {
onIdleSync {
sut.runOnUiThread { sut.showInitialLoading() }
val screenShotName = createName(testClassName + "_" + "loading", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}
@ -114,7 +140,13 @@ class TrashbinActivityIT : AbstractIT() {
onIdleSync {
sut.runOnUiThread { sut.showUser() }
val screenShotName = createName(testClassName + "_" + "normalUser", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}
@ -142,7 +174,13 @@ class TrashbinActivityIT : AbstractIT() {
onIdleSync {
sut.runOnUiThread { sut.showUser() }
val screenShotName = createName(testClassName + "_" + "differentUser", "")
screenshotViaName(sut, screenShotName)
scope.launch {
onView(isRoot()).check(matches(isDisplayed()))
launch(Dispatchers.Main) {
screenshotViaName(sut, screenShotName)
}
}
}
}
}

View file

@ -189,10 +189,8 @@ class TrashbinActivity :
trashbinPresenter?.loadFolder(onCompleted = {
EspressoIdlingResource.decrement()
hideInitialLoading()
}, onError = {
EspressoIdlingResource.decrement()
hideInitialLoading()
})
}
}
@ -303,17 +301,6 @@ class TrashbinActivity :
EspressoIdlingResource.decrement()
}
@VisibleForTesting
fun hideInitialLoading() {
EspressoIdlingResource.increment()
binding.emptyList.emptyListView.visibility = View.VISIBLE
binding.list.visibility = View.VISIBLE
binding.loadingContent.visibility = View.GONE
EspressoIdlingResource.decrement()
}
@VisibleForTesting
fun showUser() {
EspressoIdlingResource.increment()