Yokan / rebuild
Course 1 8624561

ActivityRowsTest.kt

composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/ui/screens/activity/ActivityRowsTest.kt

test / fixture99 lines
1package eu.friedcutlet.yokan.ui.screens.activity23import eu.friedcutlet.yokan.data.LibraryIndex4import eu.friedcutlet.yokan.domain.testManga5import eu.friedcutlet.yokan.database.DbDownload6import eu.friedcutlet.yokan.domain.Chapter7import eu.friedcutlet.yokan.domain.History8import eu.friedcutlet.yokan.domain.ItemType9import eu.friedcutlet.yokan.domain.UpdateEntry10import kotlin.test.Test11import kotlin.test.assertEquals12import kotlin.test.assertNull1314class ActivityRowsTest {15    private fun update(id: Long, mangaId: Long, chapterId: Long, updatedAt: Long, itemType: ItemType = ItemType.Manga) =16        UpdateEntry(17            id = id,18            mangaId = mangaId,19            chapterId = chapterId,20            itemType = itemType,21            title = "stored $mangaId",22            chapterName = "stored ch $chapterId",23            source = "src",24            date = "",25            isRead = false,26            updatedAt = updatedAt,27        )2829    private fun history(id: Long, mangaId: Long, chapterId: Long, updatedAt: Long, itemType: ItemType = ItemType.Manga) =30        History(31            id = id,32            mangaId = mangaId,33            chapterId = chapterId,34            itemType = itemType,35            title = "stored $mangaId",36            chapterName = "stored ch $chapterId",37            date = "",38            readingTimeSeconds = 0,39            updatedAt = updatedAt,40        )4142    @Test43    fun updateRowsResolveTitleChapterAndFirstDownloadPerTypeNewestFirst() {44        val one = testManga(1, "One")45        val index = LibraryIndex(46            chaptersByManga = mapOf(1L to listOf(Chapter(10, 1, "Ch 10", "/10", isRead = true), Chapter(11, 1, "", "/11"))),47        )48        val downloads = listOf(49            DbDownload(id = 7, chapterId = 10, succeeded = 1),50            DbDownload(id = 8, chapterId = 10, succeeded = 2),51        )52        val rows = buildUpdateRows(53            updates = listOf(54                update(100, 1, 10, updatedAt = 1),55                update(101, 1, 11, updatedAt = 3),56                update(102, 2, 20, updatedAt = 2, itemType = ItemType.Anime),57            ),58            titles = mapOf(1L to one),59            index = index,60            downloads = downloads,61        )6263        val manga = rows.getValue(ItemType.Manga)64        assertEquals(listOf(101L, 100L), manga.map { it.update.id })65        val read = manga.last()66        assertEquals(one, read.manga)67        assertEquals("One", read.title)68        assertEquals("Ch 10", read.chapterName)69        assertEquals(true, read.isRead)70        assertEquals(7L, read.download?.id)71        // A blank chapter name falls back to the stored one.72        assertEquals("stored ch 11", manga.first().chapterName)7374        val orphan = rows.getValue(ItemType.Anime).single()75        assertNull(orphan.manga)76        assertNull(orphan.chapter)77        assertEquals("stored 2", orphan.title)78    }7980    @Test81    fun historyRowsKeepNewestEntryPerTitle() {82        val index = LibraryIndex(chaptersByManga = mapOf(1L to listOf(Chapter(10, 1, "Ch 10", "/10"))))83        val rows = buildHistoryRows(84            history = listOf(85                history(1, mangaId = 1, chapterId = 10, updatedAt = 5),86                history(2, mangaId = 1, chapterId = 11, updatedAt = 1),87                history(3, mangaId = 2, chapterId = 20, updatedAt = 9),88                history(4, mangaId = 3, chapterId = 30, updatedAt = 7, itemType = ItemType.Novel),89            ),90            titles = mapOf(1L to testManga(1, "One")),91            index = index,92        )9394        val manga = rows.getValue(ItemType.Manga)95        assertEquals(listOf(3L, 1L), manga.map { it.history.id })96        assertEquals("Ch 10", manga.last().chapter?.name)97        assertEquals(listOf(4L), rows.getValue(ItemType.Novel).map { it.history.id })98    }99}100

Search chapters, reference and source filenames.