Merge pull request #14097 from nextcloud/fix-backup-list-fragment-ss-test

Fix BackupListFragmentIT SS Tests
This commit is contained in:
Alper Öztürk 2024-12-11 10:35:28 +01:00 committed by GitHub
commit 2ec38321b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,94 +7,154 @@
package com.owncloud.android.ui.fragment package com.owncloud.android.ui.fragment
import android.Manifest import android.Manifest
import androidx.test.espresso.intent.rule.IntentsTestRule 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 androidx.test.rule.GrantPermissionRule import androidx.test.rule.GrantPermissionRule
import com.owncloud.android.AbstractIT import com.owncloud.android.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.ui.activity.ContactsPreferenceActivity import com.owncloud.android.ui.activity.ContactsPreferenceActivity
import com.owncloud.android.ui.fragment.contactsbackup.BackupListFragment import com.owncloud.android.ui.fragment.contactsbackup.BackupListFragment
import com.owncloud.android.utils.EspressoIdlingResource
import com.owncloud.android.utils.ScreenshotTest import com.owncloud.android.utils.ScreenshotTest
import org.junit.After
import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
class BackupListFragmentIT : AbstractIT() { class BackupListFragmentIT : AbstractIT() {
@get:Rule
val testActivityRule = IntentsTestRule(ContactsPreferenceActivity::class.java, true, false)
@get:Rule @get:Rule
val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CALENDAR) val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CALENDAR)
private val testClassName = "com.owncloud.android.ui.fragment.BackupListFragmentIT"
@Before
fun registerIdlingResource() {
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
}
@After
fun unregisterIdlingResource() {
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
}
@Test @Test
@ScreenshotTest @ScreenshotTest
fun showLoading() { fun showLoading() {
val sut = testActivityRule.launchActivity(null) launchActivity<ContactsPreferenceActivity>().use { scenario ->
val file = OCFile("/") scenario.onActivity { sut ->
val transaction = sut.supportFragmentManager.beginTransaction() val file = OCFile("/")
val transaction = sut.supportFragmentManager.beginTransaction()
transaction.replace(R.id.frame_container, BackupListFragment.newInstance(file, user)) onIdleSync {
transaction.commit() EspressoIdlingResource.increment()
waitForIdleSync() transaction.replace(R.id.frame_container, BackupListFragment.newInstance(file, user))
screenshot(sut) transaction.commit()
EspressoIdlingResource.decrement()
val screenShotName = createName(testClassName + "_" + "showLoading", "")
onView(isRoot()).check(matches(isDisplayed()))
screenshotViaName(sut, screenShotName)
}
}
}
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun showContactList() { fun showContactList() {
val sut = testActivityRule.launchActivity(null) launchActivity<ContactsPreferenceActivity>().use { scenario ->
val transaction = sut.supportFragmentManager.beginTransaction() scenario.onActivity { sut ->
val file = getFile("vcard.vcf") val transaction = sut.supportFragmentManager.beginTransaction()
val ocFile = OCFile("/vcard.vcf") val file = getFile("vcard.vcf")
ocFile.storagePath = file.absolutePath val ocFile = OCFile("/vcard.vcf").apply {
ocFile.mimeType = "text/vcard" storagePath = file.absolutePath
mimeType = "text/vcard"
}
transaction.replace(R.id.frame_container, BackupListFragment.newInstance(ocFile, user)) onIdleSync {
transaction.commit() EspressoIdlingResource.increment()
waitForIdleSync() transaction.replace(R.id.frame_container, BackupListFragment.newInstance(ocFile, user))
shortSleep() transaction.commit()
screenshot(sut)
EspressoIdlingResource.decrement()
val screenShotName = createName(testClassName + "_" + "showContactList", "")
onView(isRoot()).check(matches(isDisplayed()))
screenshotViaName(sut, screenShotName)
}
}
}
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun showCalendarList() { fun showCalendarList() {
val sut = testActivityRule.launchActivity(null) launchActivity<ContactsPreferenceActivity>().use { scenario ->
val transaction = sut.supportFragmentManager.beginTransaction() scenario.onActivity { sut ->
val file = getFile("calendar.ics") val transaction = sut.supportFragmentManager.beginTransaction()
val ocFile = OCFile("/Private calender_2020-09-01_10-45-20.ics.ics") val file = getFile("calendar.ics")
ocFile.storagePath = file.absolutePath val ocFile = OCFile("/Private calender_2020-09-01_10-45-20.ics.ics").apply {
ocFile.mimeType = "text/calendar" storagePath = file.absolutePath
mimeType = "text/calendar"
}
transaction.replace(R.id.frame_container, BackupListFragment.newInstance(ocFile, user)) onIdleSync {
transaction.commit() EspressoIdlingResource.increment()
waitForIdleSync() transaction.replace(R.id.frame_container, BackupListFragment.newInstance(ocFile, user))
screenshot(sut) transaction.commit()
EspressoIdlingResource.decrement()
val screenShotName = createName(testClassName + "_" + "showCalendarList", "")
onView(isRoot()).check(matches(isDisplayed()))
screenshotViaName(sut, screenShotName)
}
}
}
} }
@Test @Test
@ScreenshotTest @ScreenshotTest
fun showCalendarAndContactsList() { fun showCalendarAndContactsList() {
val sut = testActivityRule.launchActivity(null) launchActivity<ContactsPreferenceActivity>().use { scenario ->
val transaction = sut.supportFragmentManager.beginTransaction() scenario.onActivity { sut ->
val transaction = sut.supportFragmentManager.beginTransaction()
val calendarFile = getFile("calendar.ics")
val calendarOcFile = OCFile("/Private calender_2020-09-01_10-45-20.ics.ics").apply {
storagePath = calendarFile.absolutePath
mimeType = "text/calendar"
}
val calendarFile = getFile("calendar.ics") val contactFile = getFile("vcard.vcf")
val calendarOcFile = OCFile("/Private calender_2020-09-01_10-45-20.ics") val contactOcFile = OCFile("/vcard.vcf").apply {
calendarOcFile.storagePath = calendarFile.absolutePath storagePath = contactFile.absolutePath
calendarOcFile.mimeType = "text/calendar" mimeType = "text/vcard"
}
val contactFile = getFile("vcard.vcf") val files = arrayOf(calendarOcFile, contactOcFile)
val contactOcFile = OCFile("/vcard.vcf")
contactOcFile.storagePath = contactFile.absolutePath
contactOcFile.mimeType = "text/vcard"
val files = arrayOf(calendarOcFile, contactOcFile) onIdleSync {
transaction.replace(R.id.frame_container, BackupListFragment.newInstance(files, user)) EspressoIdlingResource.increment()
transaction.commit()
waitForIdleSync() transaction.replace(R.id.frame_container, BackupListFragment.newInstance(files, user))
screenshot(sut) transaction.commit()
EspressoIdlingResource.decrement()
val screenShotName = createName(testClassName + "_" + "showCalendarAndContactsList", "")
onView(isRoot()).check(matches(isDisplayed()))
screenshotViaName(sut, screenShotName)
}
}
}
} }
} }