Added UI test cases for bookmarks and notes to verify that saved items open the exact page in the reader.

This commit is contained in:
MohitMaliFtechiz 2025-08-18 17:08:19 +05:30 committed by Kelson
parent 629a7f18dc
commit d2ce4a71a1
4 changed files with 208 additions and 27 deletions

View File

@ -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() { private fun deletePreviouslySavedNotes() {
// delete the notes if any saved to properly run the test scenario // delete the notes if any saved to properly run the test scenario
note { note {

View File

@ -32,6 +32,7 @@ import androidx.compose.ui.test.performTextReplacement
import androidx.test.espresso.Espresso.closeSoftKeyboard import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.espresso.web.sugar.Web.onWebView
import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.findElement
import androidx.test.espresso.web.webdriver.DriverAtoms.webClick
import androidx.test.espresso.web.webdriver.Locator import androidx.test.espresso.web.webdriver.Locator
import com.adevinta.android.barista.interaction.BaristaSleepInteractions import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import org.kiwix.kiwixmobile.BaseRobot 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.DELETE_MENU_BUTTON_TESTING_TAG
import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_NOTES_ITEM_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.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.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.DELETE_MENU_ICON_TESTING_TAG
import org.kiwix.kiwixmobile.core.page.NO_ITEMS_TEXT_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() { private fun pauseForBetterTestPerformance() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
} }

View File

@ -24,11 +24,18 @@ import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.ComposeTestRule import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.longClick import androidx.compose.ui.test.longClick
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performScrollToNode
import androidx.compose.ui.test.performTouchInput 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 applyWithViewHierarchyPrinting
import com.adevinta.android.barista.interaction.BaristaSleepInteractions import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import org.kiwix.kiwixmobile.BaseRobot 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.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.LEFT_DRAWER_BOOKMARK_ITEM_TESTING_TAG 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_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.DELETE_MENU_ICON_TESTING_TAG
import org.kiwix.kiwixmobile.core.page.NO_ITEMS_TEXT_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.PAGE_LIST_TEST_TAG
import org.kiwix.kiwixmobile.core.page.SWITCH_TEXT_TESTING_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.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_CONFIRM_BUTTON_TESTING_TAG
import org.kiwix.kiwixmobile.core.utils.dialog.ALERT_DIALOG_TITLE_TEXT_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
import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS
import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST 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()
}
})
}
} }

View File

@ -121,19 +121,7 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
@Test @Test
fun testBookmarks() { fun testBookmarks() {
composeTestRule.apply { openZimFileInReader()
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.
}
bookmarks { bookmarks {
// delete any bookmark if already saved to properly perform this test case. // delete any bookmark if already saved to properly perform this test case.
longClickOnSaveBookmarkImage(composeTestRule) longClickOnSaveBookmarkImage(composeTestRule)
@ -186,22 +174,37 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
} }
} }
@Test
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 @Test
fun testSavedBookmarksShowingOnBookmarkScreen() { fun testSavedBookmarksShowingOnBookmarkScreen() {
val zimFile = getZimFile() openZimFileInReader()
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()
}
bookmarks { bookmarks {
// delete any bookmark if already saved to properly perform this test case. // delete any bookmark if already saved to properly perform this test case.
longClickOnSaveBookmarkImage(composeTestRule) 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 { private fun getZimFile(): File {
val loadFileStream = val loadFileStream =
LibkiwixBookmarkTest::class.java.classLoader.getResourceAsStream("testzim.zim") LibkiwixBookmarkTest::class.java.classLoader.getResourceAsStream("testzim.zim")