mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-21 11:28:56 -04:00
Fixed the ZimManageViewModelTest.
This commit is contained in:
parent
318ae98d31
commit
476733bf91
@ -129,6 +129,7 @@ class ZimManageViewModel @Inject constructor(
|
||||
object UserClickedDownloadBooksButton : FileSelectActions()
|
||||
}
|
||||
|
||||
private var isUnitTestCase: Boolean = false
|
||||
val sideEffects = PublishProcessor.create<SideEffect<Any?>>()
|
||||
val libraryItems: MutableLiveData<List<LibraryListItem>> = MutableLiveData()
|
||||
val fileSelectListStates: MutableLiveData<FileSelectListState> = MutableLiveData()
|
||||
@ -150,7 +151,12 @@ class ZimManageViewModel @Inject constructor(
|
||||
context.registerReceiver(connectivityBroadcastReceiver)
|
||||
}
|
||||
|
||||
fun setIsUnitTestCase() {
|
||||
isUnitTestCase = true
|
||||
}
|
||||
|
||||
private fun createKiwixServiceWithProgressListener(): KiwixService {
|
||||
if (isUnitTestCase) return kiwixService
|
||||
val contentLength = getContentLengthOfLibraryXmlFile()
|
||||
val customOkHttpClient = OkHttpClient().newBuilder()
|
||||
.followRedirects(true)
|
||||
@ -178,6 +184,9 @@ class ZimManageViewModel @Inject constructor(
|
||||
}
|
||||
.build()
|
||||
return KiwixService.ServiceCreator.newHackListService(customOkHttpClient, KIWIX_DOWNLOAD_URL)
|
||||
.also {
|
||||
kiwixService = it
|
||||
}
|
||||
}
|
||||
|
||||
private fun getContentLengthOfLibraryXmlFile(): Long {
|
||||
@ -327,7 +336,12 @@ class ZimManageViewModel @Inject constructor(
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.concatMap {
|
||||
createKiwixServiceWithProgressListener().library
|
||||
Flowable.fromCallable {
|
||||
synchronized(this, ::createKiwixServiceWithProgressListener)
|
||||
}
|
||||
}
|
||||
.concatMap {
|
||||
kiwixService.library
|
||||
.toFlowable()
|
||||
.retry(5)
|
||||
.doOnSubscribe {
|
||||
@ -347,7 +361,9 @@ class ZimManageViewModel @Inject constructor(
|
||||
LibraryNetworkEntity().apply { book = LinkedList() }
|
||||
}
|
||||
}
|
||||
.subscribe(library::onNext, Throwable::printStackTrace)
|
||||
.subscribe(library::onNext, Throwable::printStackTrace).also {
|
||||
compositeDisposable?.add(it)
|
||||
}
|
||||
|
||||
private fun updateNetworkStates() =
|
||||
connectivityBroadcastReceiver.networkStates.subscribe(
|
||||
|
@ -157,7 +157,7 @@ class ZimManageViewModelTest {
|
||||
dataSource,
|
||||
connectivityManager,
|
||||
sharedPreferenceUtil
|
||||
)
|
||||
).apply(ZimManageViewModel::setIsUnitTestCase)
|
||||
testScheduler.triggerActions()
|
||||
}
|
||||
|
||||
@ -333,6 +333,7 @@ class ZimManageViewModelTest {
|
||||
defaultLanguage: Language
|
||||
) {
|
||||
every { application.getString(any()) } returns ""
|
||||
every { application.getString(any(), any()) } returns ""
|
||||
every { kiwixService.library } returns Single.just(
|
||||
libraryNetworkEntity(networkBooks)
|
||||
)
|
||||
@ -372,6 +373,8 @@ class ZimManageViewModelTest {
|
||||
language = "inactiveLanguage",
|
||||
url = ""
|
||||
)
|
||||
every { application.getString(any()) } returns ""
|
||||
every { application.getString(any(), any()) } returns ""
|
||||
every { kiwixService.library } returns Single.just(
|
||||
libraryNetworkEntity(
|
||||
listOf(
|
||||
@ -412,6 +415,8 @@ class ZimManageViewModelTest {
|
||||
url = "",
|
||||
size = "${Fat32Checker.FOUR_GIGABYTES_IN_KILOBYTES + 1}"
|
||||
)
|
||||
every { application.getString(any()) } returns ""
|
||||
every { application.getString(any(), any()) } returns ""
|
||||
every { kiwixService.library } returns Single.just(
|
||||
libraryNetworkEntity(
|
||||
listOf(bookOver4Gb)
|
||||
|
@ -288,7 +288,7 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
||||
}
|
||||
|
||||
fun getPublicDirectoryPath(path: String): String =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
path
|
||||
} else {
|
||||
path.substringBefore(context.getString(R.string.android_directory_seperator))
|
||||
|
Loading…
x
Reference in New Issue
Block a user