| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import 'package:cardash_launcher/data/models/jellyfin_library.dart';
- import 'package:cardash_launcher/data/services/jellyfin_genre_catalog.dart';
- import 'package:flutter_test/flutter_test.dart';
- const _userGenres = <String>[
- '1989',
- 'Acoustic',
- 'Alternative',
- 'Alternative Metal',
- 'Alternative Rock',
- 'ambient',
- 'atmospheric black metal',
- 'Avant-Garde',
- 'avant-garde metal',
- 'Black',
- 'Black Metal',
- 'Blues',
- 'Blues Rock',
- 'Canzone Italiana',
- 'Classical',
- 'Comedy',
- 'Composer',
- 'Conductor',
- 'Country',
- 'country rock',
- 'Dance',
- 'dark ambient',
- 'dark folk',
- 'Death',
- 'Death Metal',
- 'death-doom metal',
- 'depressive black metal',
- 'Doom Metal',
- 'dungeon synth',
- 'Electro',
- 'electronic',
- 'Film Scores',
- 'Films/Games',
- 'Folk',
- 'Folk Metal',
- 'funeral doom metal',
- 'Funk',
- 'Fusion',
- 'glam metal',
- 'gothic',
- 'Gothic Doom Metal',
- 'Gothic Metal',
- 'Gothic Rock',
- 'groove metal',
- 'Grunge',
- 'Hard Rock',
- 'Hardcore',
- 'Heavy metal',
- 'Indie Rock',
- 'industrial metal',
- 'International Pop',
- 'Jazz',
- 'Latin',
- 'Latin Music',
- 'medieval',
- 'Melodic Black Metal',
- 'Melodic Death Metal',
- 'Melodic Metal',
- 'Metal',
- 'neofolk',
- 'New Age',
- 'Pagan',
- 'pagan black metal',
- 'pagan folk',
- 'Pop',
- 'Pop-Rock',
- 'Progressive',
- 'Progressive Metal',
- 'Progressive Rock',
- 'punk',
- 'R&B',
- 'ritual ambient',
- 'Rock',
- 'Rock & Roll',
- 'Rock Pop',
- 'Rock Singer-Songwriter',
- 'Rockabilly',
- 'Singer & Songwriter',
- 'Soul',
- 'Soul & Funk',
- 'Swing',
- 'Symphonic Metal',
- 'Symphonic Power Metal',
- 'symphonic rock',
- 'Thrash Metal',
- 'Viking',
- 'Viking Metal',
- 'Vocal jazz',
- 'Метъл',
- 'Рок',
- 'Хард рок',
- ];
- void main() {
- const catalog = JellyfinGenreCatalog();
- test('groups the whole library without losing a raw genre', () {
- final families = catalog.group(_userGenres);
- final total = families.fold<int>(
- 0,
- (sum, family) => sum + family.rawGenres.length,
- );
- expect(total, _userGenres.length);
- final labels = families.map((family) => family.label).toList();
- expect(labels.first, 'Metal');
- expect(labels[1], 'Rock');
- expect(labels[2], 'Jazz');
- expect(labels, contains('1989'));
- expect(labels, contains('Canzone Italiana'));
- });
- test('maps the requested Metal, Jazz and Rock variants', () {
- final families = catalog.group(_userGenres);
- final byLabel = {for (final family in families) family.label: family};
- expect(
- byLabel['Metal']!.rawGenres,
- containsAll([
- 'Metal',
- 'Melodic Metal',
- 'Heavy metal',
- 'Folk Metal',
- 'Gothic Metal',
- 'Метъл',
- 'Black',
- 'Death',
- 'Viking',
- ]),
- );
- expect(
- byLabel['Rock']!.rawGenres,
- containsAll([
- 'Rock',
- 'Hard Rock',
- 'Pop-Rock',
- 'Alternative',
- 'Alternative Rock',
- 'Grunge',
- 'Progressive',
- 'Rock & Roll',
- 'Rock Singer-Songwriter',
- 'Рок',
- 'Хард рок',
- ]),
- );
- expect(
- byLabel['Jazz']!.rawGenres,
- containsAll(['Jazz', 'Vocal jazz', 'Fusion', 'Swing']),
- );
- expect(
- byLabel['Pop']!.rawGenres,
- containsAll(['Pop', 'Rock Pop', 'International Pop']),
- );
- expect(
- byLabel['Folk']!.rawGenres,
- containsAll(['Folk', 'dark folk', 'neofolk', 'pagan folk', 'medieval']),
- );
- });
- test('keeps the head noun correct for hybrids', () {
- expect(catalog.match('Pop-Rock').id, 'rock');
- expect(catalog.match('Rock Pop').id, 'pop');
- expect(catalog.match('Blues Rock').id, 'rock');
- expect(catalog.match('Country Rock').id, 'rock');
- expect(catalog.match('Folk Metal').id, 'metal');
- expect(catalog.match('Gothic Metal').id, 'metal');
- expect(catalog.match('Gothic Rock').id, 'rock');
- expect(catalog.match('Symphonic Power Metal').id, 'metal');
- expect(catalog.match('Progressive Metal').id, 'metal');
- expect(catalog.match('Progressive Rock').id, 'rock');
- });
- test('maps the remaining canonical families', () {
- final families = catalog.group(_userGenres);
- final byLabel = {for (final family in families) family.label: family};
- expect(byLabel['Blues']!.rawGenres, contains('Blues'));
- expect(byLabel['Soul']!.rawGenres, containsAll(['Soul', 'Soul & Funk']));
- expect(byLabel['R&B']!.rawGenres, contains('R&B'));
- expect(
- byLabel['Classical']!.rawGenres,
- containsAll(['Classical', 'Composer', 'Conductor']),
- );
- expect(
- byLabel['Soundtrack']!.rawGenres,
- containsAll(['Film Scores', 'Films/Games']),
- );
- expect(
- byLabel['Electronic']!.rawGenres,
- containsAll(['Electro', 'electronic', 'Dance']),
- );
- expect(
- byLabel['Ambient']!.rawGenres,
- containsAll([
- 'ambient',
- 'dark ambient',
- 'ritual ambient',
- 'dungeon synth',
- 'New Age',
- ]),
- );
- expect(byLabel['Punk']!.rawGenres, containsAll(['punk', 'Hardcore']));
- expect(byLabel['Latin']!.rawGenres, containsAll(['Latin', 'Latin Music']));
- expect(byLabel['Acoustic']!.rawGenres, contains('Acoustic'));
- expect(byLabel['Avant-Garde']!.rawGenres, contains('Avant-Garde'));
- expect(byLabel['Gothic']!.rawGenres, contains('gothic'));
- expect(byLabel['Pagan']!.rawGenres, contains('Pagan'));
- expect(
- byLabel['Singer-Songwriter']!.rawGenres,
- contains('Singer & Songwriter'),
- );
- expect(byLabel['Comedy']!.rawGenres, contains('Comedy'));
- });
- test('unknown tags stay standalone', () {
- final match = catalog.match('Future Bass');
- expect(match.id, 'raw:future bass');
- expect(match.label, 'Future Bass');
- final families = catalog.group(['Future Bass', 'Metal']);
- expect(families.last.label, 'Future Bass');
- expect(families.last.isStandalone, isTrue);
- });
- test('expands selected families to raw server tags', () {
- final families = catalog.group(_userGenres);
- final raw = catalog.rawGenresFor(
- families: families,
- selectedIds: ['metal', 'jazz'],
- );
- expect(raw, contains('Метъл'));
- expect(raw, contains('Melodic Metal'));
- expect(raw, contains('Jazz'));
- expect(raw, contains('Swing'));
- expect(raw, isNot(contains('Rock')));
- expect(raw, isNot(contains('Pop')));
- });
- test('resolves saved selections and drops missing families', () {
- final families = catalog.group(_userGenres);
- final resolved = catalog.resolveSelections(
- families: families,
- selections: const [
- JellyfinGenreSelection(id: 'metal', label: 'Old metal label'),
- JellyfinGenreSelection(id: 'missing', label: 'Missing'),
- JellyfinGenreSelection(id: 'raw:1989', label: '1989'),
- ],
- );
- expect(resolved.length, 2);
- expect(resolved.first.label, 'Metal');
- expect(resolved.last.label, '1989');
- });
- }
|