Files
ReelShort/test/empty_state/empty_state_test.dart

164 lines
4.6 KiB
Dart

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.light(),
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')), findsNothing);
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-icon'))),
const Size(72, 72),
);
expect(
tester.widget<Icon>(find.byKey(const Key('empty-state-icon'))).color,
AppColors.subtle,
);
expect(
tester
.widget<Padding>(find.byKey(const Key('empty-state-padding')))
.padding,
const EdgeInsets.symmetric(horizontal: 24, vertical: 28),
);
expect(
tester
.widget<Text>(find.byKey(const Key('empty-state-title')))
.style
?.fontSize,
15,
);
final subtitle = tester.widget<Text>(
find.text('New content will appear here.'),
);
expect(subtitle.style?.fontSize, 12.5);
expect(tester.widget<Text>(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_keep_standard_icon_size_in_compact_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-icon'))),
const Size(72, 72),
);
expect(find.byType(DecoratedBox), findsNothing);
expect(
tester
.widget<Text>(find.byKey(const Key('empty-state-title')))
.style
?.fontSize,
15,
);
expect(
tester
.widget<Padding>(find.byKey(const Key('empty-state-padding')))
.padding,
const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
);
expect(find.byKey(const Key('empty-state-action')), findsNothing);
});
testWidgets('should_tint_the_bare_icon_with_the_dark_theme', (tester) async {
await _pump(
tester,
theme: AppTheme.light(),
child: const EmptyState(icon: Icons.history_rounded, title: 'No history'),
);
expect(
tester.widget<Icon>(find.byKey(const Key('empty-state-icon'))).color,
AppColors.subtle,
);
await _pump(
tester,
theme: AppTheme.light(),
child: const EmptyState(icon: Icons.history_rounded, title: 'No history'),
);
expect(
tester.widget<Icon>(find.byKey(const Key('empty-state-icon'))).color,
AppColors.subtle,
);
});
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<ConstrainedBox>(
find.byKey(const Key('empty-state-content')),
);
expect(content.constraints.maxWidth, 260);
expect(tester.takeException(), isNull);
});
}
Future<void> _pump(
WidgetTester tester, {
ThemeData? theme,
required Widget child,
}) async {
await tester.pumpWidget(
MaterialApp(
theme: theme ?? AppTheme.light(),
home: Scaffold(body: child),
),
);
await tester.pumpAndSettle();
}