Fixed: ZimFileReaderWithSplittedZimFileTest, SearchFragmentTest, KiwixSplashActivityTest, and KiwixSettingsFragmentTest.

This commit is contained in:
MohitMaliFtechiz 2025-08-05 00:54:05 +05:30
parent 35ae3733e7
commit a7120603f9
4 changed files with 35 additions and 33 deletions

View File

@ -119,6 +119,7 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() {
kiwixMainActivity = it
kiwixMainActivity.navigate(KiwixDestination.Library.route)
}
composeTestRule.waitForIdle()
createAndGetSplitedZimFile()?.let {
UiThreadStatement.runOnUiThread {
val navOptions = NavOptions.Builder()
@ -129,7 +130,7 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() {
navOptions
)
}
composeTestRule.waitForIdle()
navigationHistory {
checkZimFileLoadedSuccessful(composeTestRule)
clickOnReaderFragment(composeTestRule) // activate the accessibility check to check the issues.

View File

@ -46,6 +46,8 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.search.SearchFragment
import org.kiwix.kiwixmobile.core.search.viewmodel.Action
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER
@ -258,6 +260,7 @@ class SearchFragmentTest : BaseActivityTest() {
kiwixMainActivity = it
kiwixMainActivity.navigate(KiwixDestination.Library.route)
}
composeTestRule.waitForIdle()
downloadingZimFile = getDownloadingZimFile()
getOkkHttpClientForTesting().newCall(downloadRequest()).execute().use { response ->
if (response.isSuccessful) {
@ -272,38 +275,37 @@ class SearchFragmentTest : BaseActivityTest() {
}
}
openKiwixReaderFragmentWithFile(downloadingZimFile)
composeTestRule.waitForIdle()
search { checkZimFileSearchSuccessful(composeTestRule) }
openSearchWithQuery(searchTerms[0], downloadingZimFile)
// wait for searchFragment become visible on screen.
delay(2000)
// TODO refactor this with compose based navController.
// val navHostFragment: NavHostFragment =
// kiwixMainActivity.supportFragmentManager
// .findFragmentById(R.id.nav_host_fragment) as NavHostFragment
// val searchFragment = navHostFragment.childFragmentManager.fragments[0] as SearchFragment
// for (i in 1..100) {
// // This will execute the render method 100 times frequently.
// val searchTerm = searchTerms[i % searchTerms.size]
// searchFragment.searchViewModel.actions.trySend(Action.Filter(searchTerm)).isSuccess
// }
// for (i in 1..100) {
// // this will execute the render method 100 times with 100MS delay.
// delay(100)
// val searchTerm = searchTerms[i % searchTerms.size]
// searchFragment.searchViewModel.actions.trySend(Action.Filter(searchTerm)).isSuccess
// }
// for (i in 1..100) {
// // this will execute the render method 100 times with 200MS delay.
// delay(200)
// val searchTerm = searchTerms[i % searchTerms.size]
// searchFragment.searchViewModel.actions.trySend(Action.Filter(searchTerm)).isSuccess
// }
// for (i in 1..100) {
// // this will execute the render method 100 times with 200MS delay.
// delay(300)
// val searchTerm = searchTerms[i % searchTerms.size]
// searchFragment.searchViewModel.actions.trySend(Action.Filter(searchTerm)).isSuccess
// }
val searchFragment = kiwixMainActivity.supportFragmentManager.fragments
.filterIsInstance<SearchFragment>()
.firstOrNull()
for (i in 1..100) {
// This will execute the render method 100 times frequently.
val searchTerm = searchTerms[i % searchTerms.size]
searchFragment?.searchViewModel?.actions?.trySend(Action.Filter(searchTerm))?.isSuccess
}
for (i in 1..100) {
// this will execute the render method 100 times with 100MS delay.
delay(100)
val searchTerm = searchTerms[i % searchTerms.size]
searchFragment?.searchViewModel?.actions?.trySend(Action.Filter(searchTerm))?.isSuccess
}
for (i in 1..100) {
// this will execute the render method 100 times with 200MS delay.
delay(200)
val searchTerm = searchTerms[i % searchTerms.size]
searchFragment?.searchViewModel?.actions?.trySend(Action.Filter(searchTerm))?.isSuccess
}
for (i in 1..100) {
// this will execute the render method 100 times with 200MS delay.
delay(300)
val searchTerm = searchTerms[i % searchTerms.size]
searchFragment?.searchViewModel?.actions?.trySend(Action.Filter(searchTerm))?.isSuccess
}
}
private fun removeTemporaryZimFilesToFreeUpDeviceStorage() {

View File

@ -114,6 +114,7 @@ class KiwixSettingsFragmentTest {
kiwixMainActivity = it
it.navigate(KiwixDestination.Intro.route)
}
composeTestRule.waitForIdle()
intro {
swipeLeft(composeTestRule)
clickGetStarted(composeTestRule) {}

View File

@ -32,7 +32,6 @@ import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.UiDevice
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import leakcanary.LeakAssertions
import org.junit.After
import org.junit.Assert
@ -47,7 +46,6 @@ import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER
import org.kiwix.kiwixmobile.intro.composable.GET_STARTED_BUTTON_TESTING_TAG
import org.kiwix.kiwixmobile.main.KiwixMainActivity
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.isSystemUINotRespondingDialogVisible
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
@ -94,7 +92,7 @@ class KiwixSplashActivityTest {
shouldShowIntro(true)
ActivityScenario.launch(KiwixMainActivity::class.java).onActivity {
}
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
composeTestRule.waitForIdle()
testFlakyView({
composeTestRule.apply {
waitForIdle()
@ -122,7 +120,7 @@ class KiwixSplashActivityTest {
shouldShowIntro(false)
ActivityScenario.launch(KiwixMainActivity::class.java).onActivity {
}
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
composeTestRule.waitForIdle()
Intents.intended(
IntentMatchers.hasComponent(
KiwixMainActivity::class.java.canonicalName