Fix badges tests
This commit is contained in:
parent
6cb4b35c93
commit
2968aee309
@ -132,12 +132,13 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
badgeStarred = response.data.starred
|
badgeStarred = response.data.starred
|
||||||
success = true
|
success = true
|
||||||
}
|
}
|
||||||
} else {
|
} else if (appSettingsService.isItemCachingEnabled()) {
|
||||||
// TODO: do this differently, because it's not efficient
|
// TODO: do this differently, because it's not efficient
|
||||||
val dbItems = getDBItems()
|
val dbItems = getDBItems()
|
||||||
badgeUnread = dbItems.filter { item -> item.unread }.size
|
badgeUnread = dbItems.filter { item -> item.unread }.size
|
||||||
badgeStarred = dbItems.filter { item -> item.starred }.size
|
badgeStarred = dbItems.filter { item -> item.starred }.size
|
||||||
badgeAll = items.size
|
badgeAll = dbItems.size
|
||||||
|
success = true
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class RepositoryTest() {
|
|||||||
every { appSettingsService.getApiVersion() } returns 4
|
every { appSettingsService.getApiVersion() } returns 4
|
||||||
every { appSettingsService.getBaseUrl() } returns "https://test.com/selfoss/"
|
every { appSettingsService.getBaseUrl() } returns "https://test.com/selfoss/"
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
|
|
||||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(true)
|
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(true)
|
||||||
|
|
||||||
@ -258,24 +258,19 @@ class RepositoryTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Reload badges with items caching`() {
|
fun `Reload badges without connection`() {
|
||||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||||
every { db.itemsQueries.items().executeAsList() } returns generateTestDBItems()
|
every { db.itemsQueries.items().executeAsList() } returns generateTestDBItems()
|
||||||
|
|
||||||
val itemParameter = FakeItemParameters()
|
|
||||||
itemParameter.starred = true
|
|
||||||
itemParameter.unread = false
|
|
||||||
|
|
||||||
var success = false
|
var success = false
|
||||||
|
|
||||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
repository.items = ArrayList(generateTestApiItem(itemParameter))
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
success = repository.reloadBadges()
|
success = repository.reloadBadges()
|
||||||
}
|
}
|
||||||
|
|
||||||
assertSame(true, success)
|
assertTrue(success)
|
||||||
assertSame(1, repository.badgeAll)
|
assertSame(1, repository.badgeAll)
|
||||||
assertSame(1, repository.badgeUnread)
|
assertSame(1, repository.badgeUnread)
|
||||||
assertSame(1, repository.badgeStarred)
|
assertSame(1, repository.badgeStarred)
|
||||||
@ -284,23 +279,19 @@ class RepositoryTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Reload badges without items caching`() {
|
fun `Reload badges without connection and items caching disabled`() {
|
||||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
|
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||||
val itemParameter = FakeItemParameters()
|
|
||||||
itemParameter.starred = true
|
|
||||||
itemParameter.unread = false
|
|
||||||
|
|
||||||
var success = false
|
var success = false
|
||||||
|
|
||||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
repository.items = ArrayList(generateTestApiItem(itemParameter))
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
success = repository.reloadBadges()
|
success = repository.reloadBadges()
|
||||||
}
|
}
|
||||||
|
|
||||||
assertSame(false, success)
|
assertFalse(success)
|
||||||
assertSame(0, repository.badgeAll)
|
assertSame(0, repository.badgeAll)
|
||||||
assertSame(0, repository.badgeUnread)
|
assertSame(0, repository.badgeUnread)
|
||||||
assertSame(0, repository.badgeStarred)
|
assertSame(0, repository.badgeStarred)
|
||||||
|
Loading…
Reference in New Issue
Block a user