From 0fe6dd4dbc527c8775c3d74274a022ffd4f9b17d Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 16 Aug 2024 12:49:20 +0530 Subject: [PATCH] Improved SearchFragmentTest which sometimes failing on API level 34. * Improved the SearchStateTest which sometimes failing. --- .../kiwixmobile/search/SearchFragmentTest.kt | 22 ++++++++++++++----- .../core/search/viewmodel/SearchStateTest.kt | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt index 53c88dbe0..5f830e798 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt @@ -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 } } diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt index a3af0415d..f5c7121f8 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt @@ -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"