// 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_five_slots_with_center_action', (tester) async { var centerTaps = 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: () {}, ), 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: () {}, ), ], centerAction: AppBottomNavCenterAction( label: 'Create', onTap: () => centerTaps++, ), ), ), ), ); expect(find.byKey(const Key('tab-home')), findsOneWidget); expect(find.byKey(const Key('tab-theater')), findsOneWidget); expect(find.byKey(const Key('nav-center-action')), findsOneWidget); expect(find.byKey(const Key('tab-create')), findsOneWidget); expect(find.byKey(const Key('tab-mine')), findsOneWidget); expect(find.text('Home'), findsOneWidget); final centers = [ Key('tab-home'), Key('tab-theater'), Key('nav-center-action'), 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.getSize(find.byKey(const Key('nav-center-action'))), const Size.square(AppDimens.navCenter), ); final ink = tester.widget( find .ancestor( of: find.byKey(const Key('nav-center-action')), matching: find.byType(Ink), ) .first, ); final decoration = ink.decoration! as BoxDecoration; expect(decoration.shape, BoxShape.circle); expect((decoration.gradient! as LinearGradient).colors, const [ AppColors.navCenterStart, AppColors.navCenterEnd, ]); await tester.tap(find.byKey(const Key('nav-center-action'))); expect(centerTaps, 1); }); }