Yokan / rebuild
Course 1 8624561

LocalLibraryProjectionTest.kt

composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/services/library/LocalLibraryProjectionTest.kt

test / fixture36 lines
1package eu.friedcutlet.yokan.services.library23import eu.friedcutlet.yokan.database.DbItemType4import eu.friedcutlet.yokan.database.DbManga5import eu.friedcutlet.yokan.database.DbTitleMetadata6import eu.friedcutlet.yokan.database.seedDatabaseSnapshot7import eu.friedcutlet.yokan.domain.ItemType8import kotlin.test.Test9import kotlin.test.assertEquals10import kotlin.test.assertSame11import kotlin.test.assertNotSame1213class LocalLibraryProjectionTest {14    @Test15    fun bothScreensShareMappingAndOnlyTitleDependenciesInvalidateIt() {16        val snapshot = seedDatabaseSnapshot().copy(mangas = listOf(17            DbManga(id = 1, name = "Local", description = "Description", isLocalArchive = true, itemType = DbItemType.Manga),18            DbManga(id = 2, name = "Torrent", source = "TORRENT", isLocalArchive = true, itemType = DbItemType.Manga),19            DbManga(id = 3, name = "Remote", itemType = DbItemType.Manga),20        ))21        val cache = LocalLibraryProjectionCache()22        val initial = cache.get(snapshot)23        assertEquals(listOf(1L), initial.titlesByType.getValue(ItemType.Manga).map { it.id })24        assertEquals(listOf(1L, 2L), initial.browseTitlesByType.getValue(ItemType.Manga).map { it.id })25        assertSame(initial.titlesByType.getValue(ItemType.Manga).single(), initial.browseTitlesByType.getValue(ItemType.Manga).first())26        assertEquals(listOf(1L), initial.reviewQueue.map { it.id })27        assertSame(initial, cache.get(snapshot.copy(settings = snapshot.settings.copy(themeIsDark = !snapshot.settings.themeIsDark))))28        val updated = cache.get(snapshot.copy(settings = snapshot.settings.copy(titleMetadata = listOf(DbTitleMetadata(1, metadataServerId = "linked")))))29        assertNotSame(initial, updated)30        assertEquals(emptyList(), updated.reviewQueue)31        assertEquals("linked", updated.browseTitlesByType.getValue(ItemType.Manga).first().metadataServerId)32        assertEquals(null, initial.browseTitlesByType.getValue(ItemType.Manga).first().metadataServerId)33        val deleted = cache.get(snapshot.copy(mangas = emptyList()))34        assertEquals(0, deleted.overview(emptyList(), LocalLibraryScanState()).manga)35    }36}37

Search chapters, reference and source filenames.