feat(flutter): 榜单页三强横排与第四名起列表

This commit is contained in:
Zhou Weidong committed 2026-10-20 15:08:43 +08:00
1 parent ffedde0db5
commit 881088a428
2 files changed
+247 -35

No files matched your search

+64 -8
View File
@@ -3,6 +3,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/app.dart';
import 'package:fruitshorts/core/data/models/drama.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';
@@ -31,14 +32,11 @@ void main() {
expect(find.byKey(const Key('ranking-page')), findsOneWidget);
expect(find.text('TOP 1'), findsOneWidget);
expect(
find.descendant(
of: find.byKey(const Key('ranking-row-0')),
matching: find.text('The Signal'),
),
findsOneWidget,
tester.widget<Text>(find.byKey(const Key('ranking-title-1'))).data,
'The Signal',
);
await tester.tap(find.byKey(const Key('ranking-row-0')));
await tester.tap(find.byKey(const Key('ranking-top-1')));
await tester.pumpAndSettle();
expect(find.byType(DramaDetailPage), findsOneWidget);
});
@@ -71,6 +69,44 @@ void main() {
);
});
testWidgets('should_render_podium_with_center_on_top', (tester) async {
await _pumpTheater(tester);
await tester.tap(find.byKey(const Key('theater-toolbar-ranking')));
await tester.pumpAndSettle();
final top1 = tester.getRect(find.byKey(const Key('ranking-cover-1')));
final top2 = tester.getRect(find.byKey(const Key('ranking-cover-2')));
final top3 = tester.getRect(find.byKey(const Key('ranking-cover-3')));
expect(top1.size, const Size(120, 160));
expect(top2.size, const Size(92, 124));
expect(top3.size, const Size(92, 124));
expect(top2.left, lessThan(top1.left));
expect(top3.left, greaterThan(top1.right));
expect(top1.bottom, closeTo(top2.bottom, 0.5));
expect(top1.bottom, closeTo(top3.bottom, 0.5));
expect(find.byKey(const Key('ranking-row-3')), findsNothing);
});
testWidgets('should_list_rank_four_and_below', (tester) async {
await _pumpTheater(tester, dramas: _rankDramas(5));
await tester.tap(find.byKey(const Key('theater-toolbar-ranking')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('ranking-row-3')), findsOneWidget);
expect(find.byKey(const Key('ranking-row-2')), findsNothing);
expect(find.byKey(const Key('ranking-top-4')), findsOneWidget);
});
testWidgets('should_truncate_podium_when_less_than_three', (tester) async {
await _pumpTheater(tester, dramas: _rankDramas(1));
await tester.tap(find.byKey(const Key('theater-toolbar-ranking')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('ranking-top-1')), findsOneWidget);
expect(find.byKey(const Key('ranking-top-2')), findsNothing);
expect(find.byKey(const Key('ranking-top-3')), findsNothing);
});
testWidgets('should_go_back_to_theater_from_ranking_page', (tester) async {
await _pumpTheater(tester);
await tester.tap(find.byKey(const Key('theater-toolbar-ranking')));
@@ -84,12 +120,12 @@ void main() {
});
}
Future<void> _pumpTheater(WidgetTester tester) async {
Future<void> _pumpTheater(WidgetTester tester, {List<Drama>? dramas}) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final catalog = FakeCatalogRepository();
final catalog = FakeCatalogRepository(dramas: dramas);
await tester.pumpWidget(
LumaDramaApp(
playerFactory: createWidgetPlayer,
@@ -108,3 +144,23 @@ Future<void> _pumpTheater(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('tab-theater')));
await tester.pumpAndSettle();
}
List<Drama> _rankDramas(int count) => [
for (var index = 0; index < count; index++)
Drama(
id: 'rank-$index',
title: 'Rank $index',
synopsis: 'synopsis',
posterUrl: '',
totalEpisodes: 10,
viewCount: (count - index) * 100,
episodes: [
Episode(
id: 'rank-$index-1',
number: 1,
title: 'Episode 1',
isFree: true,
),
],
),
];