feat(ranking): 榜单改为统一行布局

This commit is contained in:
Zhou Weidong committed 2026-11-02 14:44:32 +08:00
1 parent 7f65fe4d48
commit 8c1662475a
16 files changed
+927 -390

No files matched your search

+83 -35
View File
@@ -6,7 +6,9 @@ import 'package:fruitshorts/app.dart';
import 'package:fruitshorts/core/data/models/drama.dart';
import 'package:fruitshorts/core/data/models/home_feed.dart';
import 'package:fruitshorts/core/theme/app_colors.dart';
import 'package:fruitshorts/core/theme/app_dimens.dart';
import 'package:fruitshorts/core/widgets/app_pull_to_refresh.dart';
import 'package:fruitshorts/core/widgets/paged_local_list.dart';
import 'package:fruitshorts/pages/discover/discover_view.dart';
import 'package:fruitshorts/pages/discover/widgets/drama_grid.dart';
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
@@ -34,7 +36,17 @@ void main() {
expect(find.byKey(const Key('ranking-page')), findsOneWidget);
_expectUnifiedHeader(tester, const Key('ranking-back'));
expect(find.text('TOP 1'), findsOneWidget);
expect(
tester
.widget<Text>(
find.descendant(
of: find.byKey(const Key('ranking-top-1')),
matching: find.byType(Text),
),
)
.data,
'1',
);
expect(
tester.widget<Text>(find.byKey(const Key('ranking-title-1'))).data,
'The Signal',
@@ -105,51 +117,72 @@ void main() {
expect(find.byKey(const Key('new-releases-page')), findsOneWidget);
});
testWidgets('should_render_podium_with_center_on_top', (tester) async {
testWidgets('should_render_uniform_rows_with_cover_badges', (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.width, greaterThan(top2.width));
expect(top3.width, closeTo(top2.width, 0.5));
expect(top2.left, closeTo(8, 0.5));
expect(top3.right, closeTo(382, 0.5));
expect(top1.left - top2.right, lessThanOrEqualTo(10));
expect(top2.width, greaterThan(100));
expect(top2.left, lessThan(top1.left));
expect(top3.left, greaterThan(top1.right));
expect(top1.bottom, closeTo(top2.bottom - 30, 0.5));
expect(top2.bottom, closeTo(top3.bottom, 0.5));
expect(find.byKey(const Key('ranking-row-3')), findsNothing);
for (var rank = 1; rank <= 3; rank++) {
expect(find.byKey(Key('ranking-row-${rank - 1}')), findsOneWidget);
expect(
tester.getSize(find.byKey(Key('ranking-row-cover-$rank'))),
const Size(96, 128),
);
final badge = tester.widget<Container>(
find.byKey(Key('ranking-top-$rank')),
);
final decoration = badge.decoration! as BoxDecoration;
final expected = switch (rank) {
1 => AppColors.brandRed,
2 => AppColors.homeCrownGold,
_ => AppColors.bronze,
};
expect(decoration.color, expected);
}
});
testWidgets('should_list_rank_four_and_below', (tester) async {
testWidgets('should_list_every_rank_as_row', (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);
for (var index = 0; index < 5; index++) {
expect(find.byKey(Key('ranking-row-$index')), findsOneWidget);
}
final rankNumber = tester.widget<Text>(
find.byKey(const Key('ranking-top-4')),
find.descendant(
of: find.byKey(const Key('ranking-top-4')),
matching: find.byType(Text),
),
);
expect(rankNumber.data, '4');
expect(rankNumber.style?.fontSize, 48);
expect(rankNumber.style?.fontWeight, FontWeight.w800);
expect(rankNumber.style?.fontSize, 14);
expect(rankNumber.style?.fontWeight, FontWeight.w700);
final badge = tester.widget<Container>(
find.byKey(const Key('ranking-top-4')),
);
expect(
tester.getSize(find.byKey(const Key('ranking-top-4'))),
const Size(24, 24),
);
expect(
(badge.decoration! as BoxDecoration).borderRadius,
const BorderRadius.only(
topLeft: Radius.circular(AppDimens.rankingCoverRadius),
bottomRight: Radius.circular(10),
),
);
expect(
tester.getSize(find.byKey(const Key('ranking-row-3'))),
const Size(362, 96),
const Size(362, 128),
);
expect(
tester.getSize(find.byKey(const Key('ranking-row-cover-4'))),
const Size(60, 80),
const Size(96, 128),
);
});
testWidgets('should_truncate_podium_when_less_than_three', (tester) async {
testWidgets('should_render_single_row_when_only_one_drama', (tester) async {
await _pumpTheater(tester, dramas: _rankDramas(1));
await tester.tap(find.byKey(const Key('theater-toolbar-ranking')));
await tester.pumpAndSettle();
@@ -194,14 +227,18 @@ void main() {
final list = find.byKey(const Key('ranking-list'));
expect(tester.widget<ListView>(list).physics, AppPullToRefresh.physics);
final position = _scrollPosition(tester, const Key('ranking-list'));
// jumpTo 不发滚动通知,滑到底后再拖一下才会触发加载。
position.jumpTo(position.maxScrollExtent);
await tester.pump();
await tester.drag(list, const Offset(0, -60));
await tester.pump();
expect(find.byKey(const Key('ranking-row-19')), findsOneWidget);
expect(find.byKey(const Key('ranking-row-20')), findsNothing);
expect(find.byKey(const Key('ranking-load-more')), findsOneWidget);
// 加载指示出现后会撑高列表,可视区外被 finder 视为 offstage,直接看状态。
expect(_loadFooter(tester).loading, isTrue);
await tester.pump(const Duration(milliseconds: 299));
expect(find.byKey(const Key('ranking-load-more')), findsOneWidget);
expect(_loadFooter(tester).loading, isTrue);
await tester.pump(const Duration(milliseconds: 1));
position.jumpTo(position.maxScrollExtent);
@@ -219,11 +256,14 @@ void main() {
expect(repository.fetchCalls, beforeRefresh + 1);
expect(position.pixels, 0);
position.jumpTo(position.maxScrollExtent);
await tester.pump();
expect(find.byKey(const Key('ranking-load-more')), findsOneWidget);
expect(find.byKey(const Key('ranking-no-more')), findsNothing);
// 刷新重置回 20 项后,滑到底再触发一次加载,应恢复 40 项。
final refreshed = _scrollPosition(tester, const Key('ranking-list'));
refreshed.jumpTo(refreshed.maxScrollExtent);
await tester.pumpAndSettle();
refreshed.jumpTo(refreshed.maxScrollExtent);
await tester.pumpAndSettle();
expect(find.byKey(const Key('ranking-row-39')), findsOneWidget);
expect(find.byKey(const Key('ranking-no-more')), findsNothing);
});
testWidgets('should_page_new_releases_and_reset_after_refresh', (
@@ -311,10 +351,9 @@ Future<void> _pumpTheater(
),
);
await tester.pumpAndSettle();
Navigator.of(tester.element(find.byKey(const Key('home-tabs'))))
.push<void>(
MaterialPageRoute(builder: (_) => const DiscoverPage()),
);
Navigator.of(
tester.element(find.byKey(const Key('home-tabs'))),
).push<void>(MaterialPageRoute(builder: (_) => const DiscoverPage()));
await tester.pumpAndSettle();
}
@@ -326,6 +365,15 @@ ScrollPosition _scrollPosition(WidgetTester tester, Key listKey) {
return tester.state<ScrollableState>(scrollable.first).position;
}
PagedLoadFooter _loadFooter(WidgetTester tester) {
return tester.widget<PagedLoadFooter>(
find.descendant(
of: find.byKey(const Key('ranking-page'), skipOffstage: false),
matching: find.byType(PagedLoadFooter, skipOffstage: false),
),
);
}
class _CountingCatalogRepository extends FakeCatalogRepository {
_CountingCatalogRepository({super.dramas});