flutter-ci / test (push) Failing after 30m39s
Drama 新增 tagCode,推荐页只看 NEW_ARRIVAL 这个码决定上新横滑, 不再依赖可变的标签文案;分类网格高度改为复用卡片的统一常量。 头部轮播改用虚拟无限页码,首尾相接且能反向滑,自动播放不再倒滑回第一张。
84 lines
2.7 KiB
Dart
84 lines
2.7 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.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';
|
|
import 'package:fruitshorts/pages/recommend/widgets/home_hero_carousel.dart';
|
|
|
|
const List<FeedBanner> _banners = [
|
|
FeedBanner(id: '1', imageUrl: 'https://cdn.test/a.png'),
|
|
FeedBanner(id: '2', imageUrl: 'https://cdn.test/b.png'),
|
|
];
|
|
|
|
Widget _harness(List<FeedBanner> banners) {
|
|
return MaterialApp(
|
|
locale: const Locale('en'),
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
home: Scaffold(
|
|
body: HomeHeroCarousel(
|
|
banners: banners,
|
|
dramaFor: (_) => null,
|
|
onWatch: (_) {},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Color? _dotColor(WidgetTester tester, int index) {
|
|
final decoration =
|
|
tester
|
|
.widget<Container>(find.byKey(Key('home-hero-dot-$index')))
|
|
.decoration
|
|
as BoxDecoration?;
|
|
return decoration?.color;
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('should_keep_looping_backwards_from_the_first_banner', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_harness(_banners));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(_dotColor(tester, 0), AppColors.brandRed);
|
|
|
|
// 从第一张往右滑:无缝轮播应该接到最后一张,而不是被边界挡住。
|
|
await tester.fling(find.byType(PageView), const Offset(700, 0), 1200);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(_dotColor(tester, 1), AppColors.brandRed);
|
|
expect(_dotColor(tester, 0), isNot(AppColors.brandRed));
|
|
});
|
|
|
|
testWidgets('should_wrap_to_first_banner_after_last_auto_advance', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_harness(_banners));
|
|
await tester.pumpAndSettle();
|
|
|
|
// 自动播两次:第 2 张之后应回到第 1 张,且页码继续往前走不回头。
|
|
await tester.pump(const Duration(milliseconds: 4600));
|
|
await tester.pumpAndSettle();
|
|
expect(_dotColor(tester, 1), AppColors.brandRed);
|
|
|
|
await tester.pump(const Duration(milliseconds: 4600));
|
|
await tester.pumpAndSettle();
|
|
expect(_dotColor(tester, 0), AppColors.brandRed);
|
|
});
|
|
|
|
testWidgets('should_not_loop_when_only_one_banner', (tester) async {
|
|
await tester.pumpWidget(
|
|
_harness(const [FeedBanner(id: '1', imageUrl: 'https://cdn.test/a.png')]),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('home-hero-dot-0')), findsNothing);
|
|
await tester.pump(const Duration(milliseconds: 6000));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|