diff --git a/musikr/src/test/java/org/oxycblt/musikr/IndexingProgressCoalescerTest.kt b/musikr/src/test/java/org/oxycblt/musikr/IndexingProgressCoalescerTest.kt index a4f54df47..4d7e8cf93 100644 --- a/musikr/src/test/java/org/oxycblt/musikr/IndexingProgressCoalescerTest.kt +++ b/musikr/src/test/java/org/oxycblt/musikr/IndexingProgressCoalescerTest.kt @@ -45,4 +45,24 @@ class IndexingProgressCoalescerTest { assertEquals(listOf(first, latest), emitted) } + + @Test + fun submit_indeterminate_flushesLatestSongsFirst() = runTest { + val emitted = mutableListOf() + val coalescer = + IndexingProgressCoalescer( + intervalMs = 250, + clock = { 0L }, + onProgress = { emitted.add(it) }, + ) + val first = IndexingProgress.Songs(loaded = 0, explored = 1) + val latest = IndexingProgress.Songs(loaded = 2, explored = 3) + + coalescer.submit(first) + coalescer.submit(IndexingProgress.Songs(loaded = 1, explored = 2)) + coalescer.submit(latest) + coalescer.submit(IndexingProgress.Indeterminate) + + assertEquals(listOf(first, latest, IndexingProgress.Indeterminate), emitted) + } }