feat(recommend): 轮播只保留标题简介并重做顶部导航

This commit is contained in:
Vicky authored and trae-solo-agent committed 2026-10-30 17:14:34 +08:00
1 parent 53e8c924a6
commit 9ef8eb15b0
6 files changed
+180 -205

No files matched your search

+36 -2
View File
@@ -2,6 +2,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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/l10n/app_localizations.dart';
@@ -12,7 +13,14 @@ const List<FeedBanner> _banners = [
FeedBanner(id: '2', imageUrl: 'https://cdn.test/b.png'),
];
Widget _harness(List<FeedBanner> banners) {
const Drama _drama = Drama(
id: 'd1',
title: 'City Lights',
synopsis: 'A quiet city romance.',
posterUrl: 'https://cdn.test/d.png',
);
Widget _harness(List<FeedBanner> banners, {Drama? drama}) {
return MaterialApp(
locale: const Locale('en'),
supportedLocales: AppLocalizations.supportedLocales,
@@ -20,7 +28,7 @@ Widget _harness(List<FeedBanner> banners) {
home: Scaffold(
body: HomeHeroCarousel(
banners: banners,
dramaFor: (_) => null,
dramaFor: (_) => drama,
onWatch: (_) {},
),
),
@@ -69,6 +77,32 @@ void main() {
expect(_dotColor(tester, 0), AppColors.brandRed);
});
testWidgets('should_keep_only_title_and_synopsis_above_dots', (tester) async {
await tester.pumpWidget(_harness(_banners, drama: _drama));
await tester.pumpAndSettle();
final copy = find.byKey(const Key('home-hero-copy-0'));
expect(copy, findsOneWidget);
expect(
find.descendant(of: copy, matching: find.text('City Lights')),
findsOneWidget,
);
expect(
find.descendant(
of: copy,
matching: find.text('A quiet city romance.'),
),
findsOneWidget,
);
expect(find.byKey(const Key('home-hero-watch')), findsNothing);
expect(find.byKey(const Key('home-hero-favorite')), findsNothing);
// 文案块整体位于轮播点上方,给进度点留出间距。
final copyRect = tester.getRect(copy);
final dotRect = tester.getRect(find.byKey(const Key('home-hero-dot-0')));
expect(copyRect.bottom, lessThanOrEqualTo(dotRect.top));
});
testWidgets('should_not_loop_when_only_one_banner', (tester) async {
await tester.pumpWidget(
_harness(const [FeedBanner(id: '1', imageUrl: 'https://cdn.test/a.png')]),
@@ -60,7 +60,7 @@ void main() {
expect(fixture.controller.refreshCalls, 2);
});
testWidgets('should_auto_retry_three_times_then_show_network_error', (
testWidgets('should_allow_manual_retry_after_auto_retries_are_exhausted', (
tester,
) async {
final fixture = await _pumpFailingRecommend(tester);
@@ -89,7 +89,14 @@ void main() {
expect(find.byKey(const Key('recommend-feed-skeleton')), findsNothing);
expect(find.byKey(const Key('recommend-feed-empty')), findsOneWidget);
expect(find.text(l10n.networkError), findsOneWidget);
expect(find.text(l10n.retry), findsNothing);
expect(find.text(l10n.retry), findsOneWidget);
await tester.tap(find.byKey(const Key('recommend-feed-retry')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 1));
expect(fixture.controller.refreshCalls, 5);
expect(find.byKey(const Key('recommend-feed-skeleton')), findsOneWidget);
});
testWidgets('should_cancel_pending_auto_retry_when_disposed', (tester) async {
@@ -0,0 +1,48 @@
// Author: fruit.com.cn
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/theme/app_dimens.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
import 'package:fruitshorts/pages/recommend/recommend_types.dart';
import 'package:fruitshorts/pages/recommend/widgets/recommend_top_nav.dart';
void main() {
testWidgets('should_keep_large_text_and_actions_inside_narrow_top_nav', (
tester,
) async {
tester.view.physicalSize = const Size(320, 640);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
locale: const Locale('id'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: MediaQuery(
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
child: Scaffold(
body: RecommendTopNav(
selected: RecommendInnerTab.feed,
onSelected: (_) {},
onSearch: () {},
onGift: () {},
),
),
),
),
);
expect(tester.takeException(), isNull);
expect(
tester.getSize(find.byKey(const Key('recommend-search'))),
const Size.square(AppDimens.tapTarget),
);
expect(
tester.getSize(find.byKey(const Key('recommend-gift'))),
const Size.square(AppDimens.tapTarget),
);
});
}