Skip to content

Commit

Permalink
Improved DownloadTest and InitialDownloadTest which sometimes fai…
Browse files Browse the repository at this point in the history
…ling due to `file_management_no_files` view not error.

* Improved ObjectBoxToLibkiwixMigratorTest which sometime crashed due to process crashing.
  • Loading branch information
MohitMaliDeveloper committed Mar 19, 2024
1 parent ff5b09d commit 2ccd8fe
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import io.objectbox.Box
import io.objectbox.BoxStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
Expand Down Expand Up @@ -160,10 +158,8 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedFavicon
)
box.put(bookmarkEntity)
withContext(Dispatchers.Main) {
// migrate data into room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
// migrate data into room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
// check if data successfully migrated to room
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
Expand All @@ -176,10 +172,8 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {

@Test
fun testMigrationWithEmptyData(): Unit = runBlocking {
withContext(Dispatchers.Main) {
// Migrate data from empty ObjectBox database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
// Migrate data from empty ObjectBox database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertTrue(actualDataAfterMigration.isEmpty())
Expand All @@ -200,19 +194,15 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedFavicon
)
val libkiwixBook = Book()
withContext(Dispatchers.Main) {
objectBoxToLibkiwixMigrator.libkiwixBookmarks.saveBookmark(
LibkiwixBookmarkItem(
secondBookmarkEntity,
libkiwixBook
)
objectBoxToLibkiwixMigrator.libkiwixBookmarks.saveBookmark(
LibkiwixBookmarkItem(
secondBookmarkEntity,
libkiwixBook
)
box.put(bookmarkEntity)
}
withContext(Dispatchers.Main) {
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
)
box.put(bookmarkEntity)
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertEquals(2, actualDataAfterMigration.size)
Expand Down Expand Up @@ -244,10 +234,8 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
)
)
}
withContext(Dispatchers.Main) {
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
// Check if data successfully migrated to Room
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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.nav.destination.library.library
Expand Down Expand Up @@ -81,11 +82,11 @@ class DownloadTest : BaseActivityTest() {
@Test
fun downloadTest() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
activityScenario.onActivity {
it.navigate(R.id.libraryFragment)
}
try {
downloadRobot {
clickLibraryOnBottomNav()
refreshLocalLibraryData()
}
downloadRobot(DownloadRobot::refreshLocalLibraryData)
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class InitialDownloadRobot : BaseRobot() {
private var retryCountForCheckDataLoaded = 10
private val zimFileTitle = "Off the Grid"

fun clickLibraryOnBottomNav() {
clickOn(ViewId(R.id.libraryFragment))
}

fun clickDownloadOnBottomNav() {
clickOn(ViewId(R.id.downloadsFragment))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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.nav.destination.library.library
Expand Down Expand Up @@ -74,10 +75,10 @@ class InitialDownloadTest : BaseActivityTest() {
@Test
fun initialDownloadTest() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
initialDownload {
clickLibraryOnBottomNav()
refreshLocalLibraryData()
activityScenario.onActivity {
it.navigate(R.id.libraryFragment)
}
initialDownload(InitialDownloadRobot::refreshLocalLibraryData)
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
Expand Down

0 comments on commit 2ccd8fe

Please sign in to comment.