mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 15:27:55 -04:00
Merge pull request #4195 from kiwix/Fixes#4194
Fixed: When a note is deleted, the corresponding file remained in storage.
This commit is contained in:
commit
e61e3e8347
@ -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 {
|
||||
@ -188,17 +178,7 @@ class NoteFragmentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun testZimFileOpenedAfterOpeningNoteOnNotesScreen() {
|
||||
// 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")
|
||||
note {
|
||||
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) {
|
||||
activityScenario.onActivity {
|
||||
kiwixMainActivity = it
|
||||
|
@ -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
|
||||
@ -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()) })
|
||||
}
|
||||
|
@ -23,10 +23,16 @@ import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import io.reactivex.Flowable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.extensions.deleteFile
|
||||
import org.kiwix.kiwixmobile.core.extensions.isFileExist
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource.Companion.fromDatabaseValue
|
||||
import java.io.File
|
||||
|
||||
@Dao
|
||||
abstract class NotesRoomDao : PageDao {
|
||||
@ -71,6 +77,22 @@ abstract class NotesRoomDao : PageDao {
|
||||
notesList.forEachIndexed { _, note ->
|
||||
val notesRoomEntity = NotesRoomEntity(note)
|
||||
deleteNote(noteTitle = notesRoomEntity.noteTitle)
|
||||
removeNoteFileFromStorage(notesRoomEntity.noteFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the saved file from storage.
|
||||
* When the user deletes a note from the "Notes" screen,
|
||||
* the associated file should also be removed from storage,
|
||||
* as it is no longer needed.
|
||||
*/
|
||||
private fun removeNoteFileFromStorage(noteFilePath: String) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val noteFile = File(noteFilePath)
|
||||
if (noteFile.isFileExist()) {
|
||||
noteFile.deleteFile()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ class AddNoteDialog : DialogFragment() {
|
||||
val noteText = dialogNoteAddNoteBinding?.addNoteEditText?.text.toString()
|
||||
if (noteDeleted) {
|
||||
dialogNoteAddNoteBinding?.addNoteEditText?.text?.clear()
|
||||
mainRepositoryActions.deleteNote(articleNoteFileName)
|
||||
mainRepositoryActions.deleteNote(getNoteTitle())
|
||||
disableMenuItems()
|
||||
view?.snack(
|
||||
stringId = R.string.note_delete_successful,
|
||||
|
Loading…
x
Reference in New Issue
Block a user