Improve backup test reliability and cleanup

This commit is contained in:
Alinson S. Xavier 2026-04-11 19:22:28 -05:00
parent 92be0af271
commit 78770dd2d2
2 changed files with 18 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.DELETE
import org.isoron.uhabits.acceptance.steps.ListHabitsSteps.clickMenu
import org.isoron.uhabits.acceptance.steps.clearBackupFolder
import org.isoron.uhabits.acceptance.steps.clearDownloadFolder
import org.isoron.uhabits.acceptance.steps.clearPublicBackupFolderSelection
import org.isoron.uhabits.acceptance.steps.copyBackupToDownloadFolder
import org.isoron.uhabits.acceptance.steps.exportFullBackup
import org.isoron.uhabits.acceptance.steps.importBackupFromDownloadFolder
@ -62,5 +63,6 @@ class BackupTest : BaseUserInterfaceTest() {
selectPublicBackupFolder()
exportFullBackup()
verifyBackupInDownloadFolder()
clearPublicBackupFolderSelection()
}
}

View File

@ -53,8 +53,13 @@ fun clearBackupFolder() {
}
fun copyBackupToDownloadFolder() {
val srcListing = device.executeShellCommand("ls $BACKUP_FOLDER")
assertTrue("Backup folder is empty. Contents: [$srcListing]", srcListing.contains("Loop Habits Backup"))
device.executeShellCommand("rm -rf $DOWNLOAD_FOLDER")
device.executeShellCommand("mv $BACKUP_FOLDER $DOWNLOAD_FOLDER")
device.executeShellCommand("chown root $DOWNLOAD_FOLDER")
val dstListing = device.executeShellCommand("ls $DOWNLOAD_FOLDER")
assertTrue("Backup not found in download folder. Contents: [$dstListing]", dstListing.contains("Loop Habits Backup"))
}
fun selectPublicBackupFolder() {
@ -64,6 +69,12 @@ fun selectPublicBackupFolder() {
prefs.edit().putString("publicBackupFolder", uri.toString()).commit()
}
fun clearPublicBackupFolderSelection() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit().remove("publicBackupFolder").commit()
}
fun importBackupFromDownloadFolder() {
clickMenu(SETTINGS)
clickText("Import data")
@ -110,6 +121,11 @@ fun verifyBackupInDownloadFolder() {
assertTrue(listing.contains("Loop Habits Backup"))
}
fun verifyBackupInBackupFolder() {
val listing = device.executeShellCommand("ls $BACKUP_FOLDER")
assertTrue(listing.contains("Loop Habits Backup"))
}
fun openLauncher() {
device.pressHome()
device.waitForIdle()