Files
Melo/test/library/song_sort_test.dart
T
dustinandClaude Opus 5 2667613a2e Neue Melo-UI Phase 1: 4 Tabs (Meine Musik/Suche/Favoriten/Download) + Sortierung
- Meine Musik als Startbildschirm ohne Topbar: Kopfzeile (Einstellungen,
  Suche, Musikerkennung), Schnellzugriffe, Shuffle + Sortieren, Liederliste
- Sortierung nach Zuletzt hinzugefuegt / Name (A-Z-#) / Wie oft abgespielt,
  auf- und absteigend, pro Liste gespeichert (SortStore)
- Favoriten als eigener Tab mit gleicher Shuffle-/Sortier-Leiste
- Download-Tab uebernimmt den Navidrome-Server-Browser
- DB-Schema 3: playCount, gezaehlt beim Titelstart
- Theme auf #0B0B10 / #c0392b
- Scan-Aktionen aus der entfallenen Topbar jetzt in den Einstellungen

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

138 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,
);
}
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');
});
});
}