feat(flutter): 首页频道叠加轮播并改下划线选中
This commit is contained in:
1 parent
36c71e63b4
commit
a24f1fa7c0
3 files changed
+176
-65
No files matched your search
@@ -8,7 +8,6 @@ import 'package:fruitshorts/core/data/models/watch_progress.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';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/pages/player/player_view.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
@@ -49,27 +48,55 @@ void main() {
|
||||
expect(find.text('Coming soon'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_switch_home_channel_when_chip_is_tapped', (tester) async {
|
||||
testWidgets('should_switch_home_channel_when_underline_tab_is_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
|
||||
expect(_chip(tester, 'home-channel-hot').selected, isTrue);
|
||||
expect(_chip(tester, 'home-channel-free').selected, isFalse);
|
||||
expect(_chip(tester, 'home-channel-hot').selectedColor, AppColors.blue);
|
||||
expect(_chip(tester, 'home-channel-free').backgroundColor, AppColors.card);
|
||||
expect(
|
||||
_chip(tester, 'home-channel-free').labelStyle?.color,
|
||||
AppColors.onSurface,
|
||||
);
|
||||
// 悬浮在轮播图上:选中白色下划线,未选中透明占位。
|
||||
expect(_underlineColor(tester, 'hot'), Colors.white);
|
||||
expect(_underlineColor(tester, 'free'), Colors.transparent);
|
||||
expect(_labelStyle(tester, 'hot').fontWeight, FontWeight.w800);
|
||||
expect(_labelStyle(tester, 'free').fontWeight, FontWeight.w600);
|
||||
expect(_labelStyle(tester, 'hot').color, Colors.white);
|
||||
expect(_labelStyle(tester, 'free').color, Colors.white70);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-channel-free')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_chip(tester, 'home-channel-hot').selected, isFalse);
|
||||
expect(_chip(tester, 'home-channel-free').selected, isTrue);
|
||||
expect(
|
||||
_chip(tester, 'home-channel-free').labelStyle?.color,
|
||||
AppColors.onPrimary,
|
||||
expect(_underlineColor(tester, 'hot'), Colors.transparent);
|
||||
expect(_underlineColor(tester, 'free'), Colors.white);
|
||||
expect(_labelStyle(tester, 'free').fontWeight, FontWeight.w800);
|
||||
});
|
||||
|
||||
testWidgets('should_render_flush_hero_with_channels_overlaid', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
|
||||
final hero = tester.getRect(find.byKey(const Key('home-hero-banner')));
|
||||
expect(hero.width, 390);
|
||||
expect(hero.left, 0);
|
||||
final card = tester.widget<ClipRRect>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-hero-banner')),
|
||||
matching: find.byType(ClipRRect),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(card.borderRadius, BorderRadius.zero);
|
||||
|
||||
// 频道行在 hero Stack 内、位于轮播顶部 8 的位置上。
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byKey(const Key('home-channels')),
|
||||
matching: find.byKey(const Key('home-hero-section')),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final channels = tester.getRect(find.byKey(const Key('home-channels')));
|
||||
expect(channels.top, closeTo(hero.top + 8, 1));
|
||||
});
|
||||
|
||||
testWidgets('should_open_theater_search_when_home_search_is_tapped', (
|
||||
@@ -209,8 +236,22 @@ const _tabKeys = [
|
||||
Key('tab-mine'),
|
||||
];
|
||||
|
||||
ChoiceChip _chip(WidgetTester tester, String key) =>
|
||||
tester.widget<ChoiceChip>(find.byKey(Key(key)));
|
||||
Color? _underlineColor(WidgetTester tester, String name) {
|
||||
final underline = tester.widget<Container>(
|
||||
find.byKey(Key('home-channel-underline-$name')),
|
||||
);
|
||||
return (underline.decoration! as BoxDecoration).color;
|
||||
}
|
||||
|
||||
TextStyle _labelStyle(WidgetTester tester, String name) {
|
||||
final label = tester.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(Key('home-channel-$name')),
|
||||
matching: find.byType(Text),
|
||||
),
|
||||
);
|
||||
return label.style!;
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(
|
||||
WidgetTester tester, {
|
||||
|
||||
Reference in new issue
Block a user