Added UI test cases for testing these both scenarios.

This commit is contained in:
MohitMaliFtechiz 2025-01-29 15:49:08 +05:30 committed by Kelson
parent 73ea170b03
commit 561af8f735
2 changed files with 71 additions and 22 deletions

View File

@ -129,17 +129,7 @@ class NoteFragmentTest : BaseActivityTest() {
@Test @Test
fun testUserCanSeeNotesForDeletedFiles() { fun testUserCanSeeNotesForDeletedFiles() {
// delete the notes if any saved to properly run the test scenario deletePreviouslySavedNotes()
note {
openNoteFragment()
assertToolbarExist()
assertNoteRecyclerViewExist()
clickOnTrashIcon()
assertDeleteNoteDialogDisplayed()
clickOnDeleteButton()
assertNoNotesTextDisplayed()
pressBack()
}
loadZimFileInReader("testzim.zim") loadZimFileInReader("testzim.zim")
StandardActions.closeDrawer() // close the drawer if open before running the test cases. StandardActions.closeDrawer() // close the drawer if open before running the test cases.
note { note {
@ -188,17 +178,7 @@ class NoteFragmentTest : BaseActivityTest() {
@Test @Test
fun testZimFileOpenedAfterOpeningNoteOnNotesScreen() { fun testZimFileOpenedAfterOpeningNoteOnNotesScreen() {
// delete the notes if any saved to properly run the test scenario deletePreviouslySavedNotes()
note {
openNoteFragment()
assertToolbarExist()
assertNoteRecyclerViewExist()
clickOnTrashIcon()
assertDeleteNoteDialogDisplayed()
clickOnDeleteButton()
assertNoNotesTextDisplayed()
pressBack()
}
loadZimFileInReader("testzim.zim") loadZimFileInReader("testzim.zim")
note { note {
assertHomePageIsLoadedOfTestZimFile() assertHomePageIsLoadedOfTestZimFile()
@ -220,6 +200,65 @@ class NoteFragmentTest : BaseActivityTest() {
} }
} }
@Test
fun testNoteEntryIsRemovedFromDatabaseWhenDeletedInAddNoteDialog() {
deletePreviouslySavedNotes()
loadZimFileInReader("testzim.zim")
note {
clickOnNoteMenuItem(context)
assertNoteDialogDisplayed()
writeDemoNote()
saveNote()
pressBack()
openNoteFragment()
assertToolbarExist()
assertNoteRecyclerViewExist()
clickOnSavedNote()
clickOnOpenNote()
assertNoteSaved()
clickOnDeleteIcon()
pressBack()
assertNoNotesTextDisplayed()
}
}
@Test
fun testNoteFileIsDeletedWhenNoteIsRemovedFromNotesScreen() {
deletePreviouslySavedNotes()
loadZimFileInReader("testzim.zim")
// Save a note.
note {
clickOnNoteMenuItem(context)
assertNoteDialogDisplayed()
writeDemoNote()
saveNote()
pressBack()
}
// Delete that note from "Note" screen.
deletePreviouslySavedNotes()
// Test the note file is deleted or not.
note {
clickOnNoteMenuItem(context)
assertNoteDialogDisplayed()
assertNotDoesNotExist()
pressBack()
}
}
private fun deletePreviouslySavedNotes() {
// delete the notes if any saved to properly run the test scenario
note {
openNoteFragment()
assertToolbarExist()
assertNoteRecyclerViewExist()
clickOnTrashIcon()
assertDeleteNoteDialogDisplayed()
clickOnDeleteButton()
assertNoNotesTextDisplayed()
pressBack()
}
}
private fun loadZimFileInReader(zimFileName: String) { private fun loadZimFileInReader(zimFileName: String) {
activityScenario.onActivity { activityScenario.onActivity {
kiwixMainActivity = it kiwixMainActivity = it

View File

@ -26,6 +26,7 @@ import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.action.ViewActions.clearText import androidx.test.espresso.action.ViewActions.clearText
import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
@ -111,6 +112,15 @@ class NoteRobot : BaseRobot() {
testFlakyView({ isVisible(Text(noteText)) }) testFlakyView({ isVisible(Text(noteText)) })
} }
fun assertNotDoesNotExist() {
testFlakyView({ onView(withText(noteText)).check(doesNotExist()) })
}
fun clickOnDeleteIcon() {
pauseForBetterTestPerformance()
testFlakyView({ clickOn(ViewId(R.id.delete_note)) })
}
fun clickOnTrashIcon() { fun clickOnTrashIcon() {
testFlakyView({ onView(withContentDescription(R.string.pref_clear_notes)).perform(click()) }) testFlakyView({ onView(withContentDescription(R.string.pref_clear_notes)).perform(click()) })
} }