Yokan / rebuild
Course 1 8624561

LocalEpisodePlaybackTest.kt

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

test / fixture54 lines
1package eu.friedcutlet.yokan.services.library23import eu.friedcutlet.yokan.domain.ProfileId4import eu.friedcutlet.yokan.data.DefaultYokanRepository5import eu.friedcutlet.yokan.database.*6import eu.friedcutlet.yokan.domain.Chapter7import eu.friedcutlet.yokan.services.extensions.ChapterPageResolver8import eu.friedcutlet.yokan.services.extensions.ProfileReaderContent9import eu.friedcutlet.yokan.services.extensions.ProfileReaderContentTest10import eu.friedcutlet.yokan.services.files.*11import kotlinx.coroutines.CoroutineScope12import kotlinx.coroutines.SupervisorJob13import kotlinx.coroutines.cancelAndJoin14import kotlinx.coroutines.test.StandardTestDispatcher15import kotlinx.coroutines.test.runTest16import kotlin.test.*1718class LocalEpisodePlaybackTest {19    @Test fun scannedSourcelessEpisodePlaysTheFileFromItsConfiguredFolder() = runTest {20        val files = MemoryVideoFiles()21        files.put("/anime/Show/Episode 1.mkv")22        val db = InMemoryYokanDatabase(emptySnapshot().copy(settings = DbSettings(namedLocalFolders = listOf(DbLocalFolder("Anime", "/anime")))))23        DefaultLocalLibraryService(db, files, NoArchives).scan()24        val title = db.mangas().single()25        assertTrue(title.isLocalArchive)26        assertEquals("local", title.source)27        assertEquals(DbItemType.Anime, title.itemType)28        val stored = db.chapters(title.id).single()29        assertEquals("Anime/Show/Episode 1.mkv", stored.archivePath)30        val episode = Chapter(id = stored.id, mangaId = title.id, name = stored.name.orEmpty(), url = stored.url, archivePath = stored.archivePath)3132        val factory = ProfileReaderContentTest.RuntimeFactory(db, "local")33        val owner = SupervisorJob()34        val content = ProfileReaderContent(35            ProfileId.Default, db, factory, ChapterPageResolver(DefaultYokanRepository(db), db, factory),36            files, NoArchives, CoroutineScope(owner + StandardTestDispatcher(testScheduler)), StandardTestDispatcher(testScheduler),37        )38        try {39            val video = content.videos(null, episode).single()40            assertEquals("file:///anime/Show/Episode 1.mkv", video.url)41            assertEquals("Downloaded", video.quality)4243            // The virtual path follows the folder when the user re-points it.44            files.data["/moved/Show/Episode 1.mkv"] = files.data.remove("/anime/Show/Episode 1.mkv")!!45            db.updateSettings(db.settings().copy(namedLocalFolders = listOf(DbLocalFolder("Anime", "/moved"))))46            assertEquals("file:///moved/Show/Episode 1.mkv", content.videos(null, episode).single().url)4748            // A missing file never becomes a fabricated stream.49            files.data.remove("/moved/Show/Episode 1.mkv")50            assertEquals(emptyList(), content.videos(null, episode))51            assertEquals(0, factory.created)52        } finally { content.closeAndJoin(); owner.cancelAndJoin() }53    }54}55

Search chapters, reference and source filenames.