Skip to content

Commit

Permalink
Improved ObjectBoxToLibkiwixMigratorTest for clearing the previous …
Browse files Browse the repository at this point in the history
…saved bookmarks.

* Refresh the data before checking the loaded data in DownloadTest.
* Increasing the Retry count for loading data and downloading start to properly work with low internet connection.
  • Loading branch information
MohitMaliDeveloper committed Mar 13, 2024
1 parent e21a89a commit 6c2bbdb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
)
}
box = boxStore.boxFor(BookmarkEntity::class.java)
// clear the data before running the test case
clearBookmarks()

// add a file in fileSystem because we need to actual file path for making object of Archive.
val loadFileStream =
Expand All @@ -139,9 +141,6 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
}
}
}

// clear the data before running the test case
clearBookmarks()
}

@Test
Expand Down Expand Up @@ -310,7 +309,9 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
.blockingFirst() as List<LibkiwixBookmarkItem>
)
box.removeAll()
zimFile.delete() // delete the temp ZIM file to free up the memory
if (::zimFile.isInitialized) {
zimFile.delete() // delete the temp ZIM file to free up the memory
}
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fun downloadRobot(func: DownloadRobot.() -> Unit) =

class DownloadRobot : BaseRobot() {

private var retryCountForDataToLoad = 5
private var retryCountForCheckDownloadStart = 5
private var retryCountForDataToLoad = 10
private var retryCountForCheckDownloadStart = 10
private val zimFileTitle = "Off the Grid"

fun clickLibraryOnBottomNav() {
Expand All @@ -69,6 +69,10 @@ class DownloadRobot : BaseRobot() {
isVisible(Text(zimFileTitle))
}

fun refreshOnlineList() {
refresh(R.id.librarySwipeRefresh)
}

fun downloadZimFile() {
clickOn(Text(zimFileTitle))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class DownloadTest : BaseActivityTest() {
}
downloadRobot {
clickDownloadOnBottomNav()
refreshOnlineList()
waitForDataToLoad()
stopDownloadIfAlreadyStarted()
downloadZimFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ fun initialDownload(func: InitialDownloadRobot.() -> Unit) =

class InitialDownloadRobot : BaseRobot() {

private var retryCountForCheckDownloadStart = 5
private var retryCountForCheckDataLoaded = 5
private var retryCountForCheckDownloadStart = 10
private var retryCountForCheckDataLoaded = 10
private val zimFileTitle = "Off the Grid"

fun clickLibraryOnBottomNav() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ package org.kiwix.kiwixmobile.language
import android.Manifest
import android.app.Instrumentation
import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
Expand All @@ -46,9 +47,6 @@ class LanguageFragmentTest {
@JvmField
var retryRule = RetryRule()

@get:Rule
var activityScenarioRule = ActivityScenarioRule(KiwixMainActivity::class.java)

private val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
Expand Down Expand Up @@ -77,6 +75,9 @@ class LanguageFragmentTest {
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
}
ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun language(func: LanguageRobot.() -> Unit) = LanguageRobot().applyWithViewHier

class LanguageRobot : BaseRobot() {

private var retryCountForDataToLoad = 5
private var retryCountForDataToLoad = 10

fun clickDownloadOnBottomNav() {
clickOn(ViewId(R.id.downloadsFragment))
Expand Down

0 comments on commit 6c2bbdb

Please sign in to comment.