music: add more tests
Add tests for MusicViewModel, MusicMode, and MusicRepository. Going further requires me to really learn instrumentation tests.
This commit is contained in:
@@ -91,7 +91,7 @@ class SongDetailDialog : ViewBindingDialogFragment<DialogSongDetailBinding>() {
|
||||
val formattedNumber = getString(R.string.fmt_number, it.number)
|
||||
val zipped =
|
||||
if (it.name != null) {
|
||||
getString(R.string.fmt_zipped_names, it.name, formattedNumber)
|
||||
getString(R.string.fmt_zipped_names, formattedNumber, it.name)
|
||||
} else {
|
||||
formattedNumber
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ constructor(
|
||||
private val musicRepository: MusicRepository,
|
||||
private val musicSettings: MusicSettings
|
||||
) : ViewModel(), MusicRepository.Listener, HomeSettings.Listener {
|
||||
|
||||
private val _songsList = MutableStateFlow(listOf<Song>())
|
||||
/** A list of [Song]s, sorted by the preferred [Sort], to be shown in the home view. */
|
||||
val songsList: StateFlow<List<Song>>
|
||||
|
||||
@@ -347,9 +347,21 @@ interface Genre : MusicParent {
|
||||
val durationMs: Long
|
||||
}
|
||||
|
||||
/**
|
||||
* Run [Music.resolveName] on each instance in the given list and concatenate them into a [String]
|
||||
* in a localized manner.
|
||||
* @param context [Context] required
|
||||
* @return A concatenated string.
|
||||
*/
|
||||
fun <T : Music> List<T>.resolveNames(context: Context) =
|
||||
concatLocalized(context) { it.resolveName(context) }
|
||||
|
||||
/**
|
||||
* Returns if [Music.rawName] matches for each item in a list. Useful for scenarios where the
|
||||
* display information of an item must be compared without a context.
|
||||
* @param other The list of items to compare to.
|
||||
* @return True if they are the same (by [Music.rawName]), false otherwise.
|
||||
*/
|
||||
fun <T : Music> List<T>.areRawNamesTheSame(other: List<T>): Boolean {
|
||||
for (i in 0 until max(size, other.size)) {
|
||||
val a = getOrNull(i) ?: return false
|
||||
|
||||
Reference in New Issue
Block a user