Improved SearchFragmentTest which sometimes failing on API level 34.

* Improved the SearchStateTest which sometimes failing.
This commit is contained in:
MohitMaliFtechiz 2024-08-16 12:49:20 +05:30 committed by Kelson
parent 07cca85c95
commit 0fe6dd4dbc
2 changed files with 17 additions and 7 deletions

View File

@ -226,7 +226,19 @@ class SearchFragmentTest : BaseActivityTest() {
kiwixMainActivity = it
kiwixMainActivity.navigate(R.id.libraryFragment)
}
downloadingZimFile = getDownloadingZimFile(false)
downloadingZimFile = getDownloadingZimFile()
OkHttpClient().newCall(downloadRequest()).execute().use { response ->
if (response.isSuccessful) {
response.body?.let { responseBody ->
writeZimFileData(responseBody, downloadingZimFile)
}
} else {
throw RuntimeException(
"Download Failed. Error: ${response.message}\n" +
" Status Code: ${response.code}"
)
}
}
openKiwixReaderFragmentWithFile(downloadingZimFile)
search { checkZimFileSearchSuccessful(R.id.readerFragment) }
openSearchWithQuery(searchTerms[0], downloadingZimFile)
@ -328,12 +340,10 @@ class SearchFragmentTest : BaseActivityTest() {
return zimFile
}
private fun getDownloadingZimFile(isDeletePreviousZimFile: Boolean = true): File {
private fun getDownloadingZimFile(): File {
val zimFile = File(context.cacheDir, "ray_charles.zim")
if (isDeletePreviousZimFile) {
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
}
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
return zimFile
}
}

View File

@ -109,7 +109,7 @@ internal class SearchStateTest {
val searchIteratorWrapper: SuggestionIteratorWrapper = mockk()
val entryWrapper: SuggestionItemWrapper = mockk()
every { suggestionSearchWrapper.estimatedMatches } returns 100
every { suggestionSearchWrapper.estimatedMatches } returns 500
every { searchIteratorWrapper.hasNext() } returnsMany listOf(true, false)
every { searchIteratorWrapper.next() } returns entryWrapper
every { entryWrapper.title } returns "Result"