ChapterSelectionTest.kt
composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/ui/screens/detail/ChapterSelectionTest.kt
1package eu.friedcutlet.yokan.ui.screens.detail23import eu.friedcutlet.yokan.domain.Chapter4import kotlin.test.Test5import kotlin.test.assertEquals67class ChapterSelectionTest {8 private val chapters = (1L..6L).map { Chapter(it, 1, "Chapter $it", "/$it", isRead = it % 2L == 0L, isBookmarked = it == 3L, downloadSize = if (it == 4L) "1 MB" else null) }910 @Test fun statusShortcutsAndInversionOnlyUseShownChapters() {11 val shown = chapters.take(4)12 var selection = ChapterSelectionState().select(shown, ChapterSelectionOption.Unread)13 assertEquals(setOf(1L, 3L), selection.ids)14 selection = selection.select(shown, ChapterSelectionOption.Invert)15 assertEquals(setOf(2L, 4L), selection.ids)16 selection = selection.select(shown, ChapterSelectionOption.Downloaded)17 assertEquals(setOf(4L), selection.ids)18 selection = selection.select(shown, ChapterSelectionOption.Bookmarked)19 assertEquals(setOf(3L), selection.ids)20 }2122 @Test fun rangeFollowsDisplayOrderAndKeepsTheFirstAnchor() {23 val reversed = chapters.reversed()24 var selection = ChapterSelectionState().toggle(5).rangeTo(reversed, 2)25 assertEquals(setOf(5L, 4L, 3L, 2L), selection.ids)26 assertEquals(5L, selection.anchorId)27 selection = selection.rangeTo(reversed, 1)28 assertEquals(setOf(5L, 4L, 3L, 2L, 1L), selection.ids)29 }3031 @Test fun numericRangeUsesRowsRatherThanChapterIdsAndRejectsInvalidBounds() {32 val selection = ChapterSelectionState().selectRange(chapters.reversed(), 2, 4)33 assertEquals(setOf(5L, 4L, 3L), selection.ids)34 assertEquals(selection, selection.selectRange(chapters, 0, 4).selectRange(chapters, 4, 2))35 }3637 @Test fun aboveAndBelowIncludeTheAnchor() {38 var selection = ChapterSelectionState().toggle(3).select(chapters, ChapterSelectionOption.Above)39 assertEquals(setOf(1L, 2L, 3L), selection.ids)40 selection = selection.select(chapters, ChapterSelectionOption.Below)41 assertEquals(chapters.map { it.id }.toSet(), selection.ids)42 }4344 @Test fun filteringOrRemovalDropsInvisibleSelectionsAndAnchor() {45 val selection = ChapterSelectionState().select(chapters, ChapterSelectionOption.All).retainVisible(chapters.drop(1))46 assertEquals(setOf(2L, 3L, 4L, 5L, 6L), selection.ids)47 assertEquals(null, selection.anchorId)48 }49}50