Initial commit
This commit is contained in:
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:melo/library/database.dart';
|
||||
|
||||
void main() {
|
||||
late MeloDb db;
|
||||
setUp(() => db = MeloDb(NativeDatabase.memory()));
|
||||
tearDown(() => db.close());
|
||||
|
||||
SongsCompanion song(String id, String path, String title, {String? artist}) =>
|
||||
SongsCompanion.insert(
|
||||
id: id,
|
||||
path: path,
|
||||
title: title,
|
||||
artist: Value(artist),
|
||||
dateAddedMs: 1,
|
||||
updatedAtMs: 1,
|
||||
);
|
||||
|
||||
test('upsert + watchSongs sortiert nach Titel', () async {
|
||||
await db.upsertSongs([song('1', '/a.mp3', 'Beta'), song('2', '/b.mp3', 'Alpha')]);
|
||||
final songs = await db.watchSongs().first;
|
||||
expect(songs.map((s) => s.title), ['Alpha', 'Beta']);
|
||||
});
|
||||
|
||||
test('Re-upsert gleicher id erzeugt kein Duplikat, aktualisiert', () async {
|
||||
await db.upsertSongs([song('1', '/a.mp3', 'Alt')]);
|
||||
await db.upsertSongs([song('1', '/a.mp3', 'Neu')]);
|
||||
final songs = await db.watchSongs().first;
|
||||
expect(songs.length, 1);
|
||||
expect(songs.first.title, 'Neu');
|
||||
});
|
||||
|
||||
test('searchSongs findet über Titel und Künstler', () async {
|
||||
await db.upsertSongs([
|
||||
song('1', '/a.mp3', 'Nachtpuls', artist: 'Rotklang'),
|
||||
song('2', '/b.mp3', 'Taglicht', artist: 'Beatzwei'),
|
||||
]);
|
||||
expect((await db.searchSongs('nacht').first).length, 1);
|
||||
expect((await db.searchSongs('rotklang').first).length, 1);
|
||||
expect((await db.searchSongs('xyz').first).length, 0);
|
||||
});
|
||||
|
||||
test('markMissing setzt Tombstone für fehlende Pfade', () async {
|
||||
await db.upsertSongs([song('1', '/a.mp3', 'A'), song('2', '/b.mp3', 'B')]);
|
||||
await db.markMissing(['/a.mp3'], 2); // /b.mp3 fehlt jetzt
|
||||
final songs = await db.watchSongs().first;
|
||||
expect(songs.map((s) => s.path), ['/a.mp3']);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user