Try with IntentsTestRule

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-07-08 13:28:19 +02:00 committed by Alper Öztürk
parent 3800cd52ff
commit 34961f27d0
3 changed files with 43 additions and 61 deletions

View file

@ -23,7 +23,7 @@ jobs:
matrix: matrix:
scheme: [ Light ] scheme: [ Light ]
color: [ blue ] color: [ blue ]
api-level: [ 29 ] api-level: [ 27 ]
steps: steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

View file

@ -10,10 +10,8 @@ package com.owncloud.android.ui.trashbin
import android.accounts.Account import android.accounts.Account
import android.accounts.AccountManager import android.accounts.AccountManager
import android.content.Intent import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.IdlingRegistry import androidx.test.espresso.IdlingRegistry
import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.utils.EspressoIdlingResource import com.nextcloud.utils.EspressoIdlingResource
import com.owncloud.android.AbstractIT import com.owncloud.android.AbstractIT
import com.owncloud.android.MainApp import com.owncloud.android.MainApp
@ -31,11 +29,8 @@ class TrashbinActivityIT : AbstractIT() {
FILES FILES
} }
private var scenario: ActivityScenario<TrashbinActivity>? = null
val intent = Intent(ApplicationProvider.getApplicationContext(), TrashbinActivity::class.java)
@get:Rule @get:Rule
val activityRule = ActivityScenarioRule<TrashbinActivity>(intent) var activityRule = IntentsTestRule(TrashbinActivity::class.java, true, false)
@Before @Before
fun registerIdlingResource() { fun registerIdlingResource() {
@ -45,76 +40,65 @@ class TrashbinActivityIT : AbstractIT() {
@After @After
fun unregisterIdlingResource() { fun unregisterIdlingResource() {
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource) IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
scenario?.close()
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun error() { fun error() {
scenario = activityRule.scenario val sut: TrashbinActivity = activityRule.launchActivity(null)
scenario?.onActivity { sut -> val trashbinRepository = TrashbinLocalRepository(TestCase.ERROR)
val trashbinRepository = TrashbinLocalRepository(TestCase.ERROR) sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut) onIdleSync {
onIdleSync { sut.runOnUiThread { sut.loadFolder() }
sut.runOnUiThread { sut.loadFolder() } screenshot(sut)
screenshot(sut)
}
} }
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun files() { fun files() {
scenario = activityRule.scenario val sut: TrashbinActivity = activityRule.launchActivity(null)
scenario?.onActivity { sut -> val trashbinRepository = TrashbinLocalRepository(TestCase.FILES)
val trashbinRepository = TrashbinLocalRepository(TestCase.FILES) sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut) onIdleSync {
onIdleSync { sut.runOnUiThread { sut.loadFolder() }
sut.runOnUiThread { sut.loadFolder() } screenshot(sut)
screenshot(sut)
}
} }
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun empty() { fun empty() {
scenario = activityRule.scenario val sut: TrashbinActivity = activityRule.launchActivity(null)
scenario?.onActivity { sut -> val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY) sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut) onIdleSync {
onIdleSync { sut.runOnUiThread { sut.loadFolder() }
sut.runOnUiThread { sut.loadFolder() } screenshot(sut)
screenshot(sut)
}
} }
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun loading() { fun loading() {
scenario = activityRule.scenario val sut: TrashbinActivity = activityRule.launchActivity(null)
scenario?.onActivity { sut -> val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY) sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut) onIdleSync {
onIdleSync { sut.runOnUiThread { sut.showInitialLoading() }
sut.runOnUiThread { sut.showInitialLoading() } screenshot(sut)
screenshot(sut)
}
} }
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun normalUser() { fun normalUser() {
scenario = activityRule.scenario val sut: TrashbinActivity = activityRule.launchActivity(null)
scenario?.onActivity { sut -> val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY) sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut) onIdleSync {
onIdleSync { sut.runOnUiThread { sut.showUser() }
sut.runOnUiThread { sut.showUser() } screenshot(sut)
screenshot(sut)
}
} }
} }
@ -128,18 +112,16 @@ class TrashbinActivityIT : AbstractIT() {
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://nextcloud.localhost") platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://nextcloud.localhost")
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "differentUser") platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "differentUser")
val intent = Intent(targetContext, TrashbinActivity::class.java) val intent = Intent().apply {
intent.putExtra(Intent.EXTRA_USER, "differentUser@https://nextcloud.localhost") putExtra(Intent.EXTRA_USER, "differentUser@https://nextcloud.localhost")
}
val sut: TrashbinActivity = activityRule.launchActivity(intent)
val sutScenario = ActivityScenario.launch<TrashbinActivity>(intent) val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
sutScenario.onActivity { sut -> sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
sut.intent = intent onIdleSync {
val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY) sut.runOnUiThread { sut.showUser() }
sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut) screenshot(sut)
onIdleSync {
sut.runOnUiThread { sut.showUser() }
screenshot(sut)
}
} }
} }
} }

View file

@ -12,7 +12,7 @@ fi
## emulator ## emulator
if [[ ! $(emulator -list-avds | grep uiComparison -c) -eq 0 ]]; then if [[ ! $(emulator -list-avds | grep uiComparison -c) -eq 0 ]]; then
avdmanager delete avd -n uiComparison avdmanager delete avd -n uiComparison
(sleep 5; echo "no") | avdmanager create avd -n uiComparison -c 100M -k "system-images;android-30;google_apis;x86" --abi "google_apis/x86" (sleep 5; echo "no") | avdmanager create avd -n uiComparison -c 100M -k "system-images;android-27;google_apis;x86" --abi "google_apis/x86"
fi fi
if [ "$1" == "debug" ]; then if [ "$1" == "debug" ]; then