Files
ReelShort/test/home/home_feed_header_test.dart
T

55 lines
1.8 KiB
Dart

// Author: fruit.com.cn
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/theme/app_theme.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
import 'package:fruitshorts/pages/home/home_feed_channel.dart';
import 'package:fruitshorts/pages/player/widgets/home_feed_header.dart';
void main() {
testWidgets('should_emit_channel_callbacks_and_render_selected_channel', (
tester,
) async {
final selected = <HomeFeedChannel>[];
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
locale: const Locale('en'),
supportedLocales: AppLocalizations.supportedLocales,
localizationsDelegates: AppLocalizations.localizationsDelegates,
home: Builder(
builder: (context) => Scaffold(
body: HomeFeedHeader(
l10n: AppLocalizations.of(context)!,
channel: HomeFeedChannel.anime,
onChannelSelected: selected.add,
onRefresh: () async => true,
onSearch: () {},
onMore: () {},
),
),
),
),
);
expect(find.byKey(const Key('home-feed-tab-anime')), findsOneWidget);
expect(find.byKey(const Key('home-feed-tab-real')), findsOneWidget);
expect(find.byKey(const Key('home-feed-tab-recommend')), findsOneWidget);
expect(
tester.widget<Text>(find.text('Anime')).style?.fontWeight,
FontWeight.w800,
);
await tester.tap(find.byKey(const Key('home-feed-tab-real')));
await tester.tap(find.byKey(const Key('home-feed-tab-recommend')));
await tester.tap(find.byKey(const Key('home-feed-tab-anime')));
expect(selected, [
HomeFeedChannel.live,
HomeFeedChannel.recommend,
HomeFeedChannel.anime,
]);
});
}