import 'dart:io'; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:melo/library/database.dart'; import 'package:melo/library/scan_service.dart'; import 'package:path/path.dart' as p; void main() { final fixtures = p.join(Directory.current.path, 'test', 'fixtures', 'audio'); late MeloDb db; late Directory coverDir; setUp(() async { db = MeloDb(NativeDatabase.memory()); coverDir = await Directory.systemTemp.createTemp('melo_covers'); }); tearDown(() async { await db.close(); await coverDir.delete(recursive: true); }); test('scanFolders liest Tags aus den Test-mp3s', () async { final count = await scanFolders(db, [fixtures], coverDir: coverDir); expect(count, 3); final songs = await db.watchSongs().first; expect( songs.map((s) => s.title).toSet(), {'Nachtpuls', 'Taglicht', 'Herzschlag'}, ); final nacht = songs.firstWhere((s) => s.title == 'Nachtpuls'); expect(nacht.artist, 'Rotklang'); expect(nacht.album, 'Schwarz'); expect(nacht.durationMs, greaterThan(0)); }); test('extrahiert eingebettetes Cover als Datei', () async { await scanFolders(db, [fixtures], coverDir: coverDir); final songs = await db.watchSongs().first; final withCover = songs.where((s) => s.coverPath != null).toList(); // Nur "Nachtpuls" hat ein eingebettetes Cover. expect(withCover.length, 1); expect(withCover.first.title, 'Nachtpuls'); expect(File(withCover.first.coverPath!).existsSync(), isTrue); }); test('Re-Scan behält die UUID (sync-stabil)', () async { await scanFolders(db, [fixtures], coverDir: coverDir); final firstIds = { for (final s in await db.watchSongs().first) s.path: s.id }; await scanFolders(db, [fixtures], coverDir: coverDir); final secondIds = { for (final s in await db.watchSongs().first) s.path: s.id }; expect(secondIds, firstIds); expect((await db.watchSongs().first).length, 3); // keine Duplikate }); }