We improved the DeppLinksTest to test this functionality, so that we can avoid this type of error in the future.

This commit is contained in:
MohitMaliFtechiz 2024-09-20 22:22:35 +05:30
parent 4e86558b0e
commit 7078aad77a

View File

@ -20,9 +20,13 @@ package org.kiwix.kiwixmobile.deeplinks
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.accessibility.AccessibilityChecks import androidx.test.espresso.accessibility.AccessibilityChecks
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import org.junit.Before import org.junit.Before
@ -31,11 +35,13 @@ import org.junit.Test
import org.junit.jupiter.api.fail import org.junit.jupiter.api.fail
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.R.string
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.page.history.navigationHistory import org.kiwix.kiwixmobile.page.history.navigationHistory
import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.RetryRule
import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.OutputStream import java.io.OutputStream
@ -76,6 +82,7 @@ class DeepLinksTest : BaseActivityTest() {
loadZimFileInApplicationAndReturnSchemeTypeUri("file")?.let { loadZimFileInApplicationAndReturnSchemeTypeUri("file")?.let {
// Launch the activity to test the deep link // Launch the activity to test the deep link
ActivityScenario.launch<KiwixMainActivity>(createDeepLinkIntent(it)).onActivity {} ActivityScenario.launch<KiwixMainActivity>(createDeepLinkIntent(it)).onActivity {}
clickOnCopy()
navigationHistory { navigationHistory {
checkZimFileLoadedSuccessful(R.id.readerFragment) checkZimFileLoadedSuccessful(R.id.readerFragment)
assertZimFileLoaded() // check if the zim file successfully loaded assertZimFileLoaded() // check if the zim file successfully loaded
@ -87,11 +94,20 @@ class DeepLinksTest : BaseActivityTest() {
} }
} }
private fun clickOnCopy() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
testFlakyView({
onView(withText(string.action_copy)).perform(click())
})
}
}
@Test @Test
fun contentTypeDeepLinkTest() { fun contentTypeDeepLinkTest() {
loadZimFileInApplicationAndReturnSchemeTypeUri("content")?.let { loadZimFileInApplicationAndReturnSchemeTypeUri("content")?.let {
// Launch the activity to test the deep link // Launch the activity to test the deep link
ActivityScenario.launch<KiwixMainActivity>(createDeepLinkIntent(it)).onActivity {} ActivityScenario.launch<KiwixMainActivity>(createDeepLinkIntent(it)).onActivity {}
clickOnCopy()
navigationHistory { navigationHistory {
checkZimFileLoadedSuccessful(R.id.readerFragment) checkZimFileLoadedSuccessful(R.id.readerFragment)
assertZimFileLoaded() // check if the zim file successfully loaded assertZimFileLoaded() // check if the zim file successfully loaded