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:
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/i18n/strings.g.dart';
|
||||
import 'package:plezy/media/media_item.dart';
|
||||
import 'package:plezy/media/media_kind.dart';
|
||||
import 'package:plezy/media/media_rating.dart';
|
||||
import 'package:plezy/services/settings_service.dart';
|
||||
import 'package:plezy/utils/platform_detector.dart';
|
||||
import 'package:plezy/widgets/tv_spotlight_background.dart';
|
||||
|
||||
import '../test_helpers/prefs.dart';
|
||||
|
||||
/// The TV dashboard spotlight (Discover, Explore, and the library recommended
|
||||
/// tab all render through [TvSpotlightBackground]) shows every score the hub
|
||||
/// listing already returned. Listings carry the scalar rating pair, so this is
|
||||
/// normally one or two entries — never a reason to re-fetch an item.
|
||||
Future<void> _pumpSpotlight(WidgetTester tester, MediaItem item) async {
|
||||
await SettingsService.getInstance();
|
||||
tester.view.physicalSize = const Size(1920, 1080);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
TranslationProvider(
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
// TvSpotlightScaffold fills the screen with the background; a loose
|
||||
// Scaffold body would leave its bottom-anchored info block unbounded.
|
||||
body: SizedBox.expand(
|
||||
child: TvSpotlightBackground(
|
||||
item: item,
|
||||
client: null,
|
||||
allowNetwork: false,
|
||||
showPrimaryAction: false,
|
||||
compact: true,
|
||||
contentTop: 80,
|
||||
contentBottom: 200,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() {
|
||||
resetSharedPreferencesForTest();
|
||||
SettingsService.resetForTesting();
|
||||
TvDetectionService.debugSetAppleTVOverride(true);
|
||||
LocaleSettings.setLocaleSync(AppLocale.en);
|
||||
});
|
||||
|
||||
tearDown(() => TvDetectionService.debugSetAppleTVOverride(null));
|
||||
|
||||
testWidgets('dashboard spotlight badges every rating the listing carried', (tester) async {
|
||||
await _pumpSpotlight(
|
||||
tester,
|
||||
const MediaItem.plex(
|
||||
id: 'movie_1',
|
||||
kind: MediaKind.movie,
|
||||
title: 'Spotlight Movie',
|
||||
rating: 9.2,
|
||||
ratings: [
|
||||
MediaRatingSource(source: 'rottenTomatoesCritic', value: 9.2),
|
||||
MediaRatingSource(source: 'rottenTomatoesAudience', value: 8.5),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('92%'), findsOneWidget);
|
||||
expect(find.text('85%'), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets('dashboard spotlight still shows one badge for a single-score listing', (tester) async {
|
||||
await _pumpSpotlight(
|
||||
tester,
|
||||
const MediaItem.jellyfin(
|
||||
id: 'movie_2',
|
||||
kind: MediaKind.movie,
|
||||
title: 'Community Only',
|
||||
rating: 8.3,
|
||||
ratings: [MediaRatingSource(source: 'audience', value: 8.3)],
|
||||
),
|
||||
);
|
||||
|
||||
// No brand logo exists for an unattributed community score, so it keeps
|
||||
// the generic icon and the neutral 0-10 rendering.
|
||||
expect(find.text('8.3'), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('dashboard spotlight omits the rating slot when the item has no score', (tester) async {
|
||||
await _pumpSpotlight(
|
||||
tester,
|
||||
const MediaItem.plex(id: 'movie_3', kind: MediaKind.movie, title: 'Unrated', year: 2024),
|
||||
);
|
||||
|
||||
expect(find.text('2024'), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('dashboard spotlight announces each rating with its source name', (tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
|
||||
await _pumpSpotlight(
|
||||
tester,
|
||||
const MediaItem.plex(
|
||||
id: 'movie_4',
|
||||
kind: MediaKind.movie,
|
||||
title: 'Announced Movie',
|
||||
ratings: [
|
||||
MediaRatingSource(source: 'rottenTomatoesCritic', value: 9.2),
|
||||
MediaRatingSource(source: 'imdb', value: 7.4),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
// Without the group's own label a reader would hear "92%, 7.4" with no
|
||||
// way to tell which score belongs to which source.
|
||||
expect(
|
||||
find.bySemanticsLabel('${t.common.ratingSource.rottenTomatoesCritic} 92%, ${t.common.ratingSource.imdb} 7.4'),
|
||||
findsOneWidget,
|
||||
);
|
||||
semantics.dispose();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user