feat(ratings): show every rating source the server already sent
Plezy rendered exactly one score per item. MediaRatingBadge._ratingDataFor took `rating` and fell back to `audienceRating` only when it was null, so a Plex movie carrying four attributed scores surfaced one, and which one was whatever the server happened to put in the scalar slot. #1755 asked for a setting to choose the source; showing all of them answers it without one. The data was already on the wire and being thrown away. `/library/metadata/ {id}` returns a `Rating[]` child array — IMDb, both Rotten Tomatoes panels, TMDB — with no extra query parameter, but PlexMetadataDto declared no field for it, so json_serializable dropped the key. The identical parse already existed in plex_catalog_source for the Explore tab and had simply never been wired to library items. Model the scores as a list rather than widening the scalar pair. The neutral MediaItem gains `ratings`; PlexMediaItem loses audienceRating, ratingImage and audienceRatingImage, which the list subsumes — Plex sends those images on listings too, so the same field covers both response shapes and no caller narrows to a backend type to read a score any more. CatalogRatingSource is promoted to lib/media as MediaRatingSource instead of growing a second near-identical type beside it, and plex_catalog_source's _ratingsFor becomes the shared plexRatingSources so one implementation serves both paths. There is no persistence to migrate: MediaItem.toJson has no production caller, the offline path re-parses raw Plex JSON through the same mapper, and Plex's audienceRating sort is server-supplied data, not a model read. Cards and the dashboard still show fewer scores than detail screens, and that part is a real Plex limit rather than a shortcut. Section listings send only the scalar pair; includeRatings, includeElements=Rating, includeFields=Rating, includeChildren and includeExtras were each probed against a live server and none surfaced the array, while includeGuids=1 demonstrably does add Guid[] — the probe works, the parameter does not exist. Hydrating every card would be one request per row, so listings render whatever their own response carried, which is one or two attributed scores rather than the single one they showed before. Jellyfin has no per-source array at all: the server collapses whatever its fetchers found into CommunityRating and CriticRating. CommunityRating's provenance is unknowable from the DTO — TMDB vote_average, IMDb via OMDb or a local NFO, last writer wins — so it stays the generic `audience` source with no brand mark. CriticRating is the Rotten Tomatoes Tomatometer as a 0-100 percent and is divided by ten explicitly rather than folded by magnitude, because a Tomatometer of 9 means 9% and range-sniffing would have promoted a rotten score to fresh. Photo rows are skipped, since Jellyfin reuses CommunityRating for the EXIF 0-5 star. The badges share one slot on every surface. On the phone hero the scores go in a single pill because that chip row is a height-clipped Wrap and a chip per source would push year, certification and runtime out of the visible band on short heroes; on the TV detail line and the dashboard spotlight the group occupies the one metadata slot so bullet separators do not multiply. The group announces itself as a single semantics node naming each source, because a bare row of four percentages tells a screen reader nothing about which score is which. rating_utils drops parseRatingImage and isRottenTomatoes — the URI vocabulary now lives only in the Plex mapper — and the source-key resolver and label map, previously private to the Explore detail screen, become the shared pair both screens use. The label strings move from explore.ratingSource to common.ratingSource accordingly, which costs no translations because every non-English value was empty; running clean_translations also scaffolds startup.quitPlezy and startup.restartRequiredBody, which were already drifted. Verified against the live server the probes came from: a detail response now yields TMDB 83%, IMDb 8.3 and Rotten Tomatoes audience 96% through the production mapper and badge resolver, and the listing response for the same title yields TMDB 83% alone. Both payloads are pinned verbatim as fixtures. Coverage adds mapper ordering, dedupe against the array's repeat of the scalar, out-of-range rejection, the Jellyfin scale and photo guard, the CatalogItem conversion that feeds Explore's dashboard hubs, and the three render surfaces including the semantics announcement. close #1755
This commit is contained in:
@@ -1,88 +1,91 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/i18n/strings.g.dart';
|
||||
import 'package:plezy/utils/rating_utils.dart';
|
||||
|
||||
void main() {
|
||||
group('parseRatingImage - null/missing', () {
|
||||
test('returns null when imageUri is null', () {
|
||||
expect(parseRatingImage(null, 7.5), isNull);
|
||||
});
|
||||
setUpAll(() => LocaleSettings.setLocaleRaw('en'));
|
||||
|
||||
test('returns null when value is null', () {
|
||||
expect(parseRatingImage('imdb://title/tt123', null), isNull);
|
||||
});
|
||||
|
||||
test('returns null for unknown scheme', () {
|
||||
expect(parseRatingImage('unknown://foo', 5.0), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('parseRatingImage - Rotten Tomatoes', () {
|
||||
test('ripe maps to rt_fresh with percent', () {
|
||||
final info = parseRatingImage('rottentomatoes://image.rating.ripe', 7.5);
|
||||
expect(info, isNotNull);
|
||||
group('ratingInfoForSource - Rotten Tomatoes', () {
|
||||
test('critic at or above the 60% tomatometer is fresh', () {
|
||||
final info = ratingInfoForSource('rottenTomatoesCritic', 6.0);
|
||||
expect(info!.assetPath, 'assets/rating_icons/rt_fresh.svg');
|
||||
expect(info.formattedValue, '75%');
|
||||
expect(info.formattedValue, '60%');
|
||||
});
|
||||
|
||||
test('rotten maps to rt_rotten', () {
|
||||
final info = parseRatingImage('rottentomatoes://image.rating.rotten', 3.2);
|
||||
expect(info, isNotNull);
|
||||
test('critic below the tomatometer is rotten', () {
|
||||
final info = ratingInfoForSource('rottenTomatoesCritic', 5.9);
|
||||
expect(info!.assetPath, 'assets/rating_icons/rt_rotten.svg');
|
||||
expect(info.formattedValue, '32%');
|
||||
expect(info.formattedValue, '59%');
|
||||
});
|
||||
|
||||
test('upright maps to rt_upright', () {
|
||||
final info = parseRatingImage('rottentomatoes://image.rating.upright', 8.8);
|
||||
expect(info!.assetPath, 'assets/rating_icons/rt_upright.svg');
|
||||
expect(info.formattedValue, '88%');
|
||||
test('audience uses the popcorn pair on the same threshold', () {
|
||||
expect(ratingInfoForSource('rottenTomatoesAudience', 6.0)!.assetPath, 'assets/rating_icons/rt_upright.svg');
|
||||
expect(ratingInfoForSource('rottenTomatoesAudience', 5.9)!.assetPath, 'assets/rating_icons/rt_spilled.svg');
|
||||
});
|
||||
|
||||
test('spilled maps to rt_spilled', () {
|
||||
final info = parseRatingImage('rottentomatoes://image.rating.spilled', 2.0);
|
||||
expect(info!.assetPath, 'assets/rating_icons/rt_spilled.svg');
|
||||
expect(info.formattedValue, '20%');
|
||||
test('the unsplit key follows the critic pair', () {
|
||||
expect(ratingInfoForSource('rottenTomatoes', 9.2)!.assetPath, 'assets/rating_icons/rt_fresh.svg');
|
||||
});
|
||||
|
||||
test('unknown RT suffix returns null', () {
|
||||
expect(parseRatingImage('rottentomatoes://image.rating.green', 5.0), isNull);
|
||||
});
|
||||
|
||||
test('percent rounds to whole number', () {
|
||||
final info = parseRatingImage('rottentomatoes://image.rating.ripe', 7.57);
|
||||
expect(info!.formattedValue, '76%');
|
||||
test('percent rounds to a whole number', () {
|
||||
expect(ratingInfoForSource('rottenTomatoesCritic', 7.57)!.formattedValue, '76%');
|
||||
});
|
||||
});
|
||||
|
||||
group('parseRatingImage - IMDb', () {
|
||||
test('formats with one decimal', () {
|
||||
final info = parseRatingImage('imdb://title/tt123', 7.5);
|
||||
group('ratingInfoForSource - branded scales', () {
|
||||
test('IMDb keeps its 0-10 decimal', () {
|
||||
final info = ratingInfoForSource('imdb', 7.5);
|
||||
expect(info!.assetPath, 'assets/rating_icons/imdb.svg');
|
||||
expect(info.formattedValue, '7.5');
|
||||
});
|
||||
});
|
||||
|
||||
group('parseRatingImage - TMDB', () {
|
||||
test('converts value*10 to percent', () {
|
||||
final info = parseRatingImage('themoviedb://foo', 6.8);
|
||||
test('TMDB renders as a percentage', () {
|
||||
final info = ratingInfoForSource('tmdb', 6.8);
|
||||
expect(info!.assetPath, 'assets/rating_icons/tmdb.svg');
|
||||
expect(info.formattedValue, '68%');
|
||||
});
|
||||
});
|
||||
|
||||
group('isRottenTomatoes', () {
|
||||
test('matches rottentomatoes:// scheme', () {
|
||||
expect(isRottenTomatoes('rottentomatoes://image.rating.ripe'), isTrue);
|
||||
expect(isRottenTomatoes('rottentomatoes://anything'), isTrue);
|
||||
group('ratingInfoForSource - unbranded sources', () {
|
||||
test('sources without a logo get no badge so they stay label-only', () {
|
||||
for (final source in ['critic', 'audience', 'simkl', 'mal', 'anilist', 'trakt']) {
|
||||
expect(ratingInfoForSource(source, 8.0), isNull, reason: source);
|
||||
}
|
||||
});
|
||||
|
||||
test('false for null', () {
|
||||
expect(isRottenTomatoes(null), isFalse);
|
||||
test('an unknown key gets no badge', () {
|
||||
expect(ratingInfoForSource('letterboxd', 8.0), isNull);
|
||||
expect(ratingInfoForSource('', 8.0), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('ratingSourceLabel', () {
|
||||
test('names every source the mappers can emit', () {
|
||||
const sources = [
|
||||
'critic',
|
||||
'audience',
|
||||
'imdb',
|
||||
'tmdb',
|
||||
'rottenTomatoes',
|
||||
'rottenTomatoesCritic',
|
||||
'rottenTomatoesAudience',
|
||||
'simkl',
|
||||
'mal',
|
||||
'anilist',
|
||||
'trakt',
|
||||
];
|
||||
for (final source in sources) {
|
||||
expect(ratingSourceLabel(source), isNotEmpty, reason: source);
|
||||
}
|
||||
});
|
||||
|
||||
test('false for other schemes', () {
|
||||
expect(isRottenTomatoes('imdb://title'), isFalse);
|
||||
expect(isRottenTomatoes('themoviedb://foo'), isFalse);
|
||||
expect(isRottenTomatoes(''), isFalse);
|
||||
test('keeps the Rotten Tomatoes panels distinguishable', () {
|
||||
expect(ratingSourceLabel('rottenTomatoesCritic'), isNot(ratingSourceLabel('rottenTomatoesAudience')));
|
||||
});
|
||||
|
||||
test('returns null for an unknown key so it can be dropped rather than shown raw', () {
|
||||
expect(ratingSourceLabel('letterboxd'), isNull);
|
||||
expect(ratingSourceLabel(''), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user