mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
cover the drag drop target mapping
This commit is contained in:
@@ -395,7 +395,7 @@ fun QueueScreen(
|
||||
}
|
||||
}
|
||||
|
||||
private fun dropTarget(
|
||||
internal fun dropTarget(
|
||||
rows: List<QueueRow>,
|
||||
index: Int,
|
||||
from: Long,
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.subtracks.data.db.SubtracksDatabase
|
||||
import com.subtracks.data.model.Song
|
||||
import com.subtracks.data.model.SongListItem
|
||||
import com.subtracks.data.model.Source
|
||||
import com.subtracks.data.prefs.fakeUserPreferences
|
||||
import com.subtracks.data.repo.QueueRepository
|
||||
@@ -98,6 +99,13 @@ class QueueViewModelTest {
|
||||
assertEquals((139L..199L).toList(), viewModel.rows.map { it.position })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dropTargetUsesStablePositionsAcrossDirectionChanges() {
|
||||
assertEquals(1L, dropTarget(listOf(row(1), row(0), row(2), row(3)), index = 1, from = 0))
|
||||
assertEquals(3L, dropTarget(listOf(row(1), row(2), row(3), row(0)), index = 3, from = 0))
|
||||
assertEquals(1L, dropTarget(listOf(row(0), row(3), row(1), row(2)), index = 1, from = 3))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reorderingMovesTheRowLocally() {
|
||||
runBlocking { seedSongs(200) }
|
||||
@@ -113,6 +121,30 @@ class QueueViewModelTest {
|
||||
assertEquals(listOf(101L, 102L, 100L), positions.take(3))
|
||||
}
|
||||
|
||||
private fun row(position: Int) =
|
||||
QueueRow(
|
||||
position.toLong(),
|
||||
position.toLong(),
|
||||
SongListItem(
|
||||
song =
|
||||
Song(
|
||||
sourceId = 1,
|
||||
id = "s$position",
|
||||
albumId = "al1",
|
||||
artistId = "ar1",
|
||||
title = "Song $position",
|
||||
album = "Album",
|
||||
artist = "Artist",
|
||||
duration = 100,
|
||||
track = 1,
|
||||
disc = 1,
|
||||
starred = null,
|
||||
genre = null,
|
||||
),
|
||||
coverArt = null,
|
||||
),
|
||||
)
|
||||
|
||||
private suspend fun seedSongs(count: Int) {
|
||||
db.sourcesDao().upsertSource(
|
||||
Source(id = 1, name = "test", address = "http://localhost", isActive = true, createdAt = 0),
|
||||
|
||||
Reference in New Issue
Block a user