// Author: fruit.com.cn import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:fruitshorts/core/theme/app_colors.dart'; import 'package:fruitshorts/core/theme/app_dimens.dart'; import 'package:fruitshorts/core/widgets/app_bottom_nav.dart'; void main() { testWidgets('should_render_four_slots_with_orange_selected_state', ( tester, ) async { var theaterTaps = 0; await tester.pumpWidget( MaterialApp( home: Scaffold( bottomNavigationBar: AppBottomNav( items: [ AppBottomNavItem( tabKey: const Key('tab-home'), icon: Icons.movie_outlined, selectedIcon: Icons.movie_rounded, label: 'Home', selected: true, onTap: () {}, ), AppBottomNavItem( tabKey: const Key('tab-theater'), icon: Icons.explore_outlined, selectedIcon: Icons.explore_rounded, label: 'Theater', onTap: () => theaterTaps++, ), AppBottomNavItem( tabKey: const Key('tab-create'), icon: Icons.add_box_outlined, selectedIcon: Icons.add_box_rounded, label: 'Create', onTap: () {}, ), AppBottomNavItem( tabKey: const Key('tab-mine'), icon: Icons.person_outline_rounded, selectedIcon: Icons.person_rounded, label: 'Me', onTap: () {}, ), ], ), ), ), ); expect(find.byKey(const Key('tab-home')), findsOneWidget); expect(find.byKey(const Key('tab-theater')), findsOneWidget); expect(find.byKey(const Key('tab-create')), findsOneWidget); expect(find.byKey(const Key('tab-mine')), findsOneWidget); expect(find.byKey(const Key('nav-center-action')), findsNothing); expect(find.text('Home'), findsOneWidget); final centers = [ Key('tab-home'), Key('tab-theater'), Key('tab-create'), Key('tab-mine'), ].map((key) => tester.getCenter(find.byKey(key)).dx).toList(); expect(centers, orderedEquals(centers.toList()..sort())); expect( tester.getSize(find.byType(AppBottomNav)).height, AppDimens.navHeight, ); expect( tester .widget( find.descendant( of: find.byKey(const Key('tab-home')), matching: find.byIcon(Icons.movie_rounded), ), ) .color, AppColors.blue, ); await tester.tap(find.byKey(const Key('tab-theater'))); expect(theaterTaps, 1); }); testWidgets('should_fill_dark_bottom_safe_area_with_black_background', ( tester, ) async { const barKey = Key('dark-nav-bar'); await tester.pumpWidget( MaterialApp( home: MediaQuery( data: const MediaQueryData(padding: EdgeInsets.only(bottom: 34)), child: Scaffold( bottomNavigationBar: AppBottomNav( dark: true, barKey: barKey, items: [ AppBottomNavItem( tabKey: const Key('tab-home'), icon: Icons.movie_outlined, selectedIcon: Icons.movie_rounded, label: 'Home', selected: true, onTap: () {}, ), AppBottomNavItem( tabKey: const Key('tab-theater'), icon: Icons.explore_outlined, selectedIcon: Icons.explore_rounded, label: 'Theater', onTap: () {}, ), AppBottomNavItem( tabKey: const Key('tab-create'), icon: Icons.add_box_outlined, selectedIcon: Icons.add_box_rounded, label: 'Create', onTap: () {}, ), AppBottomNavItem( tabKey: const Key('tab-mine'), icon: Icons.person_outline_rounded, selectedIcon: Icons.person_rounded, label: 'Me', onTap: () {}, ), ], ), ), ), ), ); expect( tester.getSize(find.byType(AppBottomNav)).height, AppDimens.navHeight + 34, ); expect(tester.getSize(find.byKey(barKey)).height, AppDimens.navHeight); final coloredBox = tester.widget( find.descendant( of: find.byType(AppBottomNav), matching: find.byType(ColoredBox), ), ); expect(coloredBox.color, Colors.black); }); }