utils/design_system/test/empty_state_test.dart
Krzysztof kuhy Rudnicki db1ce8c378 design_system 0.4.0: import material_ui
Flutter 3.50 deprecates package:flutter/material.dart for the
material_ui package; its ThemeData is a different type, so apps on
3.50 need the theme builders to return material_ui's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:35:00 +01:00

69 lines
2.4 KiB
Dart

import 'package:design_system/design_system.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
/// Built at runtime rather than inlined as a literal, so the `EmptyState`
/// below cannot be const-folded: a const invocation is evaluated at compile
/// time, so the constructor never executes and coverage silently drops.
/// Real call sites interpolate runtime state into these strings anyway.
String _message(int count) => 'Add your first item to get started ($count).';
Future<void> _pumpEmptyState(WidgetTester tester) {
return tester.pumpWidget(
MaterialApp(
theme: buildDarkTheme(),
home: Scaffold(
body: EmptyState(
icon: Icons.inbox_outlined,
title: 'Nothing here yet',
message: _message(0),
),
),
),
);
}
void main() {
testWidgets('shows the icon, title and message', (tester) async {
await _pumpEmptyState(tester);
expect(find.byIcon(Icons.inbox_outlined), findsOneWidget);
expect(find.text('Nothing here yet'), findsOneWidget);
expect(find.text(_message(0)), findsOneWidget);
});
testWidgets('draws the icon at the shared size in the muted color', (
tester,
) async {
await _pumpEmptyState(tester);
final icon = tester.widget<Icon>(find.byType(Icon));
expect(icon.size, AppSpacing.xxl);
expect(icon.color, buildDarkTheme().colorScheme.onSurfaceVariant);
});
testWidgets('mutes the message but not the title', (tester) async {
await _pumpEmptyState(tester);
final scheme = buildDarkTheme().colorScheme;
final message = tester.widget<Text>(find.text(_message(0)));
expect(message.style?.color, scheme.onSurfaceVariant);
expect(message.textAlign, TextAlign.center);
final title = tester.widget<Text>(find.text('Nothing here yet'));
expect(title.style?.color, isNot(scheme.onSurfaceVariant));
});
testWidgets('is a pure placeholder with no action', (tester) async {
// Deliberate: no donor had an action slot, so adding one would be
// speculative surface on a widget that has no consumer yet.
await _pumpEmptyState(tester);
expect(find.byType(ButtonStyleButton), findsNothing);
});
testWidgets('stays centred and shrink-wrapped', (tester) async {
await _pumpEmptyState(tester);
expect(find.byType(Center), findsWidgets);
final column = tester.widget<Column>(find.byType(Column));
expect(column.mainAxisSize, MainAxisSize.min);
});
}