feat(library): add bulk duplicate cleanup

This commit is contained in:
zarzet
2026-09-04 12:39:03 +07:00
parent 55da453913
commit cbeada208b
6 changed files with 200 additions and 26 deletions
+49
View File
@@ -0,0 +1,49 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:spotiflac_android/services/library_database.dart';
import 'package:spotiflac_android/utils/duplicate_cleanup_policy.dart';
IsrcDuplicateEntry _entry(String id) {
return IsrcDuplicateEntry(
id: id,
source: 'local',
trackName: 'Track $id',
artistName: 'Artist',
albumName: 'Album',
filePath: '/music/$id.flac',
);
}
void main() {
test('keep-best-all retains one entry and deletes the rest per group', () {
final firstBest = _entry('first-best');
final firstLower = _entry('first-lower');
final firstLowest = _entry('first-lowest');
final secondBest = _entry('second-best');
final secondLower = _entry('second-lower');
final plan = buildKeepBestAllDuplicatePlan([
IsrcDuplicateGroup(
isrc: 'FIRST',
entries: [firstBest, firstLower, firstLowest],
),
IsrcDuplicateGroup(isrc: 'SECOND', entries: [secondBest, secondLower]),
]);
expect(plan.groupCount, 2);
expect(plan.retainedEntries, [firstBest, secondBest]);
expect(plan.entriesToDelete, [firstLower, firstLowest, secondLower]);
});
test('keep-best-all ignores groups that no longer contain duplicates', () {
final onlyCopy = _entry('only-copy');
final plan = buildKeepBestAllDuplicatePlan([
IsrcDuplicateGroup(isrc: 'ONLY', entries: [onlyCopy]),
const IsrcDuplicateGroup(isrc: 'EMPTY', entries: []),
]);
expect(plan.groupCount, 0);
expect(plan.retainedEntries, isEmpty);
expect(plan.entriesToDelete, isEmpty);
});
}