package eu.friedcutlet.yokan.ui.screens.library import eu.friedcutlet.yokan.data.LibraryIndex import eu.friedcutlet.yokan.database.* import eu.friedcutlet.yokan.domain.* import kotlin.test.* class LibraryUpdateScopeTest { private fun title(id: Long, categories: List = emptyList(), tags: List = emptyList()) = Manga(id = id, name = "Title $id", link = "/$id", description = "", status = Status.Ongoing, itemType = ItemType.Manga, favorite = true, source = "Source", lang = "en", dateAddedMillis = 0, lastUpdateMillis = 0, categories = categories, genres = tags) private val titles = listOf(title(1, listOf(10), listOf("One")), title(2, listOf(10, 20), listOf("One", "Two")), title(3)) private val categories = listOf(Category(10, "One", ItemType.Manga, 0), Category(20, "Two", ItemType.Manga, 1)) private fun content(group: DbLibraryGrouping = DbLibraryGrouping.Categories, search: String = "") = libraryContent(titles, categories, LibraryIndex.Empty, LibraryQuery(search, LibraryFilterTypes(0, 0, 0, 0, 0, 0), DbSortLibraryManga(), false, grouping = group)) @Test fun globalAndAllRemainGlobalButUnloadedOrStaleGroupsCannotExpandToGlobal() { assertNull(libraryUpdateTitleIds(null, 10, DbGroupUpdateMode.Global, LibraryIndex.Empty)) assertEquals(emptySet(), libraryUpdateTitleIds(null, 10, DbGroupUpdateMode.CurrentGroup, LibraryIndex.Empty)) assertEquals(emptySet(), libraryUpdateTitleIds(content(), 999, DbGroupUpdateMode.CurrentGroup, LibraryIndex.Empty)) assertNull(libraryUpdateTitleIds(content(), null, DbGroupUpdateMode.CurrentGroup, LibraryIndex.Empty)) } @Test fun categoryScopeUsesRawMembershipInsteadOfSearchAndRowMatches() { val hidden = content(search = "not found") assertTrue(hidden.items(10).isEmpty()) assertEquals(setOf(1L, 2L), libraryUpdateTitleIds(hidden, 10, DbGroupUpdateMode.CurrentGroup, LibraryIndex.Empty)) assertEquals(setOf(3L), libraryUpdateTitleIds(hidden, UncategorizedCategoryId, DbGroupUpdateMode.CurrentGroup, LibraryIndex.Empty)) } @Test fun automaticGroupsUseStableRawMembershipAndDeduplicateMultiTagEntries() { val hidden = content(DbLibraryGrouping.Tags, search = "not found") val id = hidden.tabs.single { it.name == "One" }.id assertEquals(setOf(1L, 2L), libraryUpdateTitleIds(hidden, id, DbGroupUpdateMode.CurrentGroup, LibraryIndex.Empty)) } @Test fun ungroupedExceptionUsesTheWholeLibrary() { assertNull(libraryUpdateTitleIds(content(DbLibraryGrouping.Ungrouped), null, DbGroupUpdateMode.CurrentExceptUngrouped, LibraryIndex.Empty)) assertEquals(setOf(2L), libraryUpdateTitleIds(content(), 20, DbGroupUpdateMode.CurrentExceptUngrouped, LibraryIndex.Empty)) } }