From 8b446a5200fb7dce16212a914c63bf7a23ca07e0 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 6 Aug 2025 17:37:30 +0530 Subject: [PATCH] Refactored the OpenSearchItemTest unit test. * Fixed: ZimHostFragmentTest UI test. --- .../kiwixmobile/webserver/ZimHostFragmentTest.kt | 2 +- .../kiwix/kiwixmobile/webserver/ZimHostRobot.kt | 14 +++++++++++--- .../search/viewmodel/effects/OpenSearchItemTest.kt | 12 +++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt index 4244fad51..bcaff8873 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt @@ -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) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt index 940c126d8..a5e0cef92 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt @@ -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) { diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItemTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItemTest.kt index f943978b4..863bf9f38 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItemTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItemTest.kt @@ -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()) + activity.navigate( + "${activity.readerFragmentRoute}?searchItemTitle=searchItemTitle", + any() + ) 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()) + activity.navigate( + "${activity.readerFragmentRoute}?searchItemTitle=searchItemTitle", + any() + ) activity.setNavigationResultOnCurrent( SearchItemToOpen(searchListItem.value, true, ZimFileReader.CONTENT_PREFIX), TAG_FILE_SEARCHED