Files
Melo/test/library/song_sort_test.dart
T
dustinandClaude Opus 5 7aa98864aa Kategorien (mehrere je Song), Metadaten-Ansicht mit Expertenmodus
- DB-Schema 4: Tabelle song_categories + Spalte categories_edited
- Kategorien kommen aus dem Genre-Tag (Trennung an ; , | /), manuell
  bearbeitbar; von Hand gesetzte Kategorien ueberlebt der naechste Scan
- Songzeile zeigt "Kuenstler | Kategorie1 - Kategorie2"
- Einstellung "Gleiche Kategorie = gleiches Coverbild" (Standard an)
- Metadaten-Sheet mit ausklappbarem Expertenmodus
- Neu: categories.dart, category_service.dart, song_detail_sheet.dart,
  app_settings.dart

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011snPXPafPC5i87o68H14W7
2026-08-20 18:29:45 +02:00

139 lines
4.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter_test/flutter_test.dart';
import 'package:melo/library/database.dart';
import 'package:melo/library/song_sort.dart';
Song _song(
String title, {
String? id,
int dateAddedMs = 0,
int playCount = 0,
}) {
return Song(
id: id ?? title,
path: '/$title.mp3',
title: title,
dateAddedMs: dateAddedMs,
updatedAtMs: 0,
deleted: false,
playCount: playCount,
categoriesEdited: false,
);
}
void main() {
group('SortMode.name — A-Z, Ziffern/Zeichen unter # ans Ende', () {
test('sortiert Buchstaben alphabetisch, Ziffern und Zeichen danach', () {
final songs = [
_song('9 Lives'),
_song('Zenit'),
_song('#Hashtag'),
_song('Anfang'),
];
final sorted = sortSongs(songs, SortMode.name, ascending: true);
expect(sorted.map((s) => s.title), ['Anfang', 'Zenit', '#Hashtag', '9 Lives']);
});
test('ignoriert Groß-/Kleinschreibung', () {
final songs = [_song('beta'), _song('Alpha'), _song('CHARLIE')];
final sorted = sortSongs(songs, SortMode.name, ascending: true);
expect(sorted.map((s) => s.title), ['Alpha', 'beta', 'CHARLIE']);
});
test('Umlaute sortieren wie ihr Grundbuchstabe', () {
final songs = [_song('Zug'), _song('Ärger'), _song('Anfang'), _song('Öl')];
final sorted = sortSongs(songs, SortMode.name, ascending: true);
expect(sorted.map((s) => s.title), ['Anfang', 'Ärger', 'Öl', 'Zug']);
});
test('absteigend dreht die Reihenfolge um', () {
final songs = [_song('Anfang'), _song('9 Lives'), _song('Zenit')];
final sorted = sortSongs(songs, SortMode.name, ascending: false);
expect(sorted.map((s) => s.title), ['9 Lives', 'Zenit', 'Anfang']);
});
});
group('SortMode.dateAdded', () {
test('absteigend = zuletzt hinzugefügt zuerst', () {
final songs = [
_song('Alt', dateAddedMs: 100),
_song('Neu', dateAddedMs: 300),
_song('Mittel', dateAddedMs: 200),
];
final sorted = sortSongs(songs, SortMode.dateAdded, ascending: false);
expect(sorted.map((s) => s.title), ['Neu', 'Mittel', 'Alt']);
});
test('aufsteigend = ältester zuerst', () {
final songs = [
_song('Neu', dateAddedMs: 300),
_song('Alt', dateAddedMs: 100),
];
final sorted = sortSongs(songs, SortMode.dateAdded, ascending: true);
expect(sorted.map((s) => s.title), ['Alt', 'Neu']);
});
});
group('SortMode.playCount', () {
test('absteigend = meistgespielt zuerst', () {
final songs = [
_song('Selten', playCount: 1),
_song('Oft', playCount: 42),
_song('Nie', playCount: 0),
];
final sorted = sortSongs(songs, SortMode.playCount, ascending: false);
expect(sorted.map((s) => s.title), ['Oft', 'Selten', 'Nie']);
});
});
group('Stabilität', () {
test('gleiche Sortierwerte werden nach Titel entschieden', () {
final songs = [
_song('Bravo', id: 'b', dateAddedMs: 5),
_song('Alpha', id: 'a', dateAddedMs: 5),
];
final sorted = sortSongs(songs, SortMode.dateAdded, ascending: false);
expect(sorted.map((s) => s.title), ['Alpha', 'Bravo']);
});
test('verändert die Eingabeliste nicht', () {
final songs = [_song('Zenit'), _song('Anfang')];
sortSongs(songs, SortMode.name, ascending: true);
expect(songs.map((s) => s.title), ['Zenit', 'Anfang']);
});
});
group('Standard-Richtung pro Modus', () {
test('Datum und Wiedergaben starten absteigend, Name aufsteigend', () {
expect(defaultAscending(SortMode.dateAdded), isFalse);
expect(defaultAscending(SortMode.playCount), isFalse);
expect(defaultAscending(SortMode.name), isTrue);
});
});
group('Beschriftungen', () {
test('jeder Modus hat ein deutsches Label', () {
expect(SortMode.dateAdded.label, 'Zuletzt hinzugefügt');
expect(SortMode.name.label, 'Name (AZ#)');
expect(SortMode.playCount.label, 'Wie oft abgespielt');
});
});
}