ChapterProgressMergeTest.kt
composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/database/ChapterProgressMergeTest.kt
1package eu.friedcutlet.yokan.database23import kotlin.test.Test4import kotlin.test.assertEquals56class ChapterProgressMergeTest {7 private val chapter = DbChapter(id = 1, mangaId = 2, url = "/c1", lastPageRead = "4", updatedAt = 100)89 @Test10 fun furthestPageWinsIncludingPositionsBeyondIntRange() {11 assertEquals("9", chapter.mergeProgress(chapter.copy(lastPageRead = "9")).lastPageRead)12 assertEquals("4", chapter.mergeProgress(chapter.copy(lastPageRead = "2")).lastPageRead)13 assertEquals("3000000000", chapter.mergeProgress(chapter.copy(lastPageRead = "3000000000")).lastPageRead)14 assertEquals("3000000000", chapter.copy(lastPageRead = "3000000000").mergeProgress(chapter).lastPageRead)15 }1617 @Test18 fun blankOrNonNumericPositionsKeepTheFirstNonBlankOne() {19 assertEquals("7", chapter.copy(lastPageRead = "").mergeProgress(chapter.copy(lastPageRead = "7")).lastPageRead)20 assertEquals("4", chapter.mergeProgress(chapter.copy(lastPageRead = "")).lastPageRead)21 assertEquals("0.5", chapter.copy(lastPageRead = "0.5").mergeProgress(chapter.copy(lastPageRead = "9")).lastPageRead)22 assertEquals("4", chapter.mergeProgress(chapter.copy(lastPageRead = "end")).lastPageRead)23 }2425 @Test26 fun marksAreKeptFromEitherSideAndTheNewerUpdatedAtWins() {27 val other = chapter.copy(isRead = true, isBookmarked = true, fillerOverride = true, updatedAt = 300)2829 val merged = chapter.mergeProgress(other)30 val reverse = other.mergeProgress(chapter)3132 assertEquals(chapter.copy(isRead = true, isBookmarked = true, fillerOverride = true, updatedAt = 300), merged)33 assertEquals(other, reverse)34 assertEquals(false, chapter.copy(fillerOverride = false).mergeProgress(other).fillerOverride)35 }36}37