mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Improved the background download test.
This commit is contained in:
parent
16ea02274b
commit
f99e37a017
@ -242,46 +242,55 @@ class DownloadTest : BaseActivityTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun downloadZIMFileInBackground() {
|
fun downloadZIMFileInBackground() {
|
||||||
activityScenario.onActivity {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
||||||
kiwixMainActivity = it
|
activityScenario.onActivity {
|
||||||
it.navigate(KiwixDestination.Library.route)
|
kiwixMainActivity = it
|
||||||
}
|
it.navigate(KiwixDestination.Library.route)
|
||||||
// delete all the ZIM files showing in the LocalLibrary
|
}
|
||||||
// screen to properly test the scenario.
|
// delete all the ZIM files showing in the LocalLibrary
|
||||||
library {
|
// screen to properly test the scenario.
|
||||||
refreshList(composeTestRule)
|
library {
|
||||||
waitUntilZimFilesRefreshing(composeTestRule)
|
refreshList(composeTestRule)
|
||||||
deleteZimIfExists(composeTestRule)
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
}
|
deleteZimIfExists(composeTestRule)
|
||||||
downloadRobot {
|
}
|
||||||
clickDownloadOnBottomNav(composeTestRule)
|
|
||||||
waitForDataToLoad(composeTestRule = composeTestRule)
|
|
||||||
stopDownloadIfAlreadyStarted(composeTestRule)
|
|
||||||
searchZappingSauvageFile(composeTestRule)
|
|
||||||
downloadZimFile(composeTestRule)
|
|
||||||
assertDownloadStart(composeTestRule)
|
|
||||||
}
|
|
||||||
// press the home button so that application goes into background
|
|
||||||
InstrumentationRegistry.getInstrumentation().uiAutomation.performGlobalAction(
|
|
||||||
AccessibilityService.GLOBAL_ACTION_HOME
|
|
||||||
)
|
|
||||||
// wait for 2 minutes to download the ZIM file in background.
|
|
||||||
composeTestRule.waitUntilTimeout(TWO_MINUTES_IN_MILLISECONDS.toLong())
|
|
||||||
// relaunch the application.
|
|
||||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
|
||||||
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
||||||
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
|
||||||
context.startActivity(intent)
|
|
||||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
|
||||||
activityScenario.onActivity {
|
|
||||||
kiwixMainActivity = it
|
|
||||||
it.navigate(KiwixDestination.Library.route)
|
|
||||||
}
|
|
||||||
library {
|
|
||||||
refreshList(composeTestRule)
|
|
||||||
waitUntilZimFilesRefreshing(composeTestRule)
|
|
||||||
downloadRobot {
|
downloadRobot {
|
||||||
checkIfZimFileDownloaded(composeTestRule)
|
clickDownloadOnBottomNav(composeTestRule)
|
||||||
|
waitForDataToLoad(composeTestRule = composeTestRule)
|
||||||
|
stopDownloadIfAlreadyStarted(composeTestRule)
|
||||||
|
searchZappingSauvageFile(composeTestRule)
|
||||||
|
downloadZimFile(composeTestRule)
|
||||||
|
assertDownloadStart(composeTestRule)
|
||||||
|
}
|
||||||
|
// press the home button so that application goes into background
|
||||||
|
InstrumentationRegistry.getInstrumentation().uiAutomation.performGlobalAction(
|
||||||
|
AccessibilityService.GLOBAL_ACTION_HOME
|
||||||
|
)
|
||||||
|
// wait for 2 minutes to download the ZIM file in background.
|
||||||
|
composeTestRule.waitUntilTimeout(TWO_MINUTES_IN_MILLISECONDS.toLong())
|
||||||
|
// relaunch the application.
|
||||||
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
|
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
||||||
|
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||||
|
context.startActivity(intent)
|
||||||
|
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||||
|
activityScenario.onActivity {
|
||||||
|
kiwixMainActivity = it
|
||||||
|
it.navigate(KiwixDestination.Library.route)
|
||||||
|
}
|
||||||
|
library {
|
||||||
|
refreshList(composeTestRule)
|
||||||
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
|
downloadRobot {
|
||||||
|
runCatching {
|
||||||
|
checkIfZimFileDownloaded(composeTestRule)
|
||||||
|
}.onFailure {
|
||||||
|
// if currently downloading check.
|
||||||
|
clickDownloadOnBottomNav(composeTestRule)
|
||||||
|
waitForDataToLoad(composeTestRule = composeTestRule)
|
||||||
|
stopDownloadIfAlreadyStarted(composeTestRule)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user