Skip to content

Commit

Permalink
Added UI test cases for testing these both scenarios.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper authored and kelson42 committed Jan 31, 2025
1 parent 73ea170 commit 561af8f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,7 @@ class NoteFragmentTest : BaseActivityTest() {

@Test
fun testUserCanSeeNotesForDeletedFiles() {
// delete the notes if any saved to properly run the test scenario
note {
openNoteFragment()
assertToolbarExist()
assertNoteRecyclerViewExist()
clickOnTrashIcon()
assertDeleteNoteDialogDisplayed()
clickOnDeleteButton()
assertNoNotesTextDisplayed()
pressBack()
}
deletePreviouslySavedNotes()
loadZimFileInReader("testzim.zim")
StandardActions.closeDrawer() // close the drawer if open before running the test cases.
note {
Expand Down Expand Up @@ -188,20 +178,33 @@ class NoteFragmentTest : BaseActivityTest() {

@Test
fun testZimFileOpenedAfterOpeningNoteOnNotesScreen() {
// delete the notes if any saved to properly run the test scenario
deletePreviouslySavedNotes()
loadZimFileInReader("testzim.zim")
note {
assertHomePageIsLoadedOfTestZimFile()
clickOnNoteMenuItem(context)
assertNoteDialogDisplayed()
writeDemoNote()
saveNote()
pressBack()
openNoteFragment()
assertToolbarExist()
assertNoteRecyclerViewExist()
clickOnTrashIcon()
assertDeleteNoteDialogDisplayed()
clickOnDeleteButton()
assertNoNotesTextDisplayed()
clickOnSavedNote()
clickOnOpenNote()
assertNoteSaved()
// to close the note dialog.
pressBack()
// to close the notes fragment.
pressBack()
}
}

@Test
fun testNoteEntryIsRemovedFromDatabaseWhenDeletedInAddNoteDialog() {
deletePreviouslySavedNotes()
loadZimFileInReader("testzim.zim")
note {
assertHomePageIsLoadedOfTestZimFile()
clickOnNoteMenuItem(context)
assertNoteDialogDisplayed()
writeDemoNote()
Expand All @@ -213,9 +216,45 @@ class NoteFragmentTest : BaseActivityTest() {
clickOnSavedNote()
clickOnOpenNote()
assertNoteSaved()
// to close the note dialog.
clickOnDeleteIcon()
pressBack()
// to close the notes fragment.
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()
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteRobot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.action.ViewActions.clearText
import androidx.test.espresso.action.ViewActions.click
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.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
Expand Down Expand Up @@ -111,6 +112,15 @@ class NoteRobot : BaseRobot() {
testFlakyView({ isVisible(Text(noteText)) })
}

fun assertNotDoesNotExist() {
testFlakyView({ onView(withText(noteText)).check(doesNotExist()) })
}

fun clickOnDeleteIcon() {
pauseForBetterTestPerformance()
testFlakyView({ clickOn(ViewId(R.id.delete_note)) })
}

fun clickOnTrashIcon() {
testFlakyView({ onView(withContentDescription(R.string.pref_clear_notes)).perform(click()) })
}
Expand Down

0 comments on commit 561af8f

Please sign in to comment.