feat(flutter): 重设计播放页与操作面板

This commit is contained in:
Zhou Weidong committed 2026-10-20 10:41:56 +08:00
1 parent 148fbc3c93
commit 9a4269b847
24 files changed
+2395 -1101

No files matched your search

+1 -1
View File
@@ -68,7 +68,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('Second page'), findsOneWidget);
expect(find.text('Comments · 2'), findsOneWidget);
expect(find.text('Comments (2)'), findsOneWidget);
expect(repository.pageCalls.last.cursor, '10');
});
+156 -10
View File
@@ -6,6 +6,8 @@ import 'package:shared_preferences_platform_interface/in_memory_shared_preferenc
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
import 'package:fruitshorts/app.dart';
import 'package:fruitshorts/core/data/models/drama.dart';
import 'package:fruitshorts/core/data/models/play_ticket.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
@@ -287,29 +289,145 @@ void main() {
);
expect(bar.showTimes, isTrue);
});
testWidgets('should_render_k28_player_structure_and_episode_grid', (
tester,
) async {
await _pumpApp(tester);
await _openSeriesPlayer(tester);
_expectFullscreenOverlay(tester);
await tester.tap(find.byKey(const Key('player-episodes')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-episodes-sheet')), findsOneWidget);
expect(find.byKey(const Key('player-episodes-close')), findsOneWidget);
final grid = tester.widget<GridView>(
find.descendant(
of: find.byKey(const Key('player-episodes-sheet')),
matching: find.byType(GridView),
),
);
final delegate =
grid.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
expect(delegate.crossAxisCount, 6);
expect(tester.takeException(), isNull);
});
testWidgets('should_show_locked_episode_in_episode_picker', (tester) async {
await _pumpApp(
tester,
catalog: FakeCatalogRepository(dramas: const [_lockedDrama]),
);
await _openSeriesPlayer(
tester,
cardKey: const Key('home-drama-card-locked-demo'),
);
await tester.tap(find.byKey(const Key('player-episodes')));
await tester.pumpAndSettle();
expect(
find.byKey(const ValueKey('episode-lock-locked-demo-1')),
findsOneWidget,
);
expect(find.byKey(const Key('player-episode-2')), findsOneWidget);
});
testWidgets('should_open_more_actions_and_change_text_size', (tester) async {
await _pumpApp(tester);
await _openSeriesPlayer(tester);
await tester.tap(find.byKey(const Key('player-more')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-more-sheet')), findsOneWidget);
expect(find.byKey(const Key('player-more-speed')), findsOneWidget);
expect(find.byKey(const Key('player-more-quality')), findsOneWidget);
expect(find.byKey(const Key('player-more-download')), findsOneWidget);
expect(find.byKey(const Key('player-more-text-size')), findsOneWidget);
expect(find.byKey(const Key('player-more-report')), findsOneWidget);
await tester.tap(find.byKey(const Key('player-more-text-size')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-text-size-sheet')), findsOneWidget);
await tester.tap(find.byKey(const Key('player-text-size-large')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('player-more')));
await tester.pumpAndSettle();
expect(
find.descendant(
of: find.byKey(const Key('player-more-text-size')),
matching: find.text('Large'),
),
findsOneWidget,
);
});
testWidgets('should_open_unlock_panel_with_honest_method_states', (
tester,
) async {
await _pumpApp(
tester,
playback: FakePlaybackRepository(
ticket: const PlayTicket(
episodeId: 'city-lights-demo-1',
accessible: false,
accessType: PlayTicket.coinRequired,
unlockCoin: 30,
),
),
);
await _openSeriesPlayer(tester);
expect(find.byKey(const Key('player-unlock-notice')), findsOneWidget);
await tester.tap(find.byKey(const Key('player-open-unlock')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-unlock-panel')), findsOneWidget);
expect(find.byKey(const Key('player-unlock-coins')), findsOneWidget);
expect(find.byKey(const Key('player-unlock-ad')), findsOneWidget);
expect(find.byKey(const Key('player-unlock-vip')), findsOneWidget);
expect(
find.text('Available unlock methods vary by title.'),
findsOneWidget,
);
});
}
void _expectFullscreenOverlay(WidgetTester tester) {
expect(find.byKey(const Key('player-back')), findsOneWidget);
expect(find.byKey(const Key('player-title')), findsOneWidget);
expect(find.byKey(const Key('player-title-dot')), findsOneWidget);
expect(find.byKey(const Key('player-subtitle')), findsOneWidget);
expect(find.byKey(const Key('player-genre-chip')), findsOneWidget);
expect(find.byKey(const Key('player-page-dots')), findsOneWidget);
expect(find.byKey(const Key('player-drama-title')), findsOneWidget);
expect(find.byKey(const Key('player-episode-label')), findsOneWidget);
expect(find.byKey(const Key('player-follow')), findsOneWidget);
expect(find.byKey(const Key('player-synopsis')), findsOneWidget);
expect(find.byKey(const Key('player-time-label')), findsOneWidget);
expect(find.byKey(const Key('player-more')), findsOneWidget);
for (final key in const [Key('player-back'), Key('player-more')]) {
expect(tester.getSize(find.byKey(key)), const Size(36, 36));
}
expect(find.byKey(const Key('player-play-toggle')), findsNothing);
expect(find.byKey(const Key('player-episodes')), findsOneWidget);
expect(find.byKey(const Key('player-comments')), findsOneWidget);
expect(find.byKey(const Key('player-rail-comments')), findsOneWidget);
expect(find.byKey(const Key('player-next')), findsOneWidget);
expect(find.byType(Slider), findsOneWidget);
expect(find.byKey(const Key('rail-like')), findsNothing);
expect(find.byKey(const Key('rail-save')), findsNothing);
expect(find.byKey(const Key('player-interaction-rail')), findsOneWidget);
expect(find.byKey(const Key('player-rail-like')), findsOneWidget);
expect(find.byKey(const Key('player-rail-save')), findsOneWidget);
expect(find.byKey(const Key('player-rail-share')), findsOneWidget);
}
Future<void> _openSeriesPlayer(WidgetTester tester) async {
Future<void> _openSeriesPlayer(
WidgetTester tester, {
Key cardKey = const Key('home-drama-card-city-lights-demo'),
}) async {
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
final card = find.byKey(const Key('home-drama-card-city-lights-demo'));
final card = find.byKey(cardKey);
await tester.scrollUntilVisible(
card,
220,
@@ -329,20 +447,22 @@ Future<void> _openSeriesPlayer(WidgetTester tester) async {
Future<void> _pumpApp(
WidgetTester tester, {
Size size = const Size(390, 844),
FakeCatalogRepository? catalog,
FakePlaybackRepository? playback,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final catalog = FakeCatalogRepository();
final repository = catalog ?? FakeCatalogRepository();
await tester.pumpWidget(
LumaDramaApp(
playerFactory: createWidgetPlayer,
catalogRepository: catalog,
categoryRepository: FakeCategoryRepository(catalog: catalog),
catalogRepository: repository,
categoryRepository: FakeCategoryRepository(catalog: repository),
watchHistoryRepository: InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
playbackRepository: FakePlaybackRepository(),
favoriteRepository: InMemoryFavoriteRepository(cards: repository.dramas),
playbackRepository: playback ?? FakePlaybackRepository(),
commentRepository: FakeCommentRepository(),
interactionRepository: FakeInteractionRepository(),
noticeRepository: FakeNoticeRepository(),
@@ -351,3 +471,29 @@ Future<void> _pumpApp(
);
await tester.pumpAndSettle();
}
const _lockedDrama = Drama(
id: 'locked-demo',
title: 'Locked Demo',
synopsis: 'Locked demo synopsis',
posterUrl: '/files/locked-demo.png',
genre: 'Suspense',
detailLoaded: true,
episodes: [
Episode(
id: 'locked-demo-1',
number: 1,
title: 'Locked Episode',
isFree: false,
locked: true,
videoUrl: 'https://example.test/locked-demo-1.mp4',
),
Episode(
id: 'locked-demo-2',
number: 2,
title: 'Open Episode',
isFree: true,
videoUrl: 'https://example.test/locked-demo-2.mp4',
),
],
);
+11 -15
View File
@@ -226,7 +226,7 @@ void main() {
await tester.pumpAndSettle();
await _openTheaterPlayer(tester);
await tester.tap(find.byKey(const Key('player-comments')));
await tester.tap(find.byKey(const Key('player-rail-comments')));
await tester.pumpAndSettle();
expect(find.text('No comments yet.'), findsOneWidget);
await tester.enterText(find.byKey(const Key('comment-input')), 'Nice demo');
@@ -236,11 +236,14 @@ void main() {
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await _tapPlayerMore(tester, const Key('player-more-like'));
await tester.tap(find.byKey(const Key('player-rail-like')));
await tester.pumpAndSettle();
expect(interactions.likeTargets, contains('DRAMA:city-lights-demo'));
await _tapPlayerMore(tester, const Key('player-more-favorite'));
await _tapPlayerMore(tester, const Key('player-more-share'));
await tester.tap(find.byKey(const Key('player-rail-save')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('player-rail-share')));
await tester.pumpAndSettle();
expect(sharedText, contains('City Lights & Velvet Nights'));
expect(sharedText, contains('FruitShorts'));
expect(tester.takeException(), isNull);
@@ -256,7 +259,8 @@ void main() {
await tester.pumpWidget(appUnderTest(interactionRepository: interactions));
await tester.pumpAndSettle();
await _openTheaterPlayer(tester);
await _tapPlayerMore(tester, const Key('player-more-like'));
await tester.tap(find.byKey(const Key('player-rail-like')));
await tester.pumpAndSettle();
expect(find.text('Sign in to continue'), findsOneWidget);
expect(interactions.likeTargets, isEmpty);
@@ -271,7 +275,8 @@ void main() {
await tester.pumpWidget(appUnderTest());
await tester.pumpAndSettle();
await _openTheaterPlayer(tester);
await _tapPlayerMore(tester, const Key('player-more-favorite'));
await tester.tap(find.byKey(const Key('player-rail-save')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('player-back')));
await tester.pumpAndSettle();
@@ -303,12 +308,3 @@ Future<void> _openTheaterPlayer(WidgetTester tester) async {
await tester.tap(card);
await tester.pumpAndSettle();
}
Future<void> _tapPlayerMore(WidgetTester tester, Key action) async {
await tester.tap(find.byKey(const Key('player-more')));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(action));
await tester.pumpAndSettle();
await tester.tap(find.byKey(action));
await tester.pumpAndSettle();
}