PlaylistDetailScreen zeigt die Songs einer Playlist (watchPlaylistSongs), erlaubt Entfernen einzelner Songs und Umsortieren per Drag & Drop (ReorderableListView.builder). Tippen auf einen Song spielt die Playlist ab dieser Stelle. Leer-Zustand mit Hinweistext. Da bestehende position-Werte nach Einfügereihenfolge lückenhaft sein können, schreibt das Umsortieren nicht nur den verschobenen Song um, sondern vergibt für die gesamte Playlist neue lückenlose Positionen (0..N-1): MeloDb.reorderAllPlaylistSongs (in einer Transaktion) + PlaylistService.reorderAll als dünner Wrapper. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
65 lines
2.0 KiB
Dart
65 lines
2.0 KiB
Dart
import 'package:drift/native.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:melo/library/database.dart';
|
|
import 'package:melo/library/playlist_service.dart';
|
|
|
|
void main() {
|
|
late MeloDb db;
|
|
late PlaylistService service;
|
|
|
|
setUp(() {
|
|
db = MeloDb(NativeDatabase.memory());
|
|
service = PlaylistService(db);
|
|
});
|
|
|
|
tearDown(() async => db.close());
|
|
|
|
test('createPlaylist delegates to db and notifies listeners', () async {
|
|
var notified = false;
|
|
service.addListener(() => notified = true);
|
|
|
|
await service.createPlaylist('Road Trip');
|
|
|
|
final playlists = await db.watchPlaylists().first;
|
|
expect(playlists.length, 1);
|
|
expect(playlists.first.name, 'Road Trip');
|
|
expect(notified, true);
|
|
});
|
|
|
|
test('toggleFavorite delegates to db and notifies listeners', () async {
|
|
await db.into(db.songs).insert(SongsCompanion.insert(
|
|
id: 'song-1', path: '/a.mp3', title: 'A', dateAddedMs: 0, updatedAtMs: 0,
|
|
));
|
|
|
|
var notified = false;
|
|
service.addListener(() => notified = true);
|
|
|
|
await service.toggleFavorite('song-1');
|
|
|
|
expect(await db.watchIsFavorite('song-1').first, true);
|
|
expect(notified, true);
|
|
});
|
|
|
|
test('reorderAll schreibt lückenlose Positionen 0..N-1 in neuer Reihenfolge', () async {
|
|
final playlistId = await db.createPlaylist('Mix');
|
|
for (final id in ['song-1', 'song-2', 'song-3']) {
|
|
await db.into(db.songs).insert(SongsCompanion.insert(
|
|
id: id, path: '/$id.mp3', title: id, dateAddedMs: 0, updatedAtMs: 0,
|
|
));
|
|
}
|
|
// Ursprüngliche (evtl. lückenhafte) Positionen.
|
|
await db.addSongToPlaylist(playlistId, 'song-1', 0);
|
|
await db.addSongToPlaylist(playlistId, 'song-2', 5);
|
|
await db.addSongToPlaylist(playlistId, 'song-3', 9);
|
|
|
|
var notified = false;
|
|
service.addListener(() => notified = true);
|
|
|
|
await service.reorderAll(playlistId, ['song-3', 'song-1', 'song-2']);
|
|
|
|
final songs = await db.watchPlaylistSongs(playlistId).first;
|
|
expect(songs.map((s) => s.id).toList(), ['song-3', 'song-1', 'song-2']);
|
|
expect(notified, true);
|
|
});
|
|
}
|