mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 19:35:36 -04:00
Fixed: The search fragment test was failing in both the custom and app modules due to a socket exception during the ZIM file download.
This commit is contained in:
parent
5c25b20ad7
commit
a7f662fe45
@ -33,7 +33,6 @@ import com.google.android.apps.common.testing.accessibility.framework.Accessibil
|
||||
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews
|
||||
import com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck
|
||||
import leakcanary.LeakAssertions
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.ResponseBody
|
||||
import org.hamcrest.Matchers.allOf
|
||||
@ -50,6 +49,7 @@ import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirecti
|
||||
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.getOkkHttpClientForTesting
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@ -147,7 +147,7 @@ class KiwixReaderFragmentTest : BaseActivityTest() {
|
||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
||||
}
|
||||
val downloadingZimFile = getDownloadingZimFile()
|
||||
OkHttpClient().newCall(downloadRequest()).execute().use { response ->
|
||||
getOkkHttpClientForTesting().newCall(downloadRequest()).execute().use { response ->
|
||||
if (response.isSuccessful) {
|
||||
response.body?.let { responseBody ->
|
||||
writeZimFileData(responseBody, downloadingZimFile)
|
||||
|
@ -36,7 +36,6 @@ import com.google.android.apps.common.testing.accessibility.framework.checks.Tou
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import leakcanary.LeakAssertions
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.ResponseBody
|
||||
import org.hamcrest.Matchers.allOf
|
||||
@ -57,6 +56,7 @@ import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirecti
|
||||
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.getOkkHttpClientForTesting
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@ -169,7 +169,7 @@ class SearchFragmentTest : BaseActivityTest() {
|
||||
UiThreadStatement.runOnUiThread { kiwixMainActivity.navigate(R.id.libraryFragment) }
|
||||
// test with a large ZIM file to properly test the scenario
|
||||
downloadingZimFile = getDownloadingZimFile()
|
||||
OkHttpClient().newCall(downloadRequest()).execute().use { response ->
|
||||
getOkkHttpClientForTesting().newCall(downloadRequest()).execute().use { response ->
|
||||
if (response.isSuccessful) {
|
||||
response.body?.let { responseBody ->
|
||||
writeZimFileData(responseBody, downloadingZimFile)
|
||||
@ -242,7 +242,7 @@ class SearchFragmentTest : BaseActivityTest() {
|
||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
||||
}
|
||||
downloadingZimFile = getDownloadingZimFile()
|
||||
OkHttpClient().newCall(downloadRequest()).execute().use { response ->
|
||||
getOkkHttpClientForTesting().newCall(downloadRequest()).execute().use { response ->
|
||||
if (response.isSuccessful) {
|
||||
response.body?.let { responseBody ->
|
||||
writeZimFileData(responseBody, downloadingZimFile)
|
||||
|
@ -37,8 +37,14 @@ import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.UiObject
|
||||
import androidx.test.uiautomator.UiObjectNotFoundException
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import okhttp3.OkHttpClient
|
||||
import org.hamcrest.Description
|
||||
import org.hamcrest.Matcher
|
||||
import org.kiwix.kiwixmobile.core.data.remote.UserAgentInterceptor
|
||||
import org.kiwix.kiwixmobile.core.di.modules.CALL_TIMEOUT
|
||||
import org.kiwix.kiwixmobile.core.di.modules.CONNECTION_TIMEOUT
|
||||
import org.kiwix.kiwixmobile.core.di.modules.READ_TIMEOUT
|
||||
import org.kiwix.kiwixmobile.core.di.modules.USER_AGENT
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||
import org.kiwix.kiwixmobile.core.utils.files.Log
|
||||
import java.io.File
|
||||
@ -47,6 +53,8 @@ import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Created by mhutti1 on 07/04/17.
|
||||
@ -234,4 +242,16 @@ object TestUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Singleton
|
||||
fun getOkkHttpClientForTesting(): OkHttpClient =
|
||||
OkHttpClient().newBuilder()
|
||||
.followRedirects(true)
|
||||
.followSslRedirects(true)
|
||||
.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
|
||||
.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS)
|
||||
.addNetworkInterceptor(UserAgentInterceptor(USER_AGENT))
|
||||
.build()
|
||||
}
|
||||
|
@ -43,6 +43,11 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.kiwix.kiwixmobile.core.data.remote.UserAgentInterceptor
|
||||
import org.kiwix.kiwixmobile.core.di.modules.CALL_TIMEOUT
|
||||
import org.kiwix.kiwixmobile.core.di.modules.CONNECTION_TIMEOUT
|
||||
import org.kiwix.kiwixmobile.core.di.modules.READ_TIMEOUT
|
||||
import org.kiwix.kiwixmobile.core.di.modules.USER_AGENT
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
||||
import org.kiwix.kiwixmobile.core.search.SearchFragment
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.Action
|
||||
@ -58,6 +63,8 @@ import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.net.URI
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Singleton
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class SearchFragmentTestForCustomApp {
|
||||
@ -123,7 +130,7 @@ class SearchFragmentTestForCustomApp {
|
||||
}
|
||||
// test with a large ZIM file to properly test the scenario
|
||||
downloadingZimFile = getDownloadingZimFile()
|
||||
OkHttpClient().newCall(downloadRequest()).execute().use { response ->
|
||||
getOkkHttpClientForTesting().newCall(downloadRequest()).execute().use { response ->
|
||||
if (response.isSuccessful) {
|
||||
response.body?.let { responseBody ->
|
||||
writeZimFileData(responseBody, downloadingZimFile)
|
||||
@ -201,7 +208,7 @@ class SearchFragmentTestForCustomApp {
|
||||
}
|
||||
// test with a large ZIM file to properly test the scenario
|
||||
downloadingZimFile = getDownloadingZimFile()
|
||||
OkHttpClient().newCall(downloadRequest()).execute().use { response ->
|
||||
getOkkHttpClientForTesting().newCall(downloadRequest()).execute().use { response ->
|
||||
if (response.isSuccessful) {
|
||||
response.body?.let { responseBody ->
|
||||
writeZimFileData(responseBody, downloadingZimFile)
|
||||
@ -321,6 +328,17 @@ class SearchFragmentTestForCustomApp {
|
||||
return zimFile
|
||||
}
|
||||
|
||||
@Singleton
|
||||
private fun getOkkHttpClientForTesting(): OkHttpClient =
|
||||
OkHttpClient().newBuilder()
|
||||
.followRedirects(true)
|
||||
.followSslRedirects(true)
|
||||
.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
|
||||
.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS)
|
||||
.addNetworkInterceptor(UserAgentInterceptor(USER_AGENT))
|
||||
.build()
|
||||
|
||||
@After
|
||||
fun finish() {
|
||||
TestUtils.deleteTemporaryFilesOfTestCases(context)
|
||||
|
Loading…
x
Reference in New Issue
Block a user