package eu.friedcutlet.yokan.ui.screens.library import eu.friedcutlet.yokan.data.buildCompletedDownloadCountsByChapterId import eu.friedcutlet.yokan.database.DbDownload import eu.friedcutlet.yokan.domain.Chapter import kotlin.test.Test import kotlin.test.assertEquals class LibraryBadgeSummaryTest { @Test fun countsUnreadChaptersAndEveryCompletedDownloadButIgnoresMissingOrIncompleteIds() { val downloads = listOf( DbDownload(id = 1, chapterId = 11, isDownload = true), DbDownload(id = 2, chapterId = 11, isDownload = true), DbDownload(id = 3, chapterId = 12, isDownload = false), DbDownload(id = 4, chapterId = null, isDownload = true), DbDownload(id = 5, chapterId = 99, isDownload = true), ) val summaries = buildLibraryBadgeSummaries( chaptersByManga = mapOf( 7L to listOf( chapter(11, isRead = false), chapter(12, isRead = true), ), 8L to emptyList(), ), completedDownloadCountsByChapterId = buildCompletedDownloadCountsByChapterId(downloads), ) assertEquals(LibraryBadgeSummary(unreadCount = 1, downloadedCount = 2, totalCount = 2, readCount = 1), summaries[7L]) assertEquals(0.5f, summaries[7L]?.progress) assertEquals(LibraryBadgeSummary(), summaries[8L]) assertEquals(0f, summaries[8L]?.progress) assertEquals(mapOf(11L to 2, 99L to 1), buildCompletedDownloadCountsByChapterId(downloads)) } private fun chapter(id: Long, isRead: Boolean) = Chapter( id = id, mangaId = 7, name = "Chapter $id", url = "/chapter/$id", isRead = isRead, ) }