|
@@ -10,130 +10,176 @@ package com.owncloud.android.ui.trashbin
|
|
|
import android.accounts.Account
|
|
|
import android.accounts.AccountManager
|
|
|
import android.content.Intent
|
|
|
-import androidx.test.espresso.intent.rule.IntentsTestRule
|
|
|
+import androidx.annotation.UiThread
|
|
|
+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.owncloud.android.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 org.junit.Rule
|
|
|
+import org.junit.After
|
|
|
+import org.junit.Before
|
|
|
import org.junit.Test
|
|
|
|
|
|
class TrashbinActivityIT : AbstractIT() {
|
|
|
+ private val testClassName = "com.owncloud.android.ui.trashbin.TrashbinActivityIT"
|
|
|
+
|
|
|
enum class TestCase {
|
|
|
ERROR,
|
|
|
EMPTY,
|
|
|
FILES
|
|
|
}
|
|
|
|
|
|
- @get:Rule
|
|
|
- var activityRule = IntentsTestRule(TrashbinActivity::class.java, true, false)
|
|
|
+ @Before
|
|
|
+ fun registerIdlingResource() {
|
|
|
+ IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ fun unregisterIdlingResource() {
|
|
|
+ IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
+ @UiThread
|
|
|
@ScreenshotTest
|
|
|
fun error() {
|
|
|
- val sut: TrashbinActivity = activityRule.launchActivity(null)
|
|
|
-
|
|
|
- val trashbinRepository = TrashbinLocalRepository(TestCase.ERROR)
|
|
|
-
|
|
|
- sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
-
|
|
|
- sut.runOnUiThread { sut.loadFolder() }
|
|
|
-
|
|
|
- shortSleep()
|
|
|
-
|
|
|
- screenshot(sut)
|
|
|
+ launchActivity<TrashbinActivity>().use { scenario ->
|
|
|
+ scenario.onActivity { sut ->
|
|
|
+ val trashbinRepository = TrashbinLocalRepository(TestCase.ERROR)
|
|
|
+ sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
+ onIdleSync {
|
|
|
+ EspressoIdlingResource.increment()
|
|
|
+ sut.loadFolder(
|
|
|
+ onComplete = { EspressoIdlingResource.decrement() },
|
|
|
+ onError = { EspressoIdlingResource.decrement() }
|
|
|
+ )
|
|
|
+ val screenShotName = createName(testClassName + "_" + "error", "")
|
|
|
+ onView(isRoot()).check(matches(isDisplayed()))
|
|
|
+ screenshotViaName(sut, screenShotName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
+ @UiThread
|
|
|
@ScreenshotTest
|
|
|
fun files() {
|
|
|
- val sut: TrashbinActivity = activityRule.launchActivity(null)
|
|
|
-
|
|
|
- val trashbinRepository = TrashbinLocalRepository(TestCase.FILES)
|
|
|
-
|
|
|
- sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
-
|
|
|
- sut.runOnUiThread { sut.loadFolder() }
|
|
|
-
|
|
|
- waitForIdleSync()
|
|
|
- shortSleep()
|
|
|
- shortSleep()
|
|
|
-
|
|
|
- screenshot(sut)
|
|
|
+ launchActivity<TrashbinActivity>().use { scenario ->
|
|
|
+ scenario.onActivity { sut ->
|
|
|
+ val trashbinRepository = TrashbinLocalRepository(TestCase.FILES)
|
|
|
+ sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
+ onIdleSync {
|
|
|
+ EspressoIdlingResource.increment()
|
|
|
+ sut.loadFolder(
|
|
|
+ onComplete = { EspressoIdlingResource.decrement() },
|
|
|
+ onError = { EspressoIdlingResource.decrement() }
|
|
|
+ )
|
|
|
+ onView(isRoot()).check(matches(isDisplayed()))
|
|
|
+ val screenShotName = createName(testClassName + "_" + "files", "")
|
|
|
+ screenshotViaName(sut, screenShotName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
+ @UiThread
|
|
|
@ScreenshotTest
|
|
|
fun empty() {
|
|
|
- val sut: TrashbinActivity = activityRule.launchActivity(null)
|
|
|
-
|
|
|
- val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
|
|
|
-
|
|
|
- sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
-
|
|
|
- sut.runOnUiThread { sut.loadFolder() }
|
|
|
-
|
|
|
- shortSleep()
|
|
|
- shortSleep()
|
|
|
- waitForIdleSync()
|
|
|
-
|
|
|
- screenshot(sut.binding.emptyList.emptyListView)
|
|
|
+ launchActivity<TrashbinActivity>().use { scenario ->
|
|
|
+ scenario.onActivity { sut ->
|
|
|
+ val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
|
|
|
+ sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
+ onIdleSync {
|
|
|
+ EspressoIdlingResource.increment()
|
|
|
+ sut.loadFolder(
|
|
|
+ onComplete = { EspressoIdlingResource.decrement() },
|
|
|
+ onError = { EspressoIdlingResource.decrement() }
|
|
|
+ )
|
|
|
+ onView(isRoot()).check(matches(isDisplayed()))
|
|
|
+ val screenShotName = createName(testClassName + "_" + "empty", "")
|
|
|
+ screenshotViaName(sut, screenShotName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
+ @UiThread
|
|
|
@ScreenshotTest
|
|
|
fun loading() {
|
|
|
- val sut: TrashbinActivity = activityRule.launchActivity(null)
|
|
|
-
|
|
|
- val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
|
|
|
-
|
|
|
- sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
-
|
|
|
- sut.runOnUiThread { sut.showInitialLoading() }
|
|
|
-
|
|
|
- shortSleep()
|
|
|
-
|
|
|
- screenshot(sut.binding.listFragmentLayout)
|
|
|
+ launchActivity<TrashbinActivity>().use { scenario ->
|
|
|
+ scenario.onActivity { sut ->
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
+ @UiThread
|
|
|
@ScreenshotTest
|
|
|
fun normalUser() {
|
|
|
- val sut: TrashbinActivity = activityRule.launchActivity(null)
|
|
|
-
|
|
|
- val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
|
|
|
-
|
|
|
- sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
-
|
|
|
- sut.runOnUiThread { sut.showUser() }
|
|
|
-
|
|
|
- shortSleep()
|
|
|
-
|
|
|
- screenshot(sut)
|
|
|
+ launchActivity<TrashbinActivity>().use { scenario ->
|
|
|
+ scenario.onActivity { sut ->
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
+ @UiThread
|
|
|
@ScreenshotTest
|
|
|
fun differentUser() {
|
|
|
val temp = Account("differentUser@https://nextcloud.localhost", MainApp.getAccountType(targetContext))
|
|
|
|
|
|
- val platformAccountManager = AccountManager.get(targetContext)
|
|
|
- platformAccountManager.addAccountExplicitly(temp, "password", null)
|
|
|
- platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://nextcloud.localhost")
|
|
|
- platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "differentUser")
|
|
|
-
|
|
|
- val intent = Intent()
|
|
|
- intent.putExtra(Intent.EXTRA_USER, "differentUser@https://nextcloud.localhost")
|
|
|
- val sut: TrashbinActivity = activityRule.launchActivity(intent)
|
|
|
-
|
|
|
- val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
|
|
|
-
|
|
|
- sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
|
|
|
-
|
|
|
- sut.runOnUiThread { sut.showUser() }
|
|
|
-
|
|
|
- shortSleep()
|
|
|
-
|
|
|
- screenshot(sut)
|
|
|
+ AccountManager.get(targetContext).apply {
|
|
|
+ addAccountExplicitly(temp, "password", null)
|
|
|
+ setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://nextcloud.localhost")
|
|
|
+ setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "differentUser")
|
|
|
+ }
|
|
|
+
|
|
|
+ val intent = Intent(targetContext, TrashbinActivity::class.java).apply {
|
|
|
+ putExtra(Intent.EXTRA_USER, "differentUser@https://nextcloud.localhost")
|
|
|
+ }
|
|
|
+
|
|
|
+ launchActivity<TrashbinActivity>(intent).use { scenario ->
|
|
|
+ scenario.onActivity { sut ->
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|