feat(app): 完善播放协议搜索与空状态

This commit is contained in:
Zhou Weidong committed 2026-10-23 12:38:47 +08:00
1 parent 671e0ce143
commit ef29fc5f15
85 files changed
+2976 -768

No files matched your search

+77 -2
View File
@@ -118,6 +118,75 @@ void main() {
expect(disabledText.style?.color, AppColors.subtle);
});
testWidgets('should_enable_quality_when_ticket_uses_lowercase_codes', (
tester,
) async {
await _openSheet(
tester,
qualities: const ['AUTO', '360p', '480p', '720p', '1080p'],
);
expect(find.text('720P'), findsOneWidget);
expect(find.text('1080P'), findsOneWidget);
expect(find.textContaining('暂不可用'), findsNothing);
final enabled = tester.widget<Text>(
find.descendant(
of: find.byKey(const Key('player-more-quality-720P')),
matching: find.byType(Text),
),
);
expect(enabled.style?.color, isNot(AppColors.subtle));
});
testWidgets('should_report_selected_quality_when_a_rendition_is_tapped', (
tester,
) async {
String? picked;
await _openSheet(
tester,
qualities: const ['AUTO', '720p'],
onQuality: (quality) async {
picked = quality;
return true;
},
);
await tester.ensureVisible(find.byKey(const Key('player-more-quality-720P')));
await tester.tap(find.byKey(const Key('player-more-quality-720P')));
await tester.pump();
expect(picked, '720P');
final selected = tester.widget<Text>(
find.descendant(
of: find.byKey(const Key('player-more-quality-720P')),
matching: find.byType(Text),
),
);
expect(selected.style?.color, AppColors.onSurface);
});
testWidgets('should_restore_previous_quality_when_switch_fails', (
tester,
) async {
await _openSheet(
tester,
qualities: const ['AUTO', '720p'],
onQuality: (_) async => false,
);
await tester.ensureVisible(find.byKey(const Key('player-more-quality-720P')));
await tester.tap(find.byKey(const Key('player-more-quality-720P')));
await tester.pumpAndSettle();
final restored = tester.widget<Text>(
find.descendant(
of: find.byKey(const Key('player-more-quality-AUTO')),
matching: find.byType(Text),
),
);
expect(restored.style?.color, AppColors.onSurface);
});
testWidgets('should_trigger_pip_and_close_sheet_when_tapped', (tester) async {
var pipCalls = 0;
await _openSheet(tester, onPip: () => pipCalls++);
@@ -142,7 +211,12 @@ void main() {
});
}
Future<void> _openSheet(WidgetTester tester, {VoidCallback? onPip}) async {
Future<void> _openSheet(
WidgetTester tester, {
VoidCallback? onPip,
Future<bool> Function(String quality)? onQuality,
List<String> qualities = const ['AUTO'],
}) async {
await tester.pumpWidget(
MaterialApp(
supportedLocales: AppLocalizations.supportedLocales,
@@ -158,11 +232,12 @@ Future<void> _openSheet(WidgetTester tester, {VoidCallback? onPip}) async {
isScrollControlled: true,
builder: (_) => PlayerMoreSheet(
l10n: AppLocalizations.of(context)!,
state: const PlayerMoreState(speed: 1.0, qualities: ['AUTO']),
state: PlayerMoreState(speed: 1.0, qualities: qualities),
actions: PlayerMoreActions(
onSpeedChanged: (_) {},
onClear: () {},
onDownload: () {},
onQualityChanged: onQuality ?? (_) async => true,
onPip: onPip,
),
),