mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
Refactored SearchFragmentTest
* As we can not search in that zim file which is not contains the FT Xapian index and testzim.zim file is not contain it so we have improved our test case. * Now we are downloading the `off the grid` zim file and performing the search functionality inside it.
This commit is contained in:
parent
32807aa71b
commit
731b0a5843
@ -18,28 +18,27 @@
|
|||||||
package org.kiwix.kiwixmobile.search
|
package org.kiwix.kiwixmobile.search
|
||||||
|
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.test.core.app.ActivityScenario
|
import androidx.test.core.app.ActivityScenario
|
||||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.uiautomator.UiDevice
|
import androidx.test.uiautomator.UiDevice
|
||||||
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import leakcanary.LeakAssertions
|
import leakcanary.LeakAssertions
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
|
import org.kiwix.kiwixmobile.download.downloadRobot
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader
|
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.OutputStream
|
|
||||||
|
|
||||||
class SearchFragmentTest : BaseActivityTest() {
|
class SearchFragmentTest : BaseActivityTest() {
|
||||||
|
|
||||||
@ -68,40 +67,29 @@ class SearchFragmentTest : BaseActivityTest() {
|
|||||||
fun searchFragmentSimple() {
|
fun searchFragmentSimple() {
|
||||||
ActivityScenario.launch(KiwixMainActivity::class.java).onActivity {
|
ActivityScenario.launch(KiwixMainActivity::class.java).onActivity {
|
||||||
kiwixMainActivity = it
|
kiwixMainActivity = it
|
||||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
|
||||||
}
|
}
|
||||||
val loadFileStream =
|
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
|
||||||
SearchFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
|
try {
|
||||||
val zimFile = File(context.cacheDir, "testzim.zim")
|
downloadRobot {
|
||||||
if (zimFile.exists()) zimFile.delete()
|
clickLibraryOnBottomNav()
|
||||||
zimFile.createNewFile()
|
deleteZimIfExists(false)
|
||||||
loadFileStream.use { inputStream ->
|
clickDownloadOnBottomNav()
|
||||||
val outputStream: OutputStream = FileOutputStream(zimFile)
|
waitForDataToLoad()
|
||||||
outputStream.use { it ->
|
downloadZimFile()
|
||||||
val buffer = ByteArray(inputStream.available())
|
assertDownloadStart()
|
||||||
var length: Int
|
waitUntilDownloadComplete()
|
||||||
while (inputStream.read(buffer).also { length = it } > 0) {
|
clickLibraryOnBottomNav()
|
||||||
it.write(buffer, 0, length)
|
checkIfZimFileDownloaded()
|
||||||
}
|
downloadZimFile()
|
||||||
}
|
}
|
||||||
}
|
} catch (e: Exception) {
|
||||||
UiThreadStatement.runOnUiThread {
|
Assert.fail(
|
||||||
kiwixMainActivity.navigate(
|
"Couldn't find downloaded file ' Off the Grid ' Original Exception: ${e.message}"
|
||||||
actionNavigationLibraryToNavigationReader()
|
|
||||||
.apply { zimFileUri = zimFile.toUri().toString() }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
search { checkZimFileSearchSuccessful(R.id.readerFragment) }
|
search { checkZimFileSearchSuccessful(R.id.readerFragment) }
|
||||||
UiThreadStatement.runOnUiThread {
|
UiThreadStatement.runOnUiThread {
|
||||||
if (zimFile.canRead()) {
|
kiwixMainActivity.openSearch(searchString = "100R")
|
||||||
kiwixMainActivity.openSearch(searchString = "Android")
|
|
||||||
} else {
|
|
||||||
throw RuntimeException(
|
|
||||||
"File $zimFile is not readable." +
|
|
||||||
" Original File $zimFile is readable = ${zimFile.canRead()}" +
|
|
||||||
" Size ${zimFile.length()}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
search {
|
search {
|
||||||
clickOnSearchItemInSearchList()
|
clickOnSearchItemInSearchList()
|
||||||
|
@ -18,6 +18,11 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.search
|
package org.kiwix.kiwixmobile.search
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.test.espresso.Espresso.onView
|
||||||
|
import androidx.test.espresso.action.ViewActions.click
|
||||||
|
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||||
import applyWithViewHierarchyPrinting
|
import applyWithViewHierarchyPrinting
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import org.kiwix.kiwixmobile.BaseRobot
|
import org.kiwix.kiwixmobile.BaseRobot
|
||||||
@ -32,7 +37,12 @@ class SearchRobot : BaseRobot() {
|
|||||||
fun clickOnSearchItemInSearchList() {
|
fun clickOnSearchItemInSearchList() {
|
||||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
|
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
|
||||||
isVisible(ViewId(R.id.search_list))
|
isVisible(ViewId(R.id.search_list))
|
||||||
clickOn(ViewId(R.id.list_item_search_text))
|
onView(withId(R.id.search_list)).perform(
|
||||||
|
actionOnItemAtPosition<RecyclerView.ViewHolder>(
|
||||||
|
0,
|
||||||
|
click()
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkZimFileSearchSuccessful(readerFragment: Int) {
|
fun checkZimFileSearchSuccessful(readerFragment: Int) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user