Refactored the OpenSearchItemTest unit test.

* Fixed: ZimHostFragmentTest UI test.
This commit is contained in:
MohitMaliFtechiz 2025-08-06 17:37:30 +05:30
parent 7b03c5da3e
commit 8b446a5200
3 changed files with 21 additions and 7 deletions

View File

@ -162,7 +162,7 @@ class ZimHostFragmentTest {
zimHost {
refreshLibraryList(composeTestRule)
assertZimFilesLoaded(composeTestRule)
openZimHostFragment(kiwixMainActivity as CoreMainActivity)
openZimHostFragment(kiwixMainActivity as CoreMainActivity, composeTestRule)
// Check if server is already started
stopServerIfAlreadyStarted(composeTestRule)

View File

@ -31,9 +31,9 @@ import applyWithViewHierarchyPrinting
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import junit.framework.AssertionFailedError
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_ZIM_HOST_ITEM_TESTING_TAG
import org.kiwix.kiwixmobile.core.ui.components.TOOLBAR_TITLE_TESTING_TAG
import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_NATURAL_BUTTON_TESTING_TAG
import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_TITLE_TEXT_TESTING_TAG
@ -69,9 +69,17 @@ class ZimHostRobot : BaseRobot() {
zimFileNodes.assertCountEquals(2)
}
fun openZimHostFragment(coreMainActivity: CoreMainActivity) {
fun openZimHostFragment(
coreMainActivity: CoreMainActivity,
composeTestRule: ComposeContentTestRule
) {
openDrawer(coreMainActivity)
clickOn(TextId(R.string.menu_wifi_hotspot))
testFlakyView({
composeTestRule.apply {
waitForIdle()
onNodeWithTag(LEFT_DRAWER_ZIM_HOST_ITEM_TESTING_TAG).performClick()
}
})
}
fun clickOnTestZim(composeTestRule: ComposeContentTestRule) {

View File

@ -19,7 +19,7 @@
package org.kiwix.kiwixmobile.core.search.viewmodel.effects
import android.content.Intent
import android.os.Bundle
import androidx.navigation.NavOptions
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkConstructor
@ -45,7 +45,10 @@ internal class OpenSearchItemTest {
} returns intent
OpenSearchItem(searchListItem, false).invokeWith(activity)
verify {
activity.navigate(activity.readerFragmentResId, any<Bundle>())
activity.navigate(
"${activity.readerFragmentRoute}?searchItemTitle=searchItemTitle",
any<NavOptions>()
)
activity.setNavigationResultOnCurrent(
SearchItemToOpen(searchListItem.value, false, ZimFileReader.CONTENT_PREFIX),
TAG_FILE_SEARCHED
@ -65,7 +68,10 @@ internal class OpenSearchItemTest {
} returns intent
OpenSearchItem(searchListItem, true).invokeWith(activity)
verify {
activity.navigate(activity.readerFragmentResId, any<Bundle>())
activity.navigate(
"${activity.readerFragmentRoute}?searchItemTitle=searchItemTitle",
any<NavOptions>()
)
activity.setNavigationResultOnCurrent(
SearchItemToOpen(searchListItem.value, true, ZimFileReader.CONTENT_PREFIX),
TAG_FILE_SEARCHED