mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
home: show album more screens as lists with a section-relevant detail column
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package com.subtracks.ui.home
|
||||
|
||||
import com.subtracks.data.model.Album
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class HomeListInfoTest {
|
||||
private val now = 1_700_000_000_000L
|
||||
|
||||
@Test
|
||||
fun relativeTimeUsesFriendlyBuckets() {
|
||||
assertNull(relativeTimeLabel(0, now))
|
||||
assertEquals("Just now", relativeTimeLabel(now / 1000 - 10, now))
|
||||
assertEquals("Today", relativeTimeLabel((now - 3 * 3_600_000L) / 1000L, now))
|
||||
assertEquals("Yesterday", relativeTimeLabel(secondsAgo(1), now))
|
||||
assertEquals("3 days ago", relativeTimeLabel(secondsAgo(3), now))
|
||||
assertEquals("Last week", relativeTimeLabel(secondsAgo(10), now))
|
||||
assertEquals("3 weeks ago", relativeTimeLabel(secondsAgo(21), now))
|
||||
assertEquals("Last month", relativeTimeLabel(secondsAgo(45), now))
|
||||
assertEquals("3 months ago", relativeTimeLabel(secondsAgo(100), now))
|
||||
assertEquals("Last year", relativeTimeLabel(secondsAgo(400), now))
|
||||
assertEquals("2 years ago", relativeTimeLabel(secondsAgo(800), now))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun albumInfoMatchesTheSection() {
|
||||
val album = album(created = secondsAgo(1), played = secondsAgo(3), playCount = 5, year = 1999)
|
||||
|
||||
assertEquals("Yesterday", albumListInfo(request(HomeSection.RecentlyAddedAlbums), album, now))
|
||||
assertEquals("3 days ago", albumListInfo(request(HomeSection.RecentlyPlayedAlbums), album, now))
|
||||
assertEquals("5 plays", albumListInfo(request(HomeSection.MostPlayedAlbums), album, now))
|
||||
assertEquals("3 days ago", albumListInfo(request(HomeSection.Rediscover), album, now))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun albumInfoIsNullWhenTheSectionHasNothingToShow() {
|
||||
val album = album(created = 0, played = null, playCount = 0, year = 0)
|
||||
|
||||
assertNull(albumListInfo(request(HomeSection.RecentlyAddedAlbums), album, now))
|
||||
assertNull(albumListInfo(request(HomeSection.RecentlyPlayedAlbums), album, now))
|
||||
assertNull(albumListInfo(request(HomeSection.MostPlayedAlbums), album, now))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDecadeListShowsTheYear() {
|
||||
val album = album(created = 0, played = null, playCount = 0, year = 1999)
|
||||
|
||||
assertEquals("1999", albumListInfo(HomeListRequest(title = "1990s", decade = 1990), album, now))
|
||||
}
|
||||
|
||||
private fun secondsAgo(days: Long): Long = (now - days * 86_400_000L) / 1000L
|
||||
|
||||
private fun request(section: HomeSection) = HomeListRequest(title = section.title, section = section)
|
||||
|
||||
private fun album(
|
||||
created: Long,
|
||||
played: Long?,
|
||||
playCount: Long,
|
||||
year: Long,
|
||||
) = Album(
|
||||
sourceId = 1,
|
||||
id = "a",
|
||||
artistId = "ar",
|
||||
name = "Album",
|
||||
albumArtist = "Artist",
|
||||
created = created,
|
||||
coverArt = null,
|
||||
genre = null,
|
||||
year = year,
|
||||
starred = null,
|
||||
songCount = 1,
|
||||
playCount = playCount,
|
||||
played = played,
|
||||
)
|
||||
}
|
||||
@@ -3,12 +3,15 @@ package com.subtracks.ui.home
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onAllNodesWithText
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.compose.ui.test.performTouchInput
|
||||
import androidx.compose.ui.test.swipeUp
|
||||
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
|
||||
@@ -17,6 +20,7 @@ import com.subtracks.data.model.AlbumSongItem
|
||||
import com.subtracks.data.model.Artist
|
||||
import com.subtracks.data.model.Song
|
||||
import com.subtracks.ui.theme.SubtracksTheme
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -75,6 +79,49 @@ class HomeScreenshotTest {
|
||||
composeRule.onRoot().captureRoboImage("src/test/screenshots/home_genres.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun homeRecentlyAddedList() {
|
||||
val now = System.currentTimeMillis()
|
||||
val albums =
|
||||
listOf(
|
||||
listAlbum("Added Yesterday", (now - 86_400_000L) / 1000L),
|
||||
listAlbum("Added This Week", (now - 3 * 86_400_000L) / 1000L),
|
||||
listAlbum("Added Weeks Ago", (now - 21 * 86_400_000L) / 1000L),
|
||||
)
|
||||
composeRule.setContent {
|
||||
SubtracksTheme {
|
||||
HomeListScreen(
|
||||
request = HomeListRequest(title = "Recently added", section = HomeSection.RecentlyAddedAlbums),
|
||||
albums = remember { flowOf(PagingData.from(albums)) }.collectAsLazyPagingItems(),
|
||||
artists = remember { flowOf(PagingData.empty<Artist>()) }.collectAsLazyPagingItems(),
|
||||
songs = remember { flowOf(PagingData.empty<AlbumSongItem>()) }.collectAsLazyPagingItems(),
|
||||
coverArt = { _, _ -> null },
|
||||
)
|
||||
}
|
||||
}
|
||||
composeRule.waitUntil(timeoutMillis = 5_000) {
|
||||
composeRule.onAllNodesWithText("Added Yesterday").fetchSemanticsNodes().isNotEmpty()
|
||||
}
|
||||
composeRule.onRoot().captureRoboImage("src/test/screenshots/home_album_list.png")
|
||||
}
|
||||
|
||||
private fun listAlbum(
|
||||
name: String,
|
||||
created: Long,
|
||||
) = Album(
|
||||
sourceId = 1,
|
||||
id = name,
|
||||
artistId = "ar",
|
||||
name = name,
|
||||
albumArtist = "Radiohead",
|
||||
created = created,
|
||||
coverArt = null,
|
||||
genre = null,
|
||||
year = 2000,
|
||||
starred = null,
|
||||
songCount = 10,
|
||||
)
|
||||
|
||||
private fun feed() =
|
||||
HomeFeed(
|
||||
recentlyPlayedAlbums = albums("Recent"),
|
||||
|
||||
Reference in New Issue
Block a user