mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
search: require three characters and play songs in album context
Drop the library-wide instr fallback: below three characters the cross-type search now returns nothing instead of scanning every table, and the screen asks for more input. Lock in that a song result plays its album context rather than a search queue.
This commit is contained in:
@@ -777,15 +777,15 @@ class LibraryDaoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun crossTypeSearchFallsBackToAScanBelowThreeCharacters() =
|
||||
fun crossTypeSearchIgnoresQueriesShorterThanThreeCharacters() =
|
||||
runTest {
|
||||
val sourceId = source()
|
||||
val dao = db.libraryDao()
|
||||
dao.upsertAlbums(listOf(album(sourceId, "al-1", "Gamma", year = null, starred = null)))
|
||||
dao.upsertSongs(listOf(song(sourceId, "s1", "Gamma Ray", starred = null)))
|
||||
|
||||
assertEquals(listOf("Gamma"), dao.searchAlbums(sourceId, "ga", 50).first().map { it.name })
|
||||
assertEquals(listOf("s1"), dao.searchSongs(sourceId, "ga", 50).first().map { it.song.id })
|
||||
assertTrue(dao.searchAlbums(sourceId, "ga", 50).first().isEmpty())
|
||||
assertTrue(dao.searchSongs(sourceId, "ga", 50).first().isEmpty())
|
||||
}
|
||||
|
||||
private suspend fun plan(sql: String): String =
|
||||
|
||||
@@ -62,14 +62,14 @@ class SearchScreenTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anEmptyQueryPromptsAndAnEmptyResultSaysSo() {
|
||||
fun aQueryShorterThanThreeCharactersPromptsForMoreInput() {
|
||||
composeRule.setContent {
|
||||
SubtracksTheme {
|
||||
SearchScreen(query = "", onQueryChange = {}, results = SearchResults())
|
||||
SearchScreen(query = "ro", onQueryChange = {}, results = SearchResults())
|
||||
}
|
||||
}
|
||||
|
||||
composeRule.onNodeWithText("Search for songs, albums, artists and playlists.").assertIsDisplayed()
|
||||
composeRule.onNodeWithText("Type at least 3 characters to search.").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.room3.Room
|
||||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.subtracks.awaitUntil
|
||||
import com.subtracks.cancelAndJoinBlocking
|
||||
import com.subtracks.data.db.SubtracksDatabase
|
||||
import com.subtracks.data.download.ArtworkStore
|
||||
@@ -12,6 +13,7 @@ import com.subtracks.data.download.FakeDownloadEngine
|
||||
import com.subtracks.data.model.Album
|
||||
import com.subtracks.data.model.Artist
|
||||
import com.subtracks.data.model.Playlist
|
||||
import com.subtracks.data.model.QueueKind
|
||||
import com.subtracks.data.model.Song
|
||||
import com.subtracks.data.prefs.fakeUserPreferences
|
||||
import com.subtracks.data.repo.DownloadRepository
|
||||
@@ -116,12 +118,41 @@ class SearchViewModelTest {
|
||||
assertEquals(listOf("pl-1"), results.playlists.map { it.id })
|
||||
assertEquals(listOf("s1"), results.songs.map { it.song.id })
|
||||
|
||||
viewModel.setQuery("oa")
|
||||
val short = runBlocking { withTimeout(5_000) { viewModel.results.first { it.isEmpty } } }
|
||||
|
||||
assertTrue(short.isEmpty)
|
||||
|
||||
viewModel.setQuery("")
|
||||
val blank = runBlocking { withTimeout(5_000) { viewModel.results.first { it.isEmpty } } }
|
||||
|
||||
assertTrue(blank.isEmpty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun playingASearchResultPlaysItsAlbumInsteadOfASearchQueue() {
|
||||
val sourceId =
|
||||
runBlocking {
|
||||
val id = sourceRepository.addSource("nav", "http://localhost/", "u", "p", false)
|
||||
db.libraryDao().upsertAlbums(listOf(album(id, "al-1", "Road Album")))
|
||||
db.libraryDao().upsertSongs(
|
||||
listOf(
|
||||
song(id, "s1", "Road Song"),
|
||||
song(id, "s2", "Another").copy(track = 2),
|
||||
),
|
||||
)
|
||||
id
|
||||
}
|
||||
|
||||
viewModel.play(song(sourceId, "s1", "Road Song"))
|
||||
awaitUntil("the queue is built") { runBlocking { db.queueDao().entries().isNotEmpty() } }
|
||||
|
||||
val entries = runBlocking { db.queueDao().entries() }
|
||||
assertEquals(1, entries.size)
|
||||
assertEquals(QueueKind.Album, entries.first().kind)
|
||||
assertEquals("al-1", entries.first().refId)
|
||||
}
|
||||
|
||||
private fun album(
|
||||
sourceId: Long,
|
||||
id: String,
|
||||
|
||||
Reference in New Issue
Block a user