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_theme.dart'; import 'package:fruitshorts/core/widgets/empty_state.dart'; void main() { testWidgets('should_render_title_subtitle_action_and_title_only_semantics', ( tester, ) async { var taps = 0; await _pump( tester, theme: AppTheme.dark(), child: EmptyState( icon: Icons.movie_outlined, title: 'No stories', subtitle: 'New content will appear here.', actionLabel: 'Retry', onAction: () => taps++, ), ); expect(find.byKey(const Key('empty-state-art')), findsOneWidget); expect(find.byKey(const Key('empty-state-art-inner')), findsOneWidget); expect(find.byKey(const Key('empty-state-icon')), findsOneWidget); expect(find.text('No stories'), findsOneWidget); expect(find.text('New content will appear here.'), findsOneWidget); expect( tester.getSize(find.byKey(const Key('empty-state-art'))), const Size(84, 84), ); expect( tester.getSize(find.byKey(const Key('empty-state-art-inner'))), const Size(56, 56), ); expect( tester.getSize(find.byKey(const Key('empty-state-icon'))), const Size(27, 27), ); final outer = tester.widget( find.byKey(const Key('empty-state-art')), ); final outerDecoration = outer.decoration! as BoxDecoration; expect(outerDecoration.shape, BoxShape.circle); expect(outerDecoration.color?.a, closeTo(0.055, 0.001)); expect(outerDecoration.border!.top.color.a, closeTo(0.11, 0.001)); final inner = tester.widget( find.byKey(const Key('empty-state-art-inner')), ); expect((inner.decoration! as BoxDecoration).color?.a, closeTo(0.11, 0.001)); expect( tester .widget(find.byKey(const Key('empty-state-padding'))) .padding, const EdgeInsets.symmetric(horizontal: 24, vertical: 28), ); expect( tester .widget(find.byKey(const Key('empty-state-title'))) .style ?.fontSize, 15, ); final subtitle = tester.widget( find.text('New content will appear here.'), ); expect(subtitle.style?.fontSize, 12.5); expect(tester.widget(find.text('Retry')).style?.fontSize, 13); expect( tester.getSize(find.byKey(const Key('empty-state-action'))).height, greaterThanOrEqualTo(44), ); final semantics = tester.ensureSemantics(); expect(find.bySemanticsLabel('No stories'), findsOneWidget); expect( find.bySemanticsLabel('New content will appear here.'), findsNothing, ); await tester.tap(find.byKey(const Key('empty-state-action'))); expect(taps, 1); semantics.dispose(); }); testWidgets('should_render_compact_dimensions_for_embedded_empty_state', ( tester, ) async { await _pump( tester, child: const EmptyState( icon: Icons.chat_bubble_outline_rounded, title: 'No comments yet.', compact: true, ), ); expect( tester.getSize(find.byKey(const Key('empty-state-art'))), const Size(60, 60), ); expect( tester.getSize(find.byKey(const Key('empty-state-art-inner'))), const Size(40, 40), ); expect( tester.getSize(find.byKey(const Key('empty-state-icon'))), const Size(21, 21), ); expect( tester .widget(find.byKey(const Key('empty-state-title'))) .style ?.fontSize, 15, ); expect( tester .widget(find.byKey(const Key('empty-state-padding'))) .padding, const EdgeInsets.symmetric(horizontal: 16, vertical: 16), ); expect(find.byKey(const Key('empty-state-action')), findsNothing); }); testWidgets('should_use_theme_aware_icon_colors', (tester) async { await _pump( tester, theme: AppTheme.dark(), child: const EmptyState(icon: Icons.history_rounded, title: 'No history'), ); expect( tester.widget(find.byKey(const Key('empty-state-icon'))).color, AppColors.blueSoft, ); await _pump( tester, theme: AppTheme.light(), child: const EmptyState(icon: Icons.history_rounded, title: 'No history'), ); expect( tester.widget(find.byKey(const Key('empty-state-icon'))).color, AppColors.blue, ); }); testWidgets('should_fit_compact_width_without_overflow', (tester) async { tester.view.physicalSize = const Size(320, 568); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); await _pump( tester, child: const EmptyState( icon: Icons.download_outlined, title: 'No download authorizations yet.', subtitle: 'New content will appear here.', actionLabel: 'Retry', ), ); final content = tester.widget( find.byKey(const Key('empty-state-content')), ); expect(content.constraints.maxWidth, 260); expect(tester.takeException(), isNull); }); } Future _pump( WidgetTester tester, { ThemeData? theme, required Widget child, }) async { await tester.pumpWidget( MaterialApp( theme: theme ?? AppTheme.dark(), home: Scaffold(body: child), ), ); await tester.pumpAndSettle(); }