From 8ded3d350ac8b8b0bc0b855f055710afcb842547 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 16 Jan 2025 11:41:06 +0530 Subject: [PATCH] Fixed: Failing unit test case. * Added a new unit test to verify that books located in the trash folder do not appear on the library screen. --- .../kiwix/kiwixmobile/core/dao/NewBookDaoTest.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewBookDaoTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewBookDaoTest.kt index 91209c4d8..3fd8b7c65 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewBookDaoTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewBookDaoTest.kt @@ -81,7 +81,17 @@ internal class NewBookDaoTest { verify { box.remove(listOf(deletedEntity)) } } - private fun expectEmissionOfExistingAndNotExistingBook(): + @Test + fun `books removes entities whose files are in the trash folder`() { + runBlocking { + val (_, _) = expectEmissionOfExistingAndNotExistingBook(true) + val books = newBookDao.books().test() + delay(1000) + books.assertValues(emptyList()) + } + } + + private fun expectEmissionOfExistingAndNotExistingBook(isInTrashFolder: Boolean = false): Pair { val query: Query = mockk() every { box.query().build() } returns query @@ -89,6 +99,10 @@ internal class NewBookDaoTest { val zimReaderSourceThatDoesNotExist = mockk() coEvery { zimReaderSourceThatExists.exists() } returns true coEvery { zimReaderSourceThatDoesNotExist.exists() } returns false + every { + zimReaderSourceThatExists.toDatabase() + } returns if (isInTrashFolder) "/.Trash/test.zim" else "" + every { zimReaderSourceThatDoesNotExist.toDatabase() } returns "" val entityThatExists = bookOnDiskEntity(zimReaderSource = zimReaderSourceThatExists) val entityThatDoesNotExist = bookOnDiskEntity(zimReaderSource = zimReaderSourceThatDoesNotExist)