LibraryBadgeSummaryTest.kt
composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/ui/screens/library/LibraryBadgeSummaryTest.kt
1package eu.friedcutlet.yokan.ui.screens.library23import eu.friedcutlet.yokan.data.buildCompletedDownloadCountsByChapterId4import eu.friedcutlet.yokan.database.DbDownload5import eu.friedcutlet.yokan.domain.Chapter6import kotlin.test.Test7import kotlin.test.assertEquals89class LibraryBadgeSummaryTest {10 @Test11 fun countsUnreadChaptersAndEveryCompletedDownloadButIgnoresMissingOrIncompleteIds() {12 val downloads = listOf(13 DbDownload(id = 1, chapterId = 11, isDownload = true),14 DbDownload(id = 2, chapterId = 11, isDownload = true),15 DbDownload(id = 3, chapterId = 12, isDownload = false),16 DbDownload(id = 4, chapterId = null, isDownload = true),17 DbDownload(id = 5, chapterId = 99, isDownload = true),18 )19 val summaries = buildLibraryBadgeSummaries(20 chaptersByManga = mapOf(21 7L to listOf(22 chapter(11, isRead = false),23 chapter(12, isRead = true),24 ),25 8L to emptyList(),26 ),27 completedDownloadCountsByChapterId = buildCompletedDownloadCountsByChapterId(downloads),28 )2930 assertEquals(LibraryBadgeSummary(unreadCount = 1, downloadedCount = 2, totalCount = 2, readCount = 1), summaries[7L])31 assertEquals(0.5f, summaries[7L]?.progress)32 assertEquals(LibraryBadgeSummary(), summaries[8L])33 assertEquals(0f, summaries[8L]?.progress)34 assertEquals(mapOf(11L to 2, 99L to 1), buildCompletedDownloadCountsByChapterId(downloads))35 }3637 private fun chapter(id: Long, isRead: Boolean) = Chapter(38 id = id,39 mangaId = 7,40 name = "Chapter $id",41 url = "/chapter/$id",42 isRead = isRead,43 )44}45