mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 22:27:13 +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
86 lines
2.9 KiB
Dart
86 lines
2.9 KiB
Dart
import 'package:design_system/design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
Future<void> _pumpHeader(
|
|
WidgetTester tester, {
|
|
Widget? action,
|
|
EdgeInsetsGeometry? padding,
|
|
}) {
|
|
return tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: buildDarkTheme(),
|
|
home: Scaffold(
|
|
body: SectionHeader('Filters', action: action, padding: padding),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('shows the title at titleMedium', (tester) async {
|
|
await _pumpHeader(tester);
|
|
expect(find.text('Filters'), findsOneWidget);
|
|
// Compare the resolved size, not the whole TextStyle: the localization
|
|
// delegate merges geometry (weight, letter spacing, line height) into
|
|
// the theme's style before it reaches the widget, so the two objects are
|
|
// never `==` even when the widget is doing exactly the right thing.
|
|
final text = tester.widget<Text>(find.text('Filters'));
|
|
expect(text.style?.fontSize, AppTextSize.subtitle);
|
|
expect(
|
|
text.style?.fontSize,
|
|
buildDarkTheme().textTheme.titleMedium?.fontSize,
|
|
);
|
|
});
|
|
|
|
testWidgets('has no padding of its own by default', (tester) async {
|
|
await _pumpHeader(tester);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(SectionHeader),
|
|
matching: find.byType(Padding),
|
|
),
|
|
findsNothing,
|
|
);
|
|
});
|
|
|
|
testWidgets('applies padding when asked', (tester) async {
|
|
await _pumpHeader(tester, padding: SectionHeader.defaultPadding);
|
|
final padding = tester.widget<Padding>(
|
|
find
|
|
.descendant(
|
|
of: find.byType(SectionHeader),
|
|
matching: find.byType(Padding),
|
|
)
|
|
.first,
|
|
);
|
|
expect(padding.padding, SectionHeader.defaultPadding);
|
|
});
|
|
|
|
testWidgets('omits the action slot by default', (tester) async {
|
|
await _pumpHeader(tester);
|
|
expect(find.byType(IconButton), findsNothing);
|
|
});
|
|
|
|
testWidgets('renders a trailing action beside the title', (tester) async {
|
|
await _pumpHeader(
|
|
tester,
|
|
action: IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
|
|
);
|
|
expect(find.byIcon(Icons.add), findsOneWidget);
|
|
// The action sits to the right of the title, not below it.
|
|
final titleRight = tester.getTopRight(find.text('Filters')).dx;
|
|
final actionLeft = tester.getTopLeft(find.byIcon(Icons.add)).dx;
|
|
expect(actionLeft, greaterThanOrEqualTo(titleRight));
|
|
});
|
|
|
|
test('defaultPadding groups the title with the content below it', () {
|
|
// Tighter below than above, so the header reads as belonging to the
|
|
// section it labels rather than floating between two of them.
|
|
expect(SectionHeader.defaultPadding.bottom, AppSpacing.xs);
|
|
expect(SectionHeader.defaultPadding.top, AppSpacing.md);
|
|
expect(SectionHeader.defaultPadding.left, AppSpacing.md);
|
|
expect(SectionHeader.defaultPadding.right, AppSpacing.md);
|
|
});
|
|
}
|