mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 22:27:13 +01:00
Some checks failed
design_system tests / test (push) Has been cancelled
Removing the action slot made the constructor const-invocable, so the test's `const EmptyState(...)` was evaluated at compile time and the constructor line never executed -- 99%, caught by the pre-push gate rather than by review, which is the point of having it. Building the message through a helper keeps the invocation non-const. That is also closer to real call sites, which interpolate runtime state into the string rather than passing a literal. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XS1m7b1piBtAL22USLW6jL
71 lines
2.4 KiB
Dart
71 lines
2.4 KiB
Dart
import 'package:design_system/design_system.dart';
|
|
import 'package:flutter/material.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);
|
|
});
|
|
}
|