enable drag and drop reordering

This commit is contained in:
Drew Weymouth
2024-06-22 17:10:26 -07:00
parent f5a4146e2b
commit 4545839e92
9 changed files with 79 additions and 160 deletions
+3 -32
View File
@@ -8,6 +8,7 @@ import (
)
func Test_ReorderItems(t *testing.T) {
tracks := []*mediaprovider.Track{
{ID: "a"}, // 0
{ID: "b"}, // 1
@@ -27,7 +28,7 @@ func Test_ReorderItems(t *testing.T) {
{ID: "b"},
{ID: "e"},
}
newTracks := ReorderItems(tracks, idxToMove, MoveToTop)
newTracks := ReorderItems(tracks, idxToMove, 0)
if !tracklistsEqual(t, newTracks, want) {
t.Error("ReorderTracks: MoveToTop order incorrect")
}
@@ -42,40 +43,10 @@ func Test_ReorderItems(t *testing.T) {
{ID: "c"},
{ID: "f"},
}
newTracks = ReorderItems(tracks, idxToMove, MoveToBottom)
newTracks = ReorderItems(tracks, idxToMove, len(tracks))
if !tracklistsEqual(t, newTracks, want) {
t.Error("ReorderTracks: MoveToBottom order incorrect")
}
// test MoveUp:
idxToMove = []int{0, 1, 3, 5}
want = []*mediaprovider.Track{
{ID: "a"},
{ID: "b"},
{ID: "d"},
{ID: "c"},
{ID: "f"},
{ID: "e"},
}
newTracks = ReorderItems(tracks, idxToMove, MoveUp)
if !tracklistsEqual(t, newTracks, want) {
t.Error("ReorderTracks: MoveUp order incorrect")
}
// test MoveDown:
idxToMove = []int{2, 4, 5}
want = []*mediaprovider.Track{
{ID: "a"},
{ID: "b"},
{ID: "d"},
{ID: "c"},
{ID: "e"},
{ID: "f"},
}
newTracks = ReorderItems(tracks, idxToMove, MoveDown)
if !tracklistsEqual(t, newTracks, want) {
t.Error("ReorderTracks: MoveDown order incorrect")
}
}
func tracklistsEqual(t *testing.T, a, b []*mediaprovider.Track) bool {