import 'package:drift/drift.dart' show Value; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:melo/downloads/download_einordnung.dart'; import 'package:melo/library/database.dart'; const _pfad = '/storage/emulated/0/Music/Melo/Neues Lied.mp3'; Future _dbMitDownload({String? album}) async { final db = MeloDb(NativeDatabase.memory()); await db.upsertSongs([ SongsCompanion.insert( id: 'yt-1', path: _pfad, title: 'Neues Lied', album: Value(album), dateAddedMs: 0, updatedAtMs: 0, ), ]); // So sieht es nach dem Scan aus: das Album-Tag von YouTube ist bereits // als Kategorie gelandet. if (album != null) await db.setCategories('yt-1', [album]); return db; } void main() { group('ordneDownloadEin', () { test('das Album-Tag von YouTube wird verworfen', () async { final db = await _dbMitDownload(album: 'Topic - Various Artists'); addTearDown(db.close); await ordneDownloadEin(db, _pfad, 'Nightcore'); final song = (await db.allSongs()).single; expect(song.album, isNull); expect(await db.categoriesOf('yt-1'), ['Nightcore']); }); test('die gewählte Kategorie überlebt den nächsten Scan', () async { final db = await _dbMitDownload(album: 'Topic - Various Artists'); addTearDown(db.close); await ordneDownloadEin(db, _pfad, 'Nightcore'); final song = (await db.allSongs()).single; expect(song.metadataEdited, isTrue, reason: 'Album bleibt verworfen'); expect(song.categoriesEdited, isTrue, reason: 'Kategorie bleibt stehen'); }); test('ohne Angabe bleibt der Titel bewusst ohne Kategorie', () async { final db = await _dbMitDownload(album: 'Topic - Various Artists'); addTearDown(db.close); await ordneDownloadEin(db, _pfad, ' '); expect(await db.categoriesOf('yt-1'), isEmpty); expect((await db.allSongs()).single.album, isNull); }); test('umgebende Leerzeichen zählen nicht zum Namen', () async { final db = await _dbMitDownload(); addTearDown(db.close); await ordneDownloadEin(db, _pfad, ' Nightcore '); expect(await db.categoriesOf('yt-1'), ['Nightcore']); }); test('ein unbekannter Pfad ändert nichts', () async { final db = await _dbMitDownload(album: 'Bleibt'); addTearDown(db.close); await ordneDownloadEin(db, '/gibt/es/nicht.mp3', 'Nightcore'); expect((await db.allSongs()).single.album, 'Bleibt'); expect(await db.categoriesOf('yt-1'), ['Bleibt']); }); }); group('kategorieVorschlaege', () { const vorhanden = ['Nightcore', 'Schwarz', 'Rock Classics']; test('leere Eingabe zeigt alles', () { expect(kategorieVorschlaege('', vorhanden), vorhanden); }); test('filtert nach Teiltreffer, unabhängig von Groß-/Kleinschreibung', () { expect(kategorieVorschlaege('night', vorhanden), ['Nightcore']); expect(kategorieVorschlaege('ROCK', vorhanden), ['Rock Classics']); }); test('ohne Treffer bleibt die Liste leer — die Eingabe wird neue ' 'Kategorie', () { expect(kategorieVorschlaege('Gibtsnicht', vorhanden), isEmpty); }); }); }