From d0a982f385ca6e74ac740498a2291b6711330931 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 8 Oct 2022 17:15:41 +0200 Subject: [PATCH] Add tests for offline filtering --- .../repository/RepositoryTest.kt | 58 ++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt index decac9d..b1cc19e 100644 --- a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt +++ b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt @@ -173,6 +173,60 @@ class RepositoryTest() { verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} } + @Test + fun `Get newer items without connectivity and tag filter`() { + val itemParameter1 = FakeItemParameters() + val itemParameter2 = FakeItemParameters() + val itemParameter3 = FakeItemParameters() + itemParameter2.tags = "Test, Stuff" + itemParameter3.tags = "Other, Tag" + coEvery { db.itemsQueries.items().executeAsList() } returnsMany listOf( + generateTestDBItems(itemParameter1), + generateTestDBItems(itemParameter2), + generateTestDBItems(itemParameter3) + ) + + every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) + every { appSettingsService.isItemCachingEnabled() } returns true + + val repository = Repository(api, appSettingsService, connectivityStatus, db) + repository.tagFilter = SelfossModel.Tag("Test", "red", 3) + runBlocking { + repository.getNewerItems() + } + + assertSame(repository.items.size, 1) + coVerify(exactly = 0) { api.getItems("unread", 0, null, null, null, null, any()) } + verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} + } + + @Test + fun `Get newer items without connectivity and source filter`() { + val itemParameter1 = FakeItemParameters() + val itemParameter2 = FakeItemParameters() + val itemParameter3 = FakeItemParameters() + itemParameter2.sourcetitle = "Test" + itemParameter3.sourcetitle = "Other" + coEvery { db.itemsQueries.items().executeAsList() } returnsMany listOf( + generateTestDBItems(itemParameter1), + generateTestDBItems(itemParameter2), + generateTestDBItems(itemParameter3) + ) + + every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) + every { appSettingsService.isItemCachingEnabled() } returns true + + val repository = Repository(api, appSettingsService, connectivityStatus, db) + repository.sourceFilter = SelfossModel.Source(1, "Test", listOf("tags"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png") + runBlocking { + repository.getNewerItems() + } + + assertSame(repository.items.size, 1) + coVerify(exactly = 0) { api.getItems("unread", 0, null, null, null, null, any()) } + verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} + } + @Test fun `Get older items`() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns @@ -998,6 +1052,6 @@ class FakeItemParameters() { val thumbnail = null val icon = "ba79e238383ce83c23a169929c8906ef.png" val link = "https://ilblogdellasci.wordpress.com/2022/09/09/etica-della-ricerca-sotto-i-riflettori/" - val sourcetitle = "La Chimica e la Società" - val tags = "Chimica, Testing" + var sourcetitle = "La Chimica e la Società" + var tags = "Chimica, Testing" } \ No newline at end of file