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 d45efb172..ceafc4d55 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -237,6 +237,26 @@ class NoteFragmentTest : BaseActivityTest() { } } + @Test + fun testSavedNotePageOpenInReader() { + deletePreviouslySavedNotes() + loadZimFileInReader("testzim.zim") + note { + assertHomePageIsLoadedOfTestZimFile() + clickOnAndroidArticle(composeTestRule) + clickOnNoteMenuItem(composeTestRule) + assertNoteDialogDisplayed(composeTestRule) + writeDemoNote(composeTestRule) + saveNote(composeTestRule) + closeAddNoteDialog(composeTestRule) + clickOnBackwardButton(composeTestRule) + openNoteFragment(kiwixMainActivity as CoreMainActivity, composeTestRule) + clickOnSavedNote(composeTestRule) + clickOnOpenArticle(composeTestRule) + assertAndroidArticleLoadedInReader(composeTestRule) + } + } + private fun deletePreviouslySavedNotes() { // delete the notes if any saved to properly run the test scenario note { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteRobot.kt index d452d2c06..9915086a7 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteRobot.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.test.performTextReplacement import androidx.test.espresso.Espresso.closeSoftKeyboard import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.espresso.web.webdriver.DriverAtoms.findElement +import androidx.test.espresso.web.webdriver.DriverAtoms.webClick import androidx.test.espresso.web.webdriver.Locator import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot @@ -42,6 +43,7 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.DELETE_MENU_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_NOTES_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.main.SAVE_MENU_BUTTON_TESTING_TAG +import org.kiwix.kiwixmobile.core.main.reader.READER_BOTTOM_BAR_PREVIOUS_SCREEN_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.core.main.reader.TAKE_NOTE_MENU_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.page.DELETE_MENU_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.page.NO_ITEMS_TEXT_TESTING_TAG @@ -251,6 +253,62 @@ class NoteRobot : BaseRobot() { }) } + fun clickOnAndroidArticle(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + onWebView() + .withElement( + findElement( + Locator.XPATH, + "//*[contains(text(), 'Android_(operating_system)')]" + ) + ) + .perform(webClick()) + } + }) + } + + fun clickOnBackwardButton(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitForIdle() + waitUntil(TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong()) { + onNodeWithTag(READER_BOTTOM_BAR_PREVIOUS_SCREEN_BUTTON_TESTING_TAG).isDisplayed() + } + onNodeWithTag(READER_BOTTOM_BAR_PREVIOUS_SCREEN_BUTTON_TESTING_TAG) + .performClick() + } + } + + fun clickOnOpenArticle(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitUntil( + TestUtils.TEST_PAUSE_MS.toLong() + ) { onNodeWithTag(ALERT_DIALOG_CONFIRM_BUTTON_TESTING_TAG).isDisplayed() } + onNodeWithTag(ALERT_DIALOG_CONFIRM_BUTTON_TESTING_TAG) + .performClick() + } + }) + } + + fun assertAndroidArticleLoadedInReader(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + waitUntilTimeout() + onWebView() + .withElement( + findElement( + Locator.XPATH, + "//*[contains(text(), 'History')]" + ) + ) + .perform(webClick()) + } + }) + } + private fun pauseForBetterTestPerformance() { BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/BookmarksRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/BookmarksRobot.kt index ba8307860..27dab1c5f 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/BookmarksRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/BookmarksRobot.kt @@ -24,11 +24,18 @@ import androidx.compose.ui.test.isDisplayed import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.junit4.ComposeTestRule import androidx.compose.ui.test.longClick +import androidx.compose.ui.test.onAllNodesWithTag import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performTouchInput +import androidx.test.espresso.web.sugar.Web +import androidx.test.espresso.web.sugar.Web.onWebView +import androidx.test.espresso.web.webdriver.DriverAtoms +import androidx.test.espresso.web.webdriver.DriverAtoms.findElement +import androidx.test.espresso.web.webdriver.DriverAtoms.webClick +import androidx.test.espresso.web.webdriver.Locator import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot @@ -36,13 +43,16 @@ import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_BOOKMARK_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.main.reader.READER_BOTTOM_BAR_BOOKMARK_BUTTON_TESTING_TAG +import org.kiwix.kiwixmobile.core.main.reader.READER_BOTTOM_BAR_PREVIOUS_SCREEN_BUTTON_TESTING_TAG import org.kiwix.kiwixmobile.core.page.DELETE_MENU_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.page.NO_ITEMS_TEXT_TESTING_TAG +import org.kiwix.kiwixmobile.core.page.PAGE_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.core.page.PAGE_LIST_TEST_TAG import org.kiwix.kiwixmobile.core.page.SWITCH_TEXT_TESTING_TAG import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_CONFIRM_BUTTON_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.TEST_PAUSE_MS import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST @@ -181,4 +191,77 @@ class BookmarksRobot : BaseRobot() { } } } + + fun assertZimFileLoadedIntoTheReader(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitUntilTimeout() + composeTestRule.apply { + waitUntilTimeout() + onNodeWithTag(BOTTOM_NAV_READER_ITEM_TESTING_TAG).performClick() + } + } + testFlakyView({ + Web.onWebView() + .withElement( + DriverAtoms.findElement( + Locator.XPATH, + "//*[contains(text(), 'Android_(operating_system)')]" + ) + ) + }) + } + + fun clickOnAndroidArticle(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + onWebView() + .withElement( + findElement( + Locator.XPATH, + "//*[contains(text(), 'Android_(operating_system)')]" + ) + ) + .perform(webClick()) + } + }) + } + + fun assertAndroidArticleLoadedInReader(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + onWebView() + .withElement( + findElement( + Locator.XPATH, + "//*[contains(text(), 'History')]" + ) + ) + .perform(webClick()) + } + }) + } + + fun clickOnBackwardButton(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitForIdle() + // wait for disappearing the snack-bar after removing the bookmark + waitUntilTimeout(TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong()) + waitUntil(TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong()) { + onNodeWithTag(READER_BOTTOM_BAR_PREVIOUS_SCREEN_BUTTON_TESTING_TAG).isDisplayed() + } + onNodeWithTag(READER_BOTTOM_BAR_PREVIOUS_SCREEN_BUTTON_TESTING_TAG) + .performClick() + } + } + + fun openBookmarkInReader(composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + onAllNodesWithTag(PAGE_ITEM_TESTING_TAG)[0].performClick() + } + }) + } } 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 a9ff53357..c6ec4c07a 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 @@ -121,19 +121,7 @@ class LibkiwixBookmarkTest : BaseActivityTest() { @Test fun testBookmarks() { - composeTestRule.apply { - runOnUiThread { - kiwixMainActivity.navigate(KiwixDestination.Library.route) - val navOptions = NavOptions.Builder() - .setPopUpTo(KiwixDestination.Reader.route, false) - .build() - kiwixMainActivity.navigate( - KiwixDestination.Reader.createRoute(zimFileUri = getZimFile().toUri().toString()), - navOptions - ) - } - waitComposeToSettleViews() // to load the ZIM file properly. - } + openZimFileInReader() bookmarks { // delete any bookmark if already saved to properly perform this test case. longClickOnSaveBookmarkImage(composeTestRule) @@ -187,21 +175,36 @@ class LibkiwixBookmarkTest : BaseActivityTest() { } @Test - fun testSavedBookmarksShowingOnBookmarkScreen() { - val zimFile = getZimFile() - composeTestRule.apply { - runOnUiThread { - kiwixMainActivity.navigate(KiwixDestination.Library.route) - val navOptions = NavOptions.Builder() - .setPopUpTo(KiwixDestination.Reader.route, false) - .build() - kiwixMainActivity.navigate( - KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), - navOptions - ) - } - waitForIdle() + fun testBookMarkPageOpenInReader() { + openZimFileInReader() + bookmarks { + openBookmarkScreen(kiwixMainActivity as CoreMainActivity, composeTestRule) + clickOnTrashIcon(composeTestRule) + assertDeleteBookmarksDialogDisplayed(composeTestRule) + clickOnDeleteButton(composeTestRule) + assertNoBookMarkTextDisplayed(composeTestRule) + pressBack() + waitComposeToSettleViews() // to properly load the ZIM file in reader. + assertZimFileLoadedIntoTheReader(composeTestRule) + clickOnAndroidArticle(composeTestRule) + waitComposeToSettleViews() + assertAndroidArticleLoadedInReader(composeTestRule) + // Save bookmark + clickOnSaveBookmarkImage(composeTestRule) + // open previous page + clickOnBackwardButton(composeTestRule) + // open bookmark screen. + openBookmarkScreen(kiwixMainActivity as CoreMainActivity, composeTestRule) + // tries to open the bookmark page in reader. + openBookmarkInReader(composeTestRule) + waitComposeToSettleViews() + assertAndroidArticleLoadedInReader(composeTestRule) } + } + + @Test + fun testSavedBookmarksShowingOnBookmarkScreen() { + openZimFileInReader() bookmarks { // delete any bookmark if already saved to properly perform this test case. longClickOnSaveBookmarkImage(composeTestRule) @@ -247,6 +250,23 @@ class LibkiwixBookmarkTest : BaseActivityTest() { } } + private fun openZimFileInReader() { + val zimFile = getZimFile() + composeTestRule.apply { + runOnUiThread { + kiwixMainActivity.navigate(KiwixDestination.Library.route) + val navOptions = NavOptions.Builder() + .setPopUpTo(KiwixDestination.Reader.route, false) + .build() + kiwixMainActivity.navigate( + KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), + navOptions + ) + } + waitComposeToSettleViews() + } + } + private fun getZimFile(): File { val loadFileStream = LibkiwixBookmarkTest::class.java.classLoader.getResourceAsStream("testzim.zim")