mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
collect only the visible tab and split the position ticker from playback state
This commit is contained in:
@@ -13,7 +13,10 @@ import com.subtracks.data.model.Source
|
||||
import com.subtracks.data.prefs.fakeUserPreferences
|
||||
import com.subtracks.data.repo.QueueRepository
|
||||
import com.subtracks.data.repo.SourceRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.OkHttpClient
|
||||
import org.junit.After
|
||||
@@ -23,6 +26,7 @@ import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@@ -924,7 +928,7 @@ class PlaybackControllerTest {
|
||||
?.id == "s1"
|
||||
}
|
||||
|
||||
assertEquals(12_000L, restored.state.value.positionMs)
|
||||
assertEquals(12_000L, restored.positionMs.value)
|
||||
assertEquals(100_000L, restored.state.value.durationMs)
|
||||
assertEquals(
|
||||
"setWindow(size=3, start=0, position=12000)",
|
||||
@@ -953,6 +957,26 @@ class PlaybackControllerTest {
|
||||
assertEquals(0L, runBlocking { queues.cursorPositionMs() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun positionTickerAdvancesPositionWithoutEmittingPlaybackState() =
|
||||
runBlocking {
|
||||
seedAlbum(3, sourceId = 1)
|
||||
controller.playAlbum(1, "al1", 0)
|
||||
await { controller.state.value.isPlaying }
|
||||
|
||||
val emissions = CopyOnWriteArrayList<PlaybackState>()
|
||||
val collector = launch(Dispatchers.Default) { controller.state.collect { emissions += it } }
|
||||
await { emissions.isNotEmpty() }
|
||||
val baseline = emissions.size
|
||||
|
||||
handle.positionMs = 7_000L
|
||||
delay(1_200L)
|
||||
|
||||
assertEquals(7_000L, controller.positionMs.value)
|
||||
assertEquals(baseline, emissions.size)
|
||||
collector.cancel()
|
||||
}
|
||||
|
||||
private fun seedAlbum(
|
||||
count: Int,
|
||||
sourceId: Long,
|
||||
|
||||
@@ -105,10 +105,10 @@ class AppScreenshotTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(albums)) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(albums)) },
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) },
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) },
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) },
|
||||
coverArt = { id, _ -> id?.let { CoverArtRef(it, "test:$it") } },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
@@ -164,10 +164,10 @@ class AppScreenshotTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(Fixtures.albums)) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.from(Fixtures.artists)) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.from(Fixtures.songItems)) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.from(Fixtures.playlists)) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(Fixtures.albums)) },
|
||||
artists = remember { flowOf(PagingData.from(Fixtures.artists)) },
|
||||
songs = remember { flowOf(PagingData.from(Fixtures.songItems)) },
|
||||
playlists = remember { flowOf(PagingData.from(Fixtures.playlists)) },
|
||||
coverArt = { id, _ -> id?.let { CoverArtRef(it, "test:$it") } },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
@@ -180,6 +180,7 @@ class AppScreenshotTest {
|
||||
)
|
||||
MiniPlayer(
|
||||
state = Fixtures.playbackState(),
|
||||
positionMs = 62_000,
|
||||
coverArt = CoverArtRef("art-al-kid-a", "test:art-al-kid-a"),
|
||||
artwork = artwork,
|
||||
onExpand = {},
|
||||
@@ -374,6 +375,7 @@ class AppScreenshotTest {
|
||||
SubtracksTheme {
|
||||
NowPlayingScreen(
|
||||
state = Fixtures.playbackState(),
|
||||
positionMs = 62_000,
|
||||
title = "Kid A",
|
||||
coverArt = CoverArtRef("art-al-kid-a", "test:art-al-kid-a"),
|
||||
artwork = artworkColorsFromSeed(Color.rgb(120, 80, 200)),
|
||||
@@ -397,6 +399,7 @@ class AppScreenshotTest {
|
||||
SubtracksTheme {
|
||||
NowPlayingScreen(
|
||||
state = Fixtures.playbackState().copy(shuffle = true, repeat = RepeatMode.One),
|
||||
positionMs = 62_000,
|
||||
title = "Kid A",
|
||||
coverArt = CoverArtRef("art-al-kid-a", "test:art-al-kid-a"),
|
||||
artwork = artworkColorsFromSeed(Color.rgb(120, 80, 200)),
|
||||
@@ -448,6 +451,7 @@ class AppScreenshotTest {
|
||||
Spacer(Modifier.weight(1f))
|
||||
MiniPlayer(
|
||||
state = Fixtures.playbackState(),
|
||||
positionMs = 62_000,
|
||||
coverArt = CoverArtRef("art-al-kid-a", "test:art-al-kid-a"),
|
||||
artwork = artworkColorsFromSeed(Color.rgb(120, 80, 200)),
|
||||
onExpand = {},
|
||||
@@ -467,10 +471,10 @@ class AppScreenshotTest {
|
||||
LibraryScreen(
|
||||
selectedTab = tab,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(Fixtures.albums)) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.from(Fixtures.artists)) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.from(Fixtures.songItems)) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.from(Fixtures.playlists)) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(Fixtures.albums)) },
|
||||
artists = remember { flowOf(PagingData.from(Fixtures.artists)) },
|
||||
songs = remember { flowOf(PagingData.from(Fixtures.songItems)) },
|
||||
playlists = remember { flowOf(PagingData.from(Fixtures.playlists)) },
|
||||
coverArt = { id, _ -> id?.let { CoverArtRef(it, "test:$it") } },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
@@ -562,7 +566,6 @@ private object Fixtures {
|
||||
coverArtId = "art-al-kid-a",
|
||||
),
|
||||
isPlaying = true,
|
||||
positionMs = 62_000,
|
||||
durationMs = 251_000,
|
||||
hasNext = true,
|
||||
hasPrevious = false,
|
||||
|
||||
@@ -8,7 +8,6 @@ import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
@@ -43,10 +42,10 @@ class LibraryOptionsScreenshotTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(albums())) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(albums())) },
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) },
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) },
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) },
|
||||
coverArt = { _, _ -> null },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
|
||||
@@ -12,7 +12,6 @@ import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
|
||||
import com.subtracks.data.model.Album
|
||||
@@ -49,10 +48,10 @@ class LibraryOptionsTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(albums())) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(albums())) },
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) },
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) },
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) },
|
||||
coverArt = { _, _ -> null },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
|
||||
@@ -15,7 +15,6 @@ import androidx.compose.ui.test.swipeDown
|
||||
import androidx.paging.LoadState
|
||||
import androidx.paging.LoadStates
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
|
||||
import com.subtracks.data.model.Album
|
||||
@@ -27,13 +26,17 @@ import com.subtracks.ui.library.LibraryScreen
|
||||
import com.subtracks.ui.library.LibraryTab
|
||||
import com.subtracks.ui.library.LibraryTabs
|
||||
import com.subtracks.ui.theme.SubtracksTheme
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@@ -51,10 +54,10 @@ class LibraryScreenTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(albums())) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(albums())) },
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) },
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) },
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) },
|
||||
coverArt = { _, _ -> null },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
@@ -86,10 +89,10 @@ class LibraryScreenTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.empty<Album>(settledLoadStates)) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.empty<Album>(settledLoadStates)) },
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) },
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) },
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) },
|
||||
coverArt = { _, _ -> null },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
@@ -109,6 +112,55 @@ class LibraryScreenTest {
|
||||
assertTrue("an empty library should offer a sync", synced)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onlyTheVisibleTabCollectsItsPagingFlow() {
|
||||
val collected = CopyOnWriteArrayList<String>()
|
||||
val albums =
|
||||
flow<PagingData<Album>> {
|
||||
collected += "albums"
|
||||
emit(PagingData.from(albums()))
|
||||
}
|
||||
val artists =
|
||||
flow<PagingData<Artist>> {
|
||||
collected += "artists"
|
||||
emit(PagingData.empty())
|
||||
}
|
||||
val songs =
|
||||
flow<PagingData<SongListItem>> {
|
||||
collected += "songs"
|
||||
emit(PagingData.empty())
|
||||
}
|
||||
val playlists =
|
||||
flow<PagingData<Playlist>> {
|
||||
collected += "playlists"
|
||||
emit(PagingData.empty())
|
||||
}
|
||||
composeRule.setContent {
|
||||
SubtracksTheme {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = albums,
|
||||
artists = artists,
|
||||
songs = songs,
|
||||
playlists = playlists,
|
||||
coverArt = { _, _ -> null },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
onPlaylistClick = {},
|
||||
onSongClick = {},
|
||||
onSync = {},
|
||||
onOpenSettings = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
composeRule.waitUntil(timeoutMillis = 5_000) { collected.isNotEmpty() }
|
||||
composeRule.waitForIdle()
|
||||
|
||||
assertEquals(listOf("albums"), collected.toList())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTabRowReflowsInOneDirectionDuringASwitch() {
|
||||
val pagerState = PagerState(currentPage = 1, pageCount = { LibraryTab.entries.size })
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
@@ -44,10 +43,10 @@ class LibrarySearchScreenshotTest {
|
||||
LibraryScreen(
|
||||
selectedTab = LibraryTab.Albums,
|
||||
onTabSelected = {},
|
||||
albums = remember { flowOf(PagingData.from(albums())) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) }.collectAsLazyPagingItems(),
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) }.collectAsLazyPagingItems(),
|
||||
albums = remember { flowOf(PagingData.from(albums())) },
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) },
|
||||
songs = remember { flowOf(PagingData.empty<SongListItem>()) },
|
||||
playlists = remember { flowOf(PagingData.empty<Playlist>()) },
|
||||
coverArt = { _, _ -> null },
|
||||
onAlbumClick = {},
|
||||
onArtistClick = {},
|
||||
|
||||
Reference in New Issue
Block a user