ui: show plural artists in song subtitles and info dialog

This commit is contained in:
austinried
2026-10-19 14:16:31 +00:00
parent d81efe168e
commit fb1c2a02ff
6 changed files with 138 additions and 3 deletions
@@ -0,0 +1,67 @@
package com.subtracks.ui.components
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.subtracks.data.model.ArtistRef
import com.subtracks.data.model.Song
import com.subtracks.ui.library.SongRow
import com.subtracks.ui.theme.SubtracksTheme
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.GraphicsMode
@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class SongArtistDisplayTest {
@get:Rule
val composeRule = createAndroidComposeRule<ComponentActivity>()
private val song =
Song(
sourceId = 1,
id = "s1",
albumId = "al1",
artistId = "ar2",
title = "Song",
album = "Album",
artist = "Two",
duration = 100,
track = 1,
disc = 1,
starred = null,
artists = listOf(ArtistRef("ar1", "One"), ArtistRef("ar2", "Two"), ArtistRef("ar3", "Three")),
)
@Test
fun aSongRowListsThePluralArtistsWithTheSingularArtistFirst() {
composeRule.setContent {
SubtracksTheme {
SongRow(song = song)
}
}
composeRule.onNodeWithText("Two · One · Three").assertIsDisplayed()
}
@Test
fun theInfoDialogListsThePluralArtistsWithTheSingularArtistFirst() {
composeRule.setContent {
SubtracksTheme {
SongInfoDialog(
song = song,
download = null,
localFile = null,
streamEncoding = null,
onDismiss = {},
genres = emptyList(),
)
}
}
composeRule.onNodeWithText("Two · One · Three").assertIsDisplayed()
}
}
@@ -0,0 +1,52 @@
package com.subtracks.ui.library
import com.subtracks.data.model.ArtistRef
import com.subtracks.data.model.Song
import com.subtracks.ui.components.artistSubtitle
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class SongArtistSubtitleTest {
@Test
fun pluralArtistsAreJoinedWithDots() {
assertEquals("One · Two", song(artist = null, artists = listOf(ArtistRef("1", "One"), ArtistRef("2", "Two"))).artistSubtitle())
}
@Test
fun singularArtistIsListedFirstWhenItIsAlsoPlural() {
assertEquals(
"Two · One · Three",
song(artist = "Two", artists = listOf(ArtistRef("1", "One"), ArtistRef("2", "Two"), ArtistRef("3", "Three")))
.artistSubtitle(),
)
}
@Test
fun singularArtistIsUsedWhenNoPluralArtistsExist() {
assertEquals("One", song(artist = "One", artists = emptyList()).artistSubtitle())
}
@Test
fun noArtistGivesNoSubtitle() {
assertNull(song(artist = null, artists = emptyList()).artistSubtitle())
}
private fun song(
artist: String?,
artists: List<ArtistRef>,
) = Song(
sourceId = 1,
id = "s1",
albumId = "al1",
artistId = "ar1",
title = "Song",
album = "Album",
artist = artist,
duration = 100,
track = 1,
disc = 1,
starred = null,
artists = artists,
)
}