diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt index 90dd75a60..d748c9309 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt @@ -43,7 +43,6 @@ import org.junit.Rule import org.junit.Test import org.junit.jupiter.api.fail import org.kiwix.kiwixmobile.BaseActivityTest -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER @@ -110,7 +109,7 @@ class DeepLinksTest : BaseActivityTest() { ActivityScenario.launch(createDeepLinkIntent(it)).onActivity {} clickOnCopy(composeTestRule) navigationHistory { - checkZimFileLoadedSuccessful(R.id.readerFragment) + checkZimFileLoadedSuccessful(composeTestRule) assertZimFileLoaded() // check if the zim file successfully loaded clickOnAndroidArticle() } @@ -138,7 +137,7 @@ class DeepLinksTest : BaseActivityTest() { ActivityScenario.launch(createDeepLinkIntent(it)).onActivity {} clickOnCopy(composeTestRule) navigationHistory { - checkZimFileLoadedSuccessful(R.id.readerFragment) + checkZimFileLoadedSuccessful(composeTestRule) assertZimFileLoaded() // check if the zim file successfully loaded clickOnAndroidArticle() } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt index 8165ea18a..5ad9682c4 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt @@ -29,8 +29,6 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput import applyWithViewHierarchyPrinting import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.ViewId -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.R.string import org.kiwix.kiwixmobile.core.page.SEARCH_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.ui.components.TOOLBAR_TITLE_TESTING_TAG @@ -38,6 +36,8 @@ import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_CONFIRM_BUTTON_TESTI import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_TITLE_TEXT_TESTING_TAG import org.kiwix.kiwixmobile.core.utils.files.Log import org.kiwix.kiwixmobile.download.DownloadTest.Companion.KIWIX_DOWNLOAD_TEST +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_LIBRARY_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG import org.kiwix.kiwixmobile.nav.destination.library.online.DOWNLOADING_PAUSE_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.nav.destination.library.online.DOWNLOADING_STATE_TEXT_TESTING_TAG @@ -57,12 +57,18 @@ fun downloadRobot(func: DownloadRobot.() -> Unit) = DownloadRobot().applyWithViewHierarchyPrinting(func) class DownloadRobot : BaseRobot() { - fun clickLibraryOnBottomNav() { - clickOn(ViewId(R.id.libraryFragment)) + fun clickLibraryOnBottomNav(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_LIBRARY_ITEM_TESTING_TAG).performClick() + } } - fun clickDownloadOnBottomNav() { - clickOn(ViewId(R.id.downloadsFragment)) + fun clickDownloadOnBottomNav(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG).performClick() + } } // Increasing the default timeout for data loading because, on the Android 16 Emulator, diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt index 054178b4c..997f8b57a 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt @@ -140,7 +140,7 @@ class DownloadTest : BaseActivityTest() { deleteZimIfExists(composeTestRule) } downloadRobot { - clickDownloadOnBottomNav() + clickDownloadOnBottomNav(composeTestRule) waitForDataToLoad(composeTestRule = composeTestRule) stopDownloadIfAlreadyStarted(composeTestRule) downloadZimFile(composeTestRule) @@ -202,7 +202,7 @@ class DownloadTest : BaseActivityTest() { selectAlbanianLanguage(composeTestRule) } } - clickDownloadOnBottomNav() + clickDownloadOnBottomNav(composeTestRule) waitForDataToLoad(composeTestRule = composeTestRule) stopDownloadIfAlreadyStarted(composeTestRule) downloadZimFile(composeTestRule) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt index c36089189..72dd6d546 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadRobot.kt @@ -26,22 +26,24 @@ import androidx.compose.ui.test.performClick import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.ViewId -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.R.string +import org.kiwix.kiwixmobile.core.ui.components.STORAGE_DEVICE_ITEM_TESTING_TAG +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.nav.destination.library.online.DOWNLOADING_STOP_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.storage.STORAGE_SELECTION_DIALOG_TITLE_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout -import org.kiwix.kiwixmobile.core.ui.components.STORAGE_DEVICE_ITEM_TESTING_TAG fun initialDownload(func: InitialDownloadRobot.() -> Unit) = InitialDownloadRobot().applyWithViewHierarchyPrinting(func) class InitialDownloadRobot : BaseRobot() { - fun clickDownloadOnBottomNav() { - clickOn(ViewId(R.id.downloadsFragment)) + fun clickDownloadOnBottomNav(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG).performClick() + } } fun assertStorageConfigureDialogDisplayed(composeTestRule: ComposeContentTestRule) { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt index 9a4a54a06..e6f671e95 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt @@ -125,7 +125,7 @@ class InitialDownloadTest : BaseActivityTest() { deleteZimIfExists(composeTestRule) } downloadRobot { - clickDownloadOnBottomNav() + clickDownloadOnBottomNav(composeTestRule) waitForDataToLoad(composeTestRule = composeTestRule) stopDownloadIfAlreadyStarted(composeTestRule) downloadZimFile(composeTestRule) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt index e54ca0989..6964af15f 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt @@ -132,7 +132,7 @@ class LanguageFragmentTest { fun testLanguageFragment() { StandardActions.closeDrawer(kiwixMainActivity as CoreMainActivity) // close the drawer if open before running the test cases. downloadRobot { - clickDownloadOnBottomNav() + clickDownloadOnBottomNav(composeTestRule) waitForDataToLoad(composeTestRule = composeTestRule) } language { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt index d43904e71..ad05336d0 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt @@ -28,11 +28,10 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput import applyWithViewHierarchyPrinting import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.ViewId -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.R.string import org.kiwix.kiwixmobile.core.page.SEARCH_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.search.SEARCH_FIELD_TESTING_TAG +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.nav.destination.library.online.LANGUAGE_MENU_ICON_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout @@ -40,8 +39,11 @@ import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout fun language(func: LanguageRobot.() -> Unit) = LanguageRobot().applyWithViewHierarchyPrinting(func) class LanguageRobot : BaseRobot() { - fun clickDownloadOnBottomNav() { - clickOn(ViewId(R.id.downloadsFragment)) + fun clickDownloadOnBottomNav(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG).performClick() + } } fun clickOnLanguageIcon(composeTestRule: ComposeContentTestRule) { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt index 60304e7cf..d28053112 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt @@ -29,18 +29,17 @@ import androidx.test.espresso.web.webdriver.DriverAtoms import androidx.test.espresso.web.webdriver.Locator import applyWithViewHierarchyPrinting import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable -import org.kiwix.kiwixmobile.R.id import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.ui.components.STORAGE_DEVICE_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_CONFIRM_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_DISMISS_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_MESSAGE_TEXT_TESTING_TAG import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_NATURAL_BUTTON_TESTING_TAG +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_READER_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG import org.kiwix.kiwixmobile.storage.STORAGE_SELECTION_DIALOG_TITLE_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout -import org.kiwix.kiwixmobile.core.ui.components.STORAGE_DEVICE_ITEM_TESTING_TAG fun copyMoveFileHandler(func: CopyMoveFileHandlerRobot.() -> Unit) = CopyMoveFileHandlerRobot().applyWithViewHierarchyPrinting(func) @@ -117,8 +116,13 @@ class CopyMoveFileHandlerRobot : BaseRobot() { } fun assertZimFileCopiedAndShowingIntoTheReader(composeTestRule: ComposeContentTestRule) { - composeTestRule.waitUntilTimeout() - isVisible(Findable.ViewId(id.readerFragment)) + composeTestRule.apply { + waitUntilTimeout() + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_READER_ITEM_TESTING_TAG).performClick() + } + } testFlakyView({ Web.onWebView() .withElement( diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterRobot.kt index 625fafa50..7fad76587 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterRobot.kt @@ -40,9 +40,9 @@ fun darkModeViewPainter(func: DarkModeViewPainterRobot.() -> Unit) = DarkModeViewPainterRobot().applyWithViewHierarchyPrinting(func) class DarkModeViewPainterRobot : BaseRobot() { - fun openSettings(coreMainActivity: CoreMainActivity) { + fun openSettings(coreMainActivity: CoreMainActivity, composeContentTest: ComposeContentTestRule) { openDrawer(coreMainActivity) - enterSettings() + enterSettings(composeContentTest) } fun enableTheDarkMode(composeContentTest: ComposeContentTestRule) { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt index 2112bab8b..0e7849a08 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt @@ -22,6 +22,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.core.net.toUri import androidx.lifecycle.Lifecycle +import androidx.navigation.NavOptions import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks @@ -45,7 +46,6 @@ import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER -import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections import org.kiwix.kiwixmobile.settings.settingsRobo import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils @@ -186,9 +186,12 @@ class DarkModeViewPainterTest : BaseActivityTest() { } } UiThreadStatement.runOnUiThread { + val navOptions = NavOptions.Builder() + .setPopUpTo(KiwixDestination.Reader.route, false) + .build() kiwixMainActivity.navigate( - LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader() - .apply { zimFileUri = zimFile.toUri().toString() } + KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), + navOptions ) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt index f11c7fa3d..7e8e62713 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt @@ -17,16 +17,16 @@ */ package org.kiwix.kiwixmobile.main +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable.StringId.TextId -import org.kiwix.kiwixmobile.Findable.ViewId -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.R.string import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.help.HelpRobot @@ -45,6 +45,7 @@ import org.kiwix.kiwixmobile.settings.SettingsRobot import org.kiwix.kiwixmobile.settings.settingsRobo import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView +import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout import org.kiwix.kiwixmobile.utils.StandardActions.openDrawer import org.kiwix.kiwixmobile.webserver.ZimHostRobot import org.kiwix.kiwixmobile.webserver.zimHost @@ -53,20 +54,40 @@ fun topLevel(func: TopLevelDestinationRobot.() -> Unit) = TopLevelDestinationRobot().applyWithViewHierarchyPrinting(func) class TopLevelDestinationRobot : BaseRobot() { - fun clickReaderOnBottomNav(func: ReaderRobot.() -> Unit) { + fun clickReaderOnBottomNav( + composeTestRule: ComposeContentTestRule, + func: ReaderRobot.() -> Unit + ) { BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) - testFlakyView({ onView(withId(R.id.readerFragment)).perform(click()) }) + testFlakyView({ + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_READER_ITEM_TESTING_TAG).performClick() + } + }) reader(func) } - fun clickLibraryOnBottomNav(func: LibraryRobot.() -> Unit) { - clickOn(ViewId(R.id.libraryFragment)) + fun clickLibraryOnBottomNav( + composeTestRule: ComposeContentTestRule, + func: LibraryRobot.() -> Unit + ) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_LIBRARY_ITEM_TESTING_TAG).performClick() + } library(func) pressBack() } - fun clickDownloadOnBottomNav(func: OnlineLibraryRobot.() -> Unit) { - clickOn(ViewId(R.id.downloadsFragment)) + fun clickDownloadOnBottomNav( + composeTestRule: ComposeContentTestRule, + func: OnlineLibraryRobot.() -> Unit + ) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG).performClick() + } onlineLibrary(func) } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt index 54535de84..a34f01ced 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt @@ -112,15 +112,15 @@ class TopLevelDestinationTest : BaseActivityTest() { @Test fun testTopLevelDestination() { topLevel { - clickReaderOnBottomNav { + clickReaderOnBottomNav(composeTestRule) { assertReaderScreenDisplayed(composeTestRule) } - clickDownloadOnBottomNav { + clickDownloadOnBottomNav(composeTestRule) { onlineLibrary { assertOnlineLibraryFragmentDisplayed(composeTestRule) } } - clickLibraryOnBottomNav { + clickLibraryOnBottomNav(composeTestRule) { assertGetZimNearbyDeviceDisplayed(composeTestRule) clickFileTransferIcon(composeTestRule) { assertReceiveFileTitleVisible(composeTestRule) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt index 2793fdfc1..86cff3c26 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt @@ -99,8 +99,8 @@ class OnlineLibraryFragmentTest : BaseActivityTest() { clickOnSearchIcon(composeTestRule) searchWikipediaZIMFiles(composeTestRule) pressBack() - clickLibraryOnBottomNav() - clickDownloadOnBottomNav() + clickLibraryOnBottomNav(composeTestRule) + clickDownloadOnBottomNav(composeTestRule) assertPreviousSearchRemainsActive(composeTestRule) } } @@ -118,8 +118,8 @@ class OnlineLibraryFragmentTest : BaseActivityTest() { searchWikipediaZIMFiles(composeTestRule) clickOnClearSearchIcon(composeTestRule) pressBack() - clickLibraryOnBottomNav() - clickDownloadOnBottomNav() + clickLibraryOnBottomNav(composeTestRule) + clickDownloadOnBottomNav(composeTestRule) assertSearchViewIsNotActive(composeTestRule) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt index 280004ed2..20363042b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.core.net.toUri import androidx.lifecycle.Lifecycle +import androidx.navigation.NavOptions import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks @@ -49,7 +50,6 @@ import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.nav.destination.library.library -import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs @@ -279,9 +279,12 @@ class NoteFragmentTest : BaseActivityTest() { } } UiThreadStatement.runOnUiThread { + val navOptions = NavOptions.Builder() + .setPopUpTo(KiwixDestination.Reader.route, false) + .build() kiwixMainActivity.navigate( - LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader() - .apply { zimFileUri = zimFile.toUri().toString() } + KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), + navOptions ) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt index 19509a0d2..e6c14d6a3 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt @@ -46,7 +46,6 @@ import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.main.topLevel -import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST @@ -117,9 +116,12 @@ class LibkiwixBookmarkTest : BaseActivityTest() { activityScenario.onActivity { kiwixMainActivity = it kiwixMainActivity.navigate(KiwixDestination.Library.route) + val navOptions = NavOptions.Builder() + .setPopUpTo(KiwixDestination.Reader.route, false) + .build() kiwixMainActivity.navigate( - LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader() - .apply { zimFileUri = getZimFile().toUri().toString() } + KiwixDestination.Reader.createRoute(zimFileUri = getZimFile().toUri().toString()), + navOptions ) } bookmarks { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt index 41eeb1e4b..de062da18 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt @@ -25,9 +25,6 @@ import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTouchInput -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.webClick @@ -36,12 +33,13 @@ import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions import junit.framework.AssertionFailedError import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.main.reader.READER_SCREEN_TESTING_TAG import org.kiwix.kiwixmobile.core.main.reader.TAB_SWITCHER_VIEW_TESTING_TAG import org.kiwix.kiwixmobile.core.page.DELETE_MENU_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.ui.components.TOOLBAR_TITLE_TESTING_TAG import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_TITLE_TEXT_TESTING_TAG +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_READER_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout @@ -54,9 +52,11 @@ class NavigationHistoryRobot : BaseRobot() { private var retryCountForBackwardNavigationHistory = 5 private var retryCountForForwardNavigationHistory = 5 - fun checkZimFileLoadedSuccessful(readerFragment: Int) { - pauseForBetterTestPerformance() - isVisible(ViewId(readerFragment)) + fun checkZimFileLoadedSuccessful(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(READER_SCREEN_TESTING_TAG).assertExists() + } } fun closeTabSwitcherIfVisible(composeTestRule: ComposeContentTestRule) { @@ -189,7 +189,12 @@ class NavigationHistoryRobot : BaseRobot() { BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) } - fun clickOnReaderFragment() { - testFlakyView({ onView(withId(org.kiwix.kiwixmobile.R.id.readerFragment)).perform(click()) }) + fun clickOnReaderFragment(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_READER_ITEM_TESTING_TAG).performClick() + } + }) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt index 374139ede..31c85327c 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt @@ -43,7 +43,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.kiwix.kiwixmobile.BaseActivityTest -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil @@ -153,7 +152,7 @@ class NavigationHistoryTest : BaseActivityTest() { StandardActions.closeDrawer(kiwixMainActivity as CoreMainActivity) // close the drawer if open before running the test cases. navigationHistory { closeTabSwitcherIfVisible(composeTestRule) - checkZimFileLoadedSuccessful(R.id.readerFragment) + checkZimFileLoadedSuccessful(composeTestRule) clickOnAndroidArticle() longClickOnBackwardButton(composeTestRule) assertBackwardNavigationHistoryDialogDisplayed(composeTestRule) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt index 44e647578..d1c9c4d41 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.core.net.toUri import androidx.lifecycle.Lifecycle +import androidx.navigation.NavOptions import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks @@ -44,13 +45,11 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.kiwix.kiwixmobile.BaseActivityTest -import org.kiwix.kiwixmobile.R 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 import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER import org.kiwix.kiwixmobile.main.KiwixMainActivity -import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs @@ -141,13 +140,13 @@ class KiwixReaderFragmentTest : BaseActivityTest() { } openKiwixReaderFragmentWithFile(zimFile) reader { - checkZimFileLoadedSuccessful(R.id.readerFragment) + checkZimFileLoadedSuccessful(composeTestRule) clickOnTabIcon(composeTestRule) clickOnClosedAllTabsButton(composeTestRule) clickOnUndoButton(composeTestRule) assertTabRestored(composeTestRule) pressBack() - checkZimFileLoadedSuccessful(R.id.readerFragment) + checkZimFileLoadedSuccessful(composeTestRule) } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { // temporary disabled on Android 25 @@ -176,7 +175,7 @@ class KiwixReaderFragmentTest : BaseActivityTest() { } openKiwixReaderFragmentWithFile(downloadingZimFile) reader { - checkZimFileLoadedSuccessful(R.id.readerFragment) + checkZimFileLoadedSuccessful(composeTestRule) clickOnTabIcon(composeTestRule) clickOnTabIcon(composeTestRule) // test the whole welcome page is loaded or not @@ -260,9 +259,12 @@ class KiwixReaderFragmentTest : BaseActivityTest() { private fun openKiwixReaderFragmentWithFile(zimFile: File) { UiThreadStatement.runOnUiThread { + val navOptions = NavOptions.Builder() + .setPopUpTo(KiwixDestination.Reader.route, false) + .build() kiwixMainActivity.navigate( - LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader() - .apply { zimFileUri = zimFile.toUri().toString() } + KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), + navOptions ) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ReaderRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ReaderRobot.kt index feb384d6e..40b6ade64 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ReaderRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ReaderRobot.kt @@ -31,8 +31,8 @@ import androidx.test.espresso.web.webdriver.Locator import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.core.main.reader.CLOSE_ALL_TABS_BUTTON_TESTING_TAG +import org.kiwix.kiwixmobile.core.main.reader.READER_SCREEN_TESTING_TAG import org.kiwix.kiwixmobile.core.main.reader.TAB_MENU_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.main.reader.TAB_TITLE_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils @@ -44,9 +44,11 @@ fun reader(func: ReaderRobot.() -> Unit) = ReaderRobot().applyWithViewHierarchyP class ReaderRobot : BaseRobot() { private var retryCountForClickOnUndoButton = 5 - fun checkZimFileLoadedSuccessful(readerFragment: Int) { - pauseForBetterTestPerformance() - isVisible(ViewId(readerFragment)) + fun checkZimFileLoadedSuccessful(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(READER_SCREEN_TESTING_TAG).assertExists() + } } fun clickOnTabIcon(composeTestRule: ComposeContentTestRule) { @@ -88,10 +90,6 @@ class ReaderRobot : BaseRobot() { } } - private fun pauseForBetterTestPerformance() { - BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) - } - fun clickOnArticle(articleTitle: String) { BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) testFlakyView({ diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt index ba16b84d4..eda666e6a 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.reader +import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.core.net.toUri import androidx.lifecycle.Lifecycle @@ -43,12 +44,12 @@ import org.junit.Rule import org.junit.Test import org.junit.jupiter.api.fail import org.kiwix.kiwixmobile.BaseActivityTest -import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.DarkModeConfig import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimReaderSource 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 import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.page.history.navigationHistory @@ -65,6 +66,9 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() { @JvmField val retryRule = RetryRule() + @get:Rule(order = COMPOSE_TEST_RULE_ORDER) + val composeTestRule = createComposeRule() + private lateinit var kiwixMainActivity: KiwixMainActivity @Before @@ -127,8 +131,8 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() { } navigationHistory { - checkZimFileLoadedSuccessful(R.id.readerFragment) - clickOnReaderFragment() // activate the accessibility check to check the issues. + checkZimFileLoadedSuccessful(composeTestRule) + clickOnReaderFragment(composeTestRule) // activate the accessibility check to check the issues. assertZimFileLoaded() // check if the zim file successfully loaded clickOnAndroidArticle() } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt index d455288c1..ad2304e9c 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt @@ -22,6 +22,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.core.net.toUri import androidx.lifecycle.Lifecycle +import androidx.navigation.NavOptions import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks @@ -45,13 +46,11 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.kiwix.kiwixmobile.BaseActivityTest -import org.kiwix.kiwixmobile.R 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 import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER import org.kiwix.kiwixmobile.main.KiwixMainActivity -import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs @@ -136,11 +135,11 @@ class SearchFragmentTest : BaseActivityTest() { } testZimFile = getTestZimFile() openKiwixReaderFragmentWithFile(testZimFile) - search { checkZimFileSearchSuccessful(R.id.readerFragment) } + search { checkZimFileSearchSuccessful(composeTestRule) } openSearchWithQuery("Android", testZimFile) search { clickOnSearchItemInSearchList(composeTestRule) - checkZimFileSearchSuccessful(R.id.readerFragment) + checkZimFileSearchSuccessful(composeTestRule) } openSearchWithQuery(zimFile = testZimFile) @@ -187,7 +186,7 @@ class SearchFragmentTest : BaseActivityTest() { } } openKiwixReaderFragmentWithFile(downloadingZimFile) - search { checkZimFileSearchSuccessful(R.id.readerFragment) } + search { checkZimFileSearchSuccessful(composeTestRule) } openSearchWithQuery(zimFile = downloadingZimFile) search { // test with fast typing/deleting @@ -273,7 +272,7 @@ class SearchFragmentTest : BaseActivityTest() { } } openKiwixReaderFragmentWithFile(downloadingZimFile) - search { checkZimFileSearchSuccessful(R.id.readerFragment) } + search { checkZimFileSearchSuccessful(composeTestRule) } openSearchWithQuery(searchTerms[0], downloadingZimFile) // wait for searchFragment become visible on screen. delay(2000) @@ -313,9 +312,12 @@ class SearchFragmentTest : BaseActivityTest() { private fun openKiwixReaderFragmentWithFile(zimFile: File) { UiThreadStatement.runOnUiThread { + val navOptions = NavOptions.Builder() + .setPopUpTo(KiwixDestination.Reader.route, false) + .build() kiwixMainActivity.navigate( - actionNavigationLibraryToNavigationReader() - .apply { zimFileUri = zimFile.toUri().toString() } + KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), + navOptions ) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchRobot.kt index f89947460..b23bf45b5 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchRobot.kt @@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.search import android.view.KeyEvent import androidx.compose.ui.test.assert +import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.onAllNodesWithTag @@ -34,11 +35,11 @@ import androidx.test.uiautomator.UiDevice import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.core.page.SEARCH_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.search.SEARCH_FIELD_TESTING_TAG import org.kiwix.kiwixmobile.core.search.SEARCH_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.ui.components.NAVIGATION_ICON_TESTING_TAG +import org.kiwix.kiwixmobile.main.BOTTOM_NAV_READER_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView @@ -59,9 +60,12 @@ class SearchRobot : BaseRobot() { } } - fun checkZimFileSearchSuccessful(readerFragment: Int) { + fun checkZimFileSearchSuccessful(composeTestRule: ComposeContentTestRule) { BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) - isVisible(ViewId(readerFragment)) + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_READER_ITEM_TESTING_TAG).assertIsDisplayed() + } } fun searchWithFrequentlyTypedWords( @@ -131,7 +135,7 @@ class SearchRobot : BaseRobot() { openSearchScreen(composeTestRule) searchWithFrequentlyTypedWords(searchString, composeTestRule = composeTestRule) clickOnSearchItemInSearchList(composeTestRule) - checkZimFileSearchSuccessful(org.kiwix.kiwixmobile.R.id.readerFragment) + checkZimFileSearchSuccessful(composeTestRule) } fun assertArticleLoaded() { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsFragmentTest.kt index 69d024868..2d7cc995f 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsFragmentTest.kt @@ -119,7 +119,7 @@ class KiwixSettingsFragmentTest { clickGetStarted(composeTestRule) {} } StandardActions.openDrawer(kiwixMainActivity as CoreMainActivity) - StandardActions.enterSettings() + StandardActions.enterSettings(composeTestRule) } @Test diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt index 48d88a7ca..16f199a86 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt @@ -130,13 +130,13 @@ class GetContentShortcutTest { ActivityScenario.launch(shortcutIntent) onlineLibrary { assertOnlineLibraryFragmentDisplayed(composeTestRule) } topLevel { - clickReaderOnBottomNav { + clickReaderOnBottomNav(composeTestRule) { assertReaderScreenDisplayed(composeTestRule) } - clickDownloadOnBottomNav { + clickDownloadOnBottomNav(composeTestRule) { onlineLibrary { assertOnlineLibraryFragmentDisplayed(composeTestRule) } } - clickLibraryOnBottomNav { + clickLibraryOnBottomNav(composeTestRule) { assertGetZimNearbyDeviceDisplayed(composeTestRule) clickFileTransferIcon(composeTestRule) { assertReceiveFileTitleVisible(composeTestRule) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt index b243c98fb..9db28dc64 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt @@ -17,24 +17,29 @@ */ package org.kiwix.kiwixmobile.utils -import org.kiwix.kiwixmobile.core.utils.files.Log +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions import androidx.test.espresso.matcher.ViewMatchers -import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn import com.adevinta.android.barista.interaction.BaristaDialogInteractions import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import org.kiwix.kiwixmobile.core.R.string import org.kiwix.kiwixmobile.core.main.CoreMainActivity +import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_SETTINGS_ITEM_TESTING_TAG +import org.kiwix.kiwixmobile.core.utils.files.Log import org.kiwix.kiwixmobile.testutils.TestUtils +import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout /** * Created by mhutti1 on 27/04/17. */ object StandardActions { - fun enterSettings() { - BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) - clickOn(TestUtils.getResourceString(string.menu_settings)) + fun enterSettings(composeContentTest: ComposeContentTestRule) { + composeContentTest.apply { + waitUntilTimeout() + onNodeWithTag(LEFT_DRAWER_SETTINGS_ITEM_TESTING_TAG).performClick() + } } fun openDrawer(coreMainActivity: CoreMainActivity) { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 07fe617ea..5373b6d18 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -135,6 +135,12 @@ + + + + + + ? { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelableArray(key, Uri::class.java) + } else { + @Suppress("UNCHECKED_CAST") + getParcelableArray(key) as? Array + } + } private fun showPeerDiscoveryProgressBar() { // Setup UI for searching peers isPeerSearching.value = true diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/BottomNavItem.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/BottomNavItem.kt index a4a64ca86..a0e7f57f9 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/BottomNavItem.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/BottomNavItem.kt @@ -21,5 +21,6 @@ package org.kiwix.kiwixmobile.main data class BottomNavItem( val route: String, val title: String, - val iconRes: Int + val iconRes: Int, + val testingTag: String ) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index c691e7efb..356f7535d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -59,7 +59,11 @@ import org.kiwix.kiwixmobile.core.extensions.update import org.kiwix.kiwixmobile.core.main.ACTION_NEW_TAB import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.DrawerMenuItem +import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_HELP_ITEM_TESTING_TAG +import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG +import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_ZIM_HOST_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.main.NEW_TAB_SHORTCUT_ID +import org.kiwix.kiwixmobile.core.main.ZIM_HOST_DEEP_LINK_SCHEME import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.dialog.DialogHost import org.kiwix.kiwixmobile.kiwixActivityComponent @@ -217,6 +221,10 @@ class KiwixMainActivity : CoreMainActivity() { handleNotificationIntent(intent) handleZimFileIntent(intent) handleGetContentIntent(intent) + intent.data?.let { uri -> + // for handling the deepLink of ZimHost screen when application is opened. + navController.handleDeepLink(intent) + } supportFragmentManager.fragments.filterIsInstance().forEach { it.onNewIntent(intent, this) } @@ -239,7 +247,11 @@ class KiwixMainActivity : CoreMainActivity() { }, OPENING_ZIM_FILE_DELAY) } - else -> toast(R.string.cannot_open_file) + else -> { + if (it.scheme != ZIM_HOST_DEEP_LINK_SCHEME) { + toast(R.string.cannot_open_file) + } + } } } } @@ -276,21 +288,24 @@ class KiwixMainActivity : CoreMainActivity() { title = CoreApp.instance.getString(string.menu_wifi_hotspot), iconRes = drawable.ic_mobile_screen_share_24px, visible = true, - onClick = { openZimHostFragment() } + onClick = { openZimHostFragment() }, + testingTag = LEFT_DRAWER_ZIM_HOST_ITEM_TESTING_TAG ) override val helpDrawerMenuItem: DrawerMenuItem? = DrawerMenuItem( title = CoreApp.instance.getString(string.menu_help), iconRes = drawable.ic_help_24px, visible = true, - onClick = { openHelpFragment() } + onClick = { openHelpFragment() }, + testingTag = LEFT_DRAWER_HELP_ITEM_TESTING_TAG ) override val supportDrawerMenuItem: DrawerMenuItem? = DrawerMenuItem( title = CoreApp.instance.getString(string.menu_support_kiwix), iconRes = drawable.ic_support_24px, visible = true, - onClick = { openSupportKiwixExternalLink() } + onClick = { openSupportKiwixExternalLink() }, + testingTag = LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG ) /** diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt index e396285e1..373e04531 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivityScreen.kt @@ -37,6 +37,8 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.testTag import androidx.navigation.NavBackStackEntry import androidx.navigation.NavHostController import androidx.navigation.compose.currentBackStackEntryAsState @@ -52,6 +54,10 @@ import org.kiwix.kiwixmobile.core.ui.theme.White import org.kiwix.kiwixmobile.ui.KiwixDestination import org.kiwix.kiwixmobile.ui.KiwixNavGraph +const val BOTTOM_NAV_READER_ITEM_TESTING_TAG = "bottomNavReaderItemTestingTag" +const val BOTTOM_NAV_LIBRARY_ITEM_TESTING_TAG = "bottomNavLibraryItemTestingTag" +const val BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG = "bottomNavDownloadsItemTestingTag" + @Suppress("LongParameterList") @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -126,17 +132,20 @@ fun BottomNavigationBar( BottomNavItem( route = KiwixDestination.Reader.route, title = stringResource(id = R.string.reader), - iconRes = drawable.ic_reader_navigation_white_24px + iconRes = drawable.ic_reader_navigation_white_24px, + testingTag = BOTTOM_NAV_READER_ITEM_TESTING_TAG ), BottomNavItem( route = KiwixDestination.Library.route, title = stringResource(id = R.string.library), - iconRes = drawable.ic_library_navigation_white_24dp + iconRes = drawable.ic_library_navigation_white_24dp, + testingTag = BOTTOM_NAV_LIBRARY_ITEM_TESTING_TAG ), BottomNavItem( route = KiwixDestination.Downloads.route, title = stringResource(id = R.string.download), - iconRes = drawable.ic_download_navigation_white_24dp + iconRes = drawable.ic_download_navigation_white_24dp, + testingTag = BOTTOM_NAV_DOWNLOADS_ITEM_TESTING_TAG ) ) val currentDestinationRoute = navBackStackEntry?.destination?.route @@ -162,7 +171,8 @@ fun BottomNavigationBar( contentDescription = item.title ) }, - label = { Text(item.title) } + label = { Text(item.title) }, + modifier = Modifier.semantics { testTag = item.testingTag } ) } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt index c15409827..397741cb7 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt @@ -75,6 +75,7 @@ import org.kiwix.kiwixmobile.core.extensions.snack import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.MainRepositoryActions +import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY import org.kiwix.kiwixmobile.core.navigateToAppSettings import org.kiwix.kiwixmobile.core.navigateToSettings import org.kiwix.kiwixmobile.core.reader.ZimFileReader @@ -283,10 +284,6 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal } zimManageViewModel.setAlertDialogShower(dialogShower as AlertDialogShower) zimManageViewModel.fileSelectListStates.observe(viewLifecycleOwner, Observer(::render)) - .also { - // coreMainActivity.navHostContainer - // .setBottomMarginToFragmentContainerView(0) - } coroutineJobs.apply { add(sideEffects()) add(fileSelectActions()) @@ -315,9 +312,9 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal } private fun showCopyMoveDialogForOpenedZimFileFromStorage() { - val args = LocalLibraryFragmentArgs.fromBundle(requireArguments()) - if (args.zimFileUri.isNotEmpty()) { - handleSelectedFileUri(args.zimFileUri.toUri()) + val zimFileUri = arguments?.getString(ZIM_FILE_URI_KEY).orEmpty() + if (zimFileUri.isNotEmpty()) { + handleSelectedFileUri(zimFileUri.toUri()) } requireArguments().clear() } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt index bbc45ba10..14efb7084 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/online/OnlineLibraryFragment.kt @@ -294,10 +294,6 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { libraryItems .onEach { onLibraryItemsChange(it) } .launchIn(viewLifecycleOwner.lifecycleScope) - .also { - // coreMainActivity.navHostContainer - // .setBottomMarginToFragmentContainerView(0) - } // Observe when online library downloading. onlineLibraryDownloading .onEach { (initialLibraryDownloading, loadingMoreItem) -> diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt index d84a3534e..ba431b5e8 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt @@ -40,11 +40,14 @@ import org.kiwix.kiwixmobile.core.extensions.snack import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.extensions.update import org.kiwix.kiwixmobile.core.main.CoreMainActivity +import org.kiwix.kiwixmobile.core.main.PAGE_URL_KEY +import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY import org.kiwix.kiwixmobile.core.main.reader.CoreReaderFragment import org.kiwix.kiwixmobile.core.main.reader.HIDE_TAB_SWITCHER_DELAY import org.kiwix.kiwixmobile.core.main.reader.RestoreOrigin import org.kiwix.kiwixmobile.core.main.reader.RestoreOrigin.FromExternalLaunch import org.kiwix.kiwixmobile.core.main.reader.RestoreOrigin.FromSearchScreen +import org.kiwix.kiwixmobile.core.main.reader.SEARCH_ITEM_TITLE_KEY import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem import org.kiwix.kiwixmobile.core.reader.ZimReaderSource import org.kiwix.kiwixmobile.core.reader.ZimReaderSource.Companion.fromDatabaseValue @@ -83,11 +86,13 @@ class KiwixReaderFragment : CoreReaderFragment() { @Suppress("MagicNumber") private fun openPageInBookFromNavigationArguments() { showProgressBarWithProgress(30) - val args = KiwixReaderFragmentArgs.fromBundle(requireArguments()) + val zimFileUri = arguments?.getString(ZIM_FILE_URI_KEY).orEmpty() + val pageUrl = arguments?.getString(PAGE_URL_KEY).orEmpty() + val searchItemTitle = arguments?.getString(SEARCH_ITEM_TITLE_KEY).orEmpty() coreReaderLifeCycleScope?.launch { - if (args.pageUrl.isNotEmpty()) { - if (args.zimFileUri.isNotEmpty()) { - tryOpeningZimFile(args.zimFileUri) + if (pageUrl.isNotEmpty()) { + if (zimFileUri.isNotEmpty()) { + tryOpeningZimFile(zimFileUri) } else { // Set up bookmarks for the current book when opening bookmarks from the Bookmark screen. // This is necessary because we are not opening the ZIM file again; the bookmark is @@ -96,13 +101,13 @@ class KiwixReaderFragment : CoreReaderFragment() { zimReaderContainer?.zimFileReader?.let(::setUpBookmarks) } hideProgressBar() - loadUrlWithCurrentWebview(args.pageUrl) + loadUrlWithCurrentWebview(pageUrl) } else { - if (args.zimFileUri.isNotEmpty()) { - tryOpeningZimFile(args.zimFileUri) + if (zimFileUri.isNotEmpty()) { + tryOpeningZimFile(zimFileUri) } else { val restoreOrigin = - if (args.searchItemTitle.isNotEmpty()) FromSearchScreen else FromExternalLaunch + if (searchItemTitle.isNotEmpty()) FromSearchScreen else FromExternalLaunch manageExternalLaunchAndRestoringViewState(restoreOrigin) } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt b/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt index 50744e07e..47f4c217e 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/ui/KiwixNavGraph.kt @@ -39,6 +39,7 @@ import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.navArgument +import androidx.navigation.navDeepLink import org.kiwix.kiwixmobile.core.main.BOOKMARK_FRAGMENT import org.kiwix.kiwixmobile.core.main.DOWNLOAD_FRAGMENT import org.kiwix.kiwixmobile.core.main.FIND_IN_PAGE_SEARCH_STRING @@ -56,6 +57,7 @@ import org.kiwix.kiwixmobile.core.main.SETTINGS_FRAGMENT import org.kiwix.kiwixmobile.core.main.SHOULD_OPEN_IN_NEW_TAB import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY import org.kiwix.kiwixmobile.core.main.ZIM_HOST_FRAGMENT +import org.kiwix.kiwixmobile.core.main.ZIM_HOST_NAV_DEEP_LINK import org.kiwix.kiwixmobile.core.main.reader.SEARCH_ITEM_TITLE_KEY import org.kiwix.kiwixmobile.core.page.bookmark.BookmarksFragment import org.kiwix.kiwixmobile.core.page.history.HistoryFragment @@ -68,6 +70,7 @@ import org.kiwix.kiwixmobile.help.KiwixHelpFragment import org.kiwix.kiwixmobile.intro.IntroFragment import org.kiwix.kiwixmobile.language.LanguageFragment import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferFragment +import org.kiwix.kiwixmobile.localFileTransfer.URIS_KEY import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragment import org.kiwix.kiwixmobile.nav.destination.library.online.OnlineLibraryFragment import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment @@ -179,7 +182,10 @@ fun KiwixNavGraph( LanguageFragment() } } - composable(KiwixDestination.ZimHost.route) { + composable( + KiwixDestination.ZimHost.route, + deepLinks = listOf(navDeepLink { uriPattern = ZIM_HOST_NAV_DEEP_LINK }) + ) { FragmentContainer { ZimHostFragment() } @@ -228,14 +234,14 @@ fun KiwixNavGraph( composable( route = KiwixDestination.LocalFileTransfer.route, arguments = listOf( - navArgument("uris") { + navArgument(URIS_KEY) { type = NavType.StringType nullable = true defaultValue = null } ) ) { backStackEntry -> - val urisParam = backStackEntry.arguments?.getString("uris") + val urisParam = backStackEntry.arguments?.getString(URIS_KEY) val uris: List? = urisParam?.takeIf { it != "null" }?.split(",")?.map { Uri.decode(it).toUri() @@ -245,7 +251,7 @@ fun KiwixNavGraph( LocalFileTransferFragment().apply { arguments = Bundle().apply { putParcelableArray( - "uris", + URIS_KEY, uris?.toTypedArray() ) } @@ -341,12 +347,12 @@ sealed class KiwixDestination(val route: String) { } } - object LocalFileTransfer : KiwixDestination("$LOCAL_FILE_TRANSFER_FRAGMENT?uris={uris}") { + object LocalFileTransfer : KiwixDestination("$LOCAL_FILE_TRANSFER_FRAGMENT?$URIS_KEY={uris}") { fun createRoute(uris: String? = null): String { return if (uris != null) { - "$LOCAL_FILE_TRANSFER_FRAGMENT?uris=${Uri.encode(uris)}" + "$LOCAL_FILE_TRANSFER_FRAGMENT?$URIS_KEY=${Uri.encode(uris)}" } else { - "$LOCAL_FILE_TRANSFER_FRAGMENT?uris=null" + "$LOCAL_FILE_TRANSFER_FRAGMENT?$URIS_KEY=null" } } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.kt index 1d154fb82..aafa34abe 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.kt @@ -26,11 +26,10 @@ import android.content.Context import android.content.Intent import android.os.Build import androidx.core.app.NotificationCompat -import androidx.navigation.NavDeepLinkBuilder +import androidx.core.net.toUri import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.R -import org.kiwix.kiwixmobile.R.id -import org.kiwix.kiwixmobile.R.navigation +import org.kiwix.kiwixmobile.core.main.ZIM_HOST_NAV_DEEP_LINK import org.kiwix.kiwixmobile.core.qr.GenerateQR import org.kiwix.kiwixmobile.core.utils.HOTSPOT_SERVICE_CHANNEL_ID import javax.inject.Inject @@ -58,13 +57,15 @@ class HotspotNotificationManager @Inject constructor( @SuppressLint("UnspecifiedImmutableFlag") fun buildForegroundNotification(uri: String? = null): Notification { val coreMainActivity = (context as CoreApp).getMainActivity() - val contentIntent = - NavDeepLinkBuilder(context).setComponentName( - coreMainActivity.mainActivity::class.java - ) - .setGraph(navigation.kiwix_nav_graph) - .setDestination(id.zimHostFragment) - .createPendingIntent() + val contentIntent = PendingIntent.getActivity( + context, + 0, + Intent(context, coreMainActivity.mainActivity::class.java).apply { + action = Intent.ACTION_VIEW + data = ZIM_HOST_NAV_DEEP_LINK.toUri() + }, + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + ) hotspotNotificationChannel() val stopIntent = Intent(context, HotspotService::class.java).setAction( diff --git a/app/src/main/res/menu/menu_bottom_nav.xml b/app/src/main/res/menu/menu_bottom_nav.xml deleted file mode 100644 index f0484284b..000000000 --- a/app/src/main/res/menu/menu_bottom_nav.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/navigation/kiwix_nav_graph.xml b/app/src/main/res/navigation/kiwix_nav_graph.xml deleted file mode 100644 index 2cbd53489..000000000 --- a/app/src/main/res/navigation/kiwix_nav_graph.xml +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt index 9fc319715..636e647b9 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt @@ -62,6 +62,7 @@ import org.kiwix.kiwixmobile.core.reader.ZimReaderSource import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower import org.kiwix.kiwixmobile.core.utils.dialog.RateDialogHandler +import org.kiwix.kiwixmobile.core.utils.files.Log import javax.inject.Inject import kotlin.system.exitProcess @@ -88,6 +89,16 @@ const val HELP_FRAGMENT = "helpFragment" const val SETTINGS_FRAGMENT = "settingsFragment" const val SEARCH_FRAGMENT = "searchFragment" const val LOCAL_FILE_TRANSFER_FRAGMENT = "localFileTransferFragment" +const val ZIM_HOST_DEEP_LINK_SCHEME = "kiwix" +const val ZIM_HOST_NAV_DEEP_LINK = "$ZIM_HOST_DEEP_LINK_SCHEME://zimhost" +const val LEFT_DRAWER_BOOKMARK_ITEM_TESTING_TAG = "leftDrawerBookmarkItemTestingTag" +const val LEFT_DRAWER_HISTORY_ITEM_TESTING_TAG = "leftDrawerHistoryItemTestingTag" +const val LEFT_DRAWER_NOTES_ITEM_TESTING_TAG = "leftDrawerNotesItemTestingTag" +const val LEFT_DRAWER_SETTINGS_ITEM_TESTING_TAG = "leftDrawerSettingsItemTestingTag" +const val LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG = "leftDrawerSupportItemTestingTag" +const val LEFT_DRAWER_HELP_ITEM_TESTING_TAG = "leftDrawerHelpItemTestingTag" +const val LEFT_DRAWER_ZIM_HOST_ITEM_TESTING_TAG = "leftDrawerZimHostItemTestingTag" +const val LEFT_DRAWER_ABOUT_APP_ITEM_TESTING_TAG = "leftDrawerAboutAppItemTestingTag" abstract class CoreMainActivity : BaseActivity(), WebViewProvider { abstract val searchFragmentRoute: String @@ -373,7 +384,9 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { } private fun activeFragments(): MutableList = - supportFragmentManager.fragments + supportFragmentManager.fragments.also { + Log.d("Fragments", "Found fragments: ${supportFragmentManager.fragments}") + } fun navigate(action: NavDirections) { navController.currentDestination?.getAction(action.actionId)?.run { @@ -453,19 +466,22 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { title = CoreApp.instance.getString(R.string.bookmarks), iconRes = R.drawable.ic_bookmark_black_24dp, visible = true, - onClick = { openBookmarks() } + onClick = { openBookmarks() }, + testingTag = LEFT_DRAWER_BOOKMARK_ITEM_TESTING_TAG ), DrawerMenuItem( title = CoreApp.instance.getString(R.string.history), iconRes = R.drawable.ic_history_24px, visible = true, - onClick = { openHistory() } + onClick = { openHistory() }, + testingTag = LEFT_DRAWER_HISTORY_ITEM_TESTING_TAG ), DrawerMenuItem( title = CoreApp.instance.getString(R.string.pref_notes), iconRes = R.drawable.ic_add_note, visible = true, - onClick = { openNotes() } + onClick = { openNotes() }, + testingTag = LEFT_DRAWER_NOTES_ITEM_TESTING_TAG ), zimHostDrawerMenuItem ) @@ -479,7 +495,8 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { title = CoreApp.instance.getString(R.string.menu_settings), iconRes = R.drawable.ic_settings_24px, visible = true, - onClick = { openSettings() } + onClick = { openSettings() }, + testingTag = LEFT_DRAWER_SETTINGS_ITEM_TESTING_TAG ) ) ) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/DrawerMenuItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/DrawerMenuItem.kt index c4924f128..a79e3b2b0 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/DrawerMenuItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/DrawerMenuItem.kt @@ -24,7 +24,8 @@ data class DrawerMenuItem( val title: String, @DrawableRes val iconRes: Int, val visible: Boolean = true, - val onClick: () -> Unit + val onClick: () -> Unit, + val testingTag: String ) data class DrawerMenuGroup(val drawerMenuItemList: List) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/reader/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/reader/CoreReaderFragment.kt index e682cb337..afaa6de2f 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/reader/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/reader/CoreReaderFragment.kt @@ -123,6 +123,7 @@ import org.kiwix.kiwixmobile.core.main.ServiceWorkerUninitialiser import org.kiwix.kiwixmobile.core.main.UNINITIALISER_ADDRESS import org.kiwix.kiwixmobile.core.main.WebViewCallback import org.kiwix.kiwixmobile.core.main.WebViewProvider +import org.kiwix.kiwixmobile.core.main.ZIM_HOST_DEEP_LINK_SCHEME import org.kiwix.kiwixmobile.core.main.reader.RestoreOrigin.FromExternalLaunch import org.kiwix.kiwixmobile.core.navigateToAppSettings import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem @@ -1931,7 +1932,7 @@ abstract class CoreReaderFragment : // Added condition to handle ZIM files. When opening from storage, the intent may // return null for the type, triggering the search unintentionally. This condition // prevents such occurrences. - intent.scheme !in listOf("file", "content") + intent.scheme !in listOf("file", "content", ZIM_HOST_DEEP_LINK_SCHEME) ) { val searchString = if (intent.data == null) "" else intent.data?.lastPathSegment openSearch( diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt index 18bba6130..a29e61fc2 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt @@ -37,6 +37,8 @@ import org.kiwix.kiwixmobile.core.extensions.browserIntent import org.kiwix.kiwixmobile.core.main.ACTION_NEW_TAB import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.DrawerMenuItem +import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_ABOUT_APP_ITEM_TESTING_TAG +import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.main.NEW_TAB_SHORTCUT_ID import org.kiwix.kiwixmobile.core.utils.dialog.DialogHost import org.kiwix.kiwixmobile.custom.BuildConfig @@ -117,7 +119,8 @@ class CustomMainActivity : CoreMainActivity() { onClick = { closeNavigationDrawer() externalLinkOpener.openExternalUrl(BuildConfig.SUPPORT_URL.toUri().browserIntent(), false) - } + }, + testingTag = LEFT_DRAWER_SUPPORT_ITEM_TESTING_TAG ) } else { /** @@ -146,7 +149,8 @@ class CustomMainActivity : CoreMainActivity() { BuildConfig.ABOUT_APP_URL.toUri().browserIntent(), false ) - } + }, + testingTag = LEFT_DRAWER_ABOUT_APP_ITEM_TESTING_TAG ) } else { null diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index 15176467b..d00b965fc 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt @@ -34,6 +34,7 @@ import org.kiwix.kiwixmobile.core.extensions.browserIntent import org.kiwix.kiwixmobile.core.extensions.isFileExist import org.kiwix.kiwixmobile.core.extensions.update import org.kiwix.kiwixmobile.core.main.CoreMainActivity +import org.kiwix.kiwixmobile.core.main.PAGE_URL_KEY import org.kiwix.kiwixmobile.core.main.reader.CoreReaderFragment import org.kiwix.kiwixmobile.core.main.reader.ReaderMenuState import org.kiwix.kiwixmobile.core.main.reader.RestoreOrigin @@ -173,9 +174,9 @@ class CustomReaderFragment : CoreReaderFragment() { } private fun loadPageFromNavigationArguments() { - val args = CustomReaderFragmentArgs.fromBundle(requireArguments()) - if (args.pageUrl.isNotEmpty()) { - loadUrlWithCurrentWebview(args.pageUrl) + val pageUrl = arguments?.getString(PAGE_URL_KEY).orEmpty() + if (pageUrl.isNotEmpty()) { + loadUrlWithCurrentWebview(pageUrl) // Setup bookmark for current book // See https://github.com/kiwix/kiwix-android/issues/3541 zimReaderContainer?.zimFileReader?.let(::setUpBookmarks) diff --git a/custom/src/main/res/layout/activity_custom_main.xml b/custom/src/main/res/layout/activity_custom_main.xml deleted file mode 100644 index 86faa6017..000000000 --- a/custom/src/main/res/layout/activity_custom_main.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - diff --git a/custom/src/main/res/navigation/custom_nav_graph.xml b/custom/src/main/res/navigation/custom_nav_graph.xml deleted file mode 100644 index 198bb8c4b..000000000 --- a/custom/src/main/res/navigation/custom_nav_graph.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -