This commit is contained in:
Forrest 2026-08-05 21:57:06 -04:00
parent 2ce32cac4e
commit b6639fb1c9
26 changed files with 454 additions and 204 deletions

View file

@ -176,6 +176,7 @@ void main() {
albumSort: AlbumSort.recentlyAdded,
trackSort: TrackSort.yearDesc,
nowPlayingCassette: true,
appTheme: AppTheme.lavender,
);
final back = AppSettings.fromJson(s.toJson());
expect(back.useStaticAccent, isTrue);
@ -186,6 +187,7 @@ void main() {
expect(back.albumSort, AlbumSort.recentlyAdded);
expect(back.trackSort, TrackSort.yearDesc);
expect(back.nowPlayingCassette, isTrue);
expect(back.appTheme, AppTheme.lavender);
});
test('fromJson falls back to defaults for missing/unknown values', () {
@ -201,6 +203,7 @@ void main() {
expect(back.albumSort, AlbumSort.nameAsc);
expect(back.trackSort, TrackSort.titleAsc);
expect(back.nowPlayingCassette, isFalse);
expect(back.appTheme, AppTheme.standard);
// An unrecognised enum name also falls back rather than throwing.
expect(
AppSettings.fromJson({'defaultBrowseMode': 'bogus'}).defaultBrowseMode,
@ -533,5 +536,46 @@ void main() {
songs, const BrowseFilter(genre: 'rock'), TrackSort.titleAsc);
expect(out.map((s) => s.id), ['b', 'a']);
});
test('track ratingDesc sorts highest first, unrated last, tie-break title',
() {
final songs = [
song('low', title: 'A'),
song('high', title: 'B'),
song('unrated', title: 'C'),
song('tieB', title: 'Zed'),
song('tieA', title: 'Abe'),
];
final out = applyTrackQuery(
songs,
const BrowseFilter(),
TrackSort.ratingDesc,
ratings: {'low': 2, 'high': 5, 'tieA': 3, 'tieB': 3},
);
// 5, then the two 3s (title tie-break Abe<Zed), then 2, then unrated (0).
expect(out.map((s) => s.id), ['high', 'tieA', 'tieB', 'low', 'unrated']);
});
test('track ratingDesc falls back to Song.userRating when not in map', () {
final songs = [
Song(id: 'r4', title: 'A', userRating: 4),
Song(id: 'r1', title: 'B', userRating: 1),
];
final out =
applyTrackQuery(songs, const BrowseFilter(), TrackSort.ratingDesc);
expect(out.map((s) => s.id), ['r4', 'r1']);
});
test('track minRating filter keeps only tracks at or above the threshold',
() {
final songs = [song('a'), song('b'), song('c'), song('d')];
final out = applyTrackQuery(
songs,
const BrowseFilter(minRating: 3),
TrackSort.titleAsc,
ratings: {'a': 5, 'b': 3, 'c': 2}, // d unrated (0)
);
expect(out.map((s) => s.id), ['a', 'b']);
});
});
}