Merge shared library surfaces and connect title navigation
This commit is contained in:
commit
3bfb8cd779
623 changed files with 2008 additions and 38 deletions
|
|
@ -0,0 +1,49 @@
|
|||
package org.justinvisser.wolfskin.tv
|
||||
|
||||
import android.app.Application
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.justinvisser.wolfskin.conductarr.MemoryCacheStore
|
||||
import org.justinvisser.wolfskin.design.LibraryTitle
|
||||
import org.justinvisser.wolfskin.tv.read.LibrarySnapshotStore
|
||||
|
||||
/** A stale library remains readable offline without crossing server/person boundaries. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], application = Application::class)
|
||||
class LibrarySnapshotStoreTest {
|
||||
@Test fun savedCopyArrivesBeforeFailedRefreshAndFreshCopySkipsNetwork() = runBlocking {
|
||||
var now = 1000L
|
||||
val store = LibrarySnapshotStore(MemoryCacheStore()) { now }
|
||||
val items = listOf(LibraryTitle("a", "Film A", "movie", year = 2007, runtimeSeconds = 6000, played = true))
|
||||
store.read("server:justin", "movies") { items }.toList()
|
||||
val fresh = store.read("server:justin", "movies") { error("Fresh snapshot must not read") }.toList()
|
||||
assertEquals(items, fresh.single().items)
|
||||
now += 11 * 60_000
|
||||
val offline = store.read("server:justin", "movies") { throw java.io.IOException("offline") }.toList()
|
||||
assertEquals(2, offline.size)
|
||||
assertFalse(offline.first().unreachable)
|
||||
assertTrue(offline.last().unreachable)
|
||||
assertEquals(1000L, offline.last().savedAtMillis)
|
||||
assertEquals(items, offline.last().items)
|
||||
for (scope in listOf("server:mindel", "other-server:justin")) {
|
||||
val isolated = store.read(scope, "movies") { throw java.io.IOException("offline") }.toList().single()
|
||||
assertNull(isolated.savedAtMillis)
|
||||
assertTrue(isolated.items.isEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun explicitRecoveryRefreshesEvenFreshEmptyDestination() = runBlocking {
|
||||
val store = LibrarySnapshotStore(MemoryCacheStore()) { 1000L }
|
||||
store.read("server:justin", "movies") { emptyList() }.toList()
|
||||
val current = listOf(LibraryTitle("b", "New Film", "movie"))
|
||||
val reads = store.read("server:justin", "movies", force = true) { current }.toList()
|
||||
assertTrue(reads.first().items.isEmpty())
|
||||
assertEquals(current, reads.last().items)
|
||||
assertFalse(reads.last().unreachable)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue