mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 19:07:17 +01:00
unified-design-system/ froze the token layer as prose -- 1220 lines of README, tokens.md and annotated HTML, and zero importable code. Every Flutter repo transcribed the token table by hand, so the "shared" palette was enforced only by discipline, and had already drifted: 10 divergent theme.dart copies (todo and untools byte-identical, the other 8 each unique), ~318 raw color literals, 4 hand-rolled AppStatusColors extensions with inconsistent field sets, ~35 inlined AlertDialogs, ~38 raw SnackBar sites with no helper anywhere. This promotes the token layer into an importable component layer, so the design system is enforced by the compiler and the package manager instead. The components own the tokens: a consumer has nothing local left to edit. Scales are the six-repo consensus, which is also what tokens.md specifies; drifted repos get corrected to this rather than the reverse. Themes are built from explicit ColorSchemes, never fromSeed -- the palette is hand-picked for contrast, and secondary/tertiary are set explicitly so SegmentedButton cannot fall back to stock Material teal. Widgets are extracted only where two or more repos already had a structurally similar implementation; SectionHeader reconciles untools' trailing-action variant with billsplit's padded one as an opt-in union, so either caller can adopt it with no visual change. 63 tests, 102/102 lines covered, gated at 100% on pre-push. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XS1m7b1piBtAL22USLW6jL
72 lines
2.3 KiB
Dart
72 lines
2.3 KiB
Dart
import 'package:design_system/design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
Future<void> _pumpEmptyState(WidgetTester tester, {Widget? action}) {
|
|
return tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: buildDarkTheme(),
|
|
home: Scaffold(
|
|
body: EmptyState(
|
|
icon: Icons.inbox_outlined,
|
|
title: 'Nothing here yet',
|
|
message: 'Add your first item to get started.',
|
|
action: action,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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('Add your first item to get started.'), 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('Add your first item to get started.'),
|
|
);
|
|
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('omits the action slot by default', (tester) async {
|
|
await _pumpEmptyState(tester);
|
|
expect(find.byType(ElevatedButton), findsNothing);
|
|
});
|
|
|
|
testWidgets('renders an action when one is given', (tester) async {
|
|
await _pumpEmptyState(
|
|
tester,
|
|
action: ElevatedButton(onPressed: () {}, child: const Text('Add item')),
|
|
);
|
|
expect(find.text('Add item'), findsOneWidget);
|
|
});
|
|
|
|
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);
|
|
});
|
|
}
|