mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Fixed: Test cases are frequently failing on API level 33.
* Refreshed the ZIM files list before deleting/checking for downloaded ZIM files in `DownloadTest` and `InitialDownloadTest` because sometimes data doesn't show on the `LocalLibraryScreen` after downloading the ZIM file, leading to test failures. * Hiding the `Storage Restriction` dialog in `LibkiwixBookTest` and `MimeTypeTest` to not show this dialog in these test cases. * Improved the temporary ZIM file path in `NoteFragmentTest` to properly display the ZIM file in the LocalLibrary screen so that it can be deleted in our test case. * Enhanced the loading of ZIM files in `LocalLibraryTest`.
This commit is contained in:
parent
28945412f3
commit
291a063747
@ -28,11 +28,13 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import applyWithViewHierarchyPrinting
|
||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
||||
import junit.framework.AssertionFailedError
|
||||
import org.kiwix.kiwixmobile.BaseRobot
|
||||
import org.kiwix.kiwixmobile.Findable.Text
|
||||
import org.kiwix.kiwixmobile.Findable.ViewId
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.download.DownloadTest.Companion.KIWIX_DOWNLOAD_TEST
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||
|
||||
fun downloadRobot(func: DownloadRobot.() -> Unit) =
|
||||
@ -185,4 +187,13 @@ class DownloadRobot : BaseRobot() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshLocalLibraryData() {
|
||||
try {
|
||||
refresh(R.id.zim_swiperefresh)
|
||||
pauseForBetterTestPerformance()
|
||||
} catch (e: RuntimeException) {
|
||||
Log.w(KIWIX_DOWNLOAD_TEST, "Failed to refresh ZIM list: " + e.localizedMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.download
|
||||
|
||||
import android.util.Log
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.preference.PreferenceManager
|
||||
@ -29,7 +28,6 @@ import androidx.test.filters.LargeTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
||||
import leakcanary.LeakAssertions
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
@ -39,7 +37,6 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||
@ -86,6 +83,7 @@ class DownloadTest : BaseActivityTest() {
|
||||
try {
|
||||
downloadRobot {
|
||||
clickLibraryOnBottomNav()
|
||||
refreshLocalLibraryData()
|
||||
deleteZimIfExists(false)
|
||||
clickDownloadOnBottomNav()
|
||||
waitForDataToLoad()
|
||||
@ -98,19 +96,17 @@ class DownloadTest : BaseActivityTest() {
|
||||
assertDownloadResumed()
|
||||
waitUntilDownloadComplete()
|
||||
clickLibraryOnBottomNav()
|
||||
// refresh the local library list to show the downloaded zim file
|
||||
refreshLocalLibraryData()
|
||||
checkIfZimFileDownloaded()
|
||||
deleteZimIfExists(true)
|
||||
refreshLocalLibraryData()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Assert.fail(
|
||||
"Couldn't find downloaded file ' Off the Grid ' Original Exception: ${e.message}"
|
||||
)
|
||||
}
|
||||
try {
|
||||
refresh(R.id.zim_swiperefresh)
|
||||
} catch (e: RuntimeException) {
|
||||
Log.w(KIWIX_DOWNLOAD_TEST, "Failed to refresh ZIM list: " + e.localizedMessage)
|
||||
}
|
||||
LeakAssertions.assertNoLeaks()
|
||||
}
|
||||
|
||||
@ -124,7 +120,7 @@ class DownloadTest : BaseActivityTest() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KIWIX_DOWNLOAD_TEST = "kiwixDownloadTest"
|
||||
const val KIWIX_DOWNLOAD_TEST = "kiwixDownloadTest"
|
||||
|
||||
@BeforeClass
|
||||
fun beforeClass() {
|
||||
|
@ -91,10 +91,19 @@ class InitialDownloadRobot : BaseRobot() {
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshList() {
|
||||
fun refreshOnlineList() {
|
||||
refresh(R.id.librarySwipeRefresh)
|
||||
}
|
||||
|
||||
fun refreshLocalLibraryData() {
|
||||
try {
|
||||
refresh(R.id.zim_swiperefresh)
|
||||
pauseForBetterTestPerformance()
|
||||
} catch (e: RuntimeException) {
|
||||
Log.w("InitialDownloadTest", "Failed to refresh ZIM list: " + e.localizedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
fun waitForDataToLoad() {
|
||||
try {
|
||||
isVisible(Text(zimFileTitle))
|
||||
|
@ -75,11 +75,12 @@ class InitialDownloadTest : BaseActivityTest() {
|
||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
|
||||
initialDownload {
|
||||
clickLibraryOnBottomNav()
|
||||
refreshLocalLibraryData()
|
||||
// This is for if download test fails for some reason after downloading the zim file
|
||||
deleteZimIfExists()
|
||||
clickDownloadOnBottomNav()
|
||||
assertLibraryListDisplayed()
|
||||
refreshList()
|
||||
refreshOnlineList()
|
||||
waitForDataToLoad()
|
||||
stopDownloadIfAlreadyStarted()
|
||||
downloadZimFile()
|
||||
|
@ -27,7 +27,6 @@ import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.libzim.Archive
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.core.NightModeConfig
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
@ -35,6 +34,7 @@ import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||
import org.kiwix.libzim.Archive
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
@ -53,6 +53,7 @@ class MimeTypeTest : BaseActivityTest() {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
|
||||
}
|
||||
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
|
||||
moveToState(Lifecycle.State.RESUMED)
|
||||
|
@ -34,7 +34,6 @@ import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
import org.kiwix.kiwixmobile.search.SearchFragmentTest
|
||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||
@ -88,7 +87,7 @@ class LocalLibraryTest : BaseActivityTest() {
|
||||
}
|
||||
// load a zim file to test, After downloading zim file library list is visible or not
|
||||
val loadFileStream =
|
||||
SearchFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
|
||||
LocalLibraryTest::class.java.classLoader.getResourceAsStream("testzim.zim")
|
||||
val zimFile =
|
||||
File(
|
||||
ContextCompat.getExternalFilesDirs(context, null)[0],
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.note
|
||||
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.Lifecycle
|
||||
@ -93,7 +94,10 @@ class NoteFragmentTest : BaseActivityTest() {
|
||||
|
||||
val loadFileStream =
|
||||
NoteFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
|
||||
val zimFile = File(context.cacheDir, "testzim.zim")
|
||||
val zimFile = File(
|
||||
ContextCompat.getExternalFilesDirs(context, null)[0],
|
||||
"testzim.zim"
|
||||
)
|
||||
if (zimFile.exists()) zimFile.delete()
|
||||
zimFile.createNewFile()
|
||||
loadFileStream.use { inputStream ->
|
||||
|
@ -60,6 +60,7 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
|
||||
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
|
||||
}
|
||||
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
|
||||
moveToState(Lifecycle.State.RESUMED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user