mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 20:27:15 +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
114 lines
3.4 KiB
Dart
114 lines
3.4 KiB
Dart
import 'package:design_system/design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// Pumps a screen with one button that opens the confirmation and records
|
|
/// whatever it returned.
|
|
Future<List<bool?>> _pumpConfirm(
|
|
WidgetTester tester, {
|
|
String confirmLabel = 'Delete',
|
|
String cancelLabel = 'Cancel',
|
|
}) async {
|
|
final results = <bool?>[];
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: buildDarkTheme(),
|
|
home: Scaffold(
|
|
body: Builder(
|
|
builder: (context) => ElevatedButton(
|
|
onPressed: () async {
|
|
results.add(
|
|
await confirmDestructive(
|
|
context,
|
|
title: 'Delete note?',
|
|
message: 'This cannot be undone.',
|
|
confirmLabel: confirmLabel,
|
|
cancelLabel: cancelLabel,
|
|
),
|
|
);
|
|
},
|
|
child: const Text('open'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('open'));
|
|
await tester.pumpAndSettle();
|
|
return results;
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('shows the title and message', (tester) async {
|
|
await _pumpConfirm(tester);
|
|
expect(find.text('Delete note?'), findsOneWidget);
|
|
expect(find.text('This cannot be undone.'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('returns true when the destructive action is chosen', (
|
|
tester,
|
|
) async {
|
|
final results = await _pumpConfirm(tester);
|
|
await tester.tap(find.text('Delete'));
|
|
await tester.pumpAndSettle();
|
|
expect(results, [true]);
|
|
});
|
|
|
|
testWidgets('returns false when cancelled', (tester) async {
|
|
final results = await _pumpConfirm(tester);
|
|
await tester.tap(find.text('Cancel'));
|
|
await tester.pumpAndSettle();
|
|
expect(results, [false]);
|
|
});
|
|
|
|
testWidgets('Escape dismisses as a refusal', (tester) async {
|
|
final results = await _pumpConfirm(tester);
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pumpAndSettle();
|
|
expect(results, [false]);
|
|
});
|
|
|
|
testWidgets('a barrier dismissal counts as a refusal, not a null', (
|
|
tester,
|
|
) async {
|
|
final results = await _pumpConfirm(tester);
|
|
// Tap the barrier, well outside the dialog.
|
|
await tester.tapAt(const Offset(10, 10));
|
|
await tester.pumpAndSettle();
|
|
expect(results, [false]);
|
|
});
|
|
|
|
testWidgets('autofocuses Cancel so a reflexive Return is safe', (
|
|
tester,
|
|
) async {
|
|
final results = await _pumpConfirm(tester);
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
expect(results, [false], reason: 'Return must not delete');
|
|
});
|
|
|
|
testWidgets('styles the destructive action with the error color', (
|
|
tester,
|
|
) async {
|
|
await _pumpConfirm(tester);
|
|
final button = tester.widget<TextButton>(
|
|
find.ancestor(of: find.text('Delete'), matching: find.byType(TextButton)),
|
|
);
|
|
final color = button.style?.foregroundColor?.resolve({});
|
|
expect(color, buildDarkTheme().colorScheme.error);
|
|
});
|
|
|
|
testWidgets('honours custom labels', (tester) async {
|
|
final results = await _pumpConfirm(
|
|
tester,
|
|
confirmLabel: 'Discard',
|
|
cancelLabel: 'Keep',
|
|
);
|
|
expect(find.text('Discard'), findsOneWidget);
|
|
await tester.tap(find.text('Keep'));
|
|
await tester.pumpAndSettle();
|
|
expect(results, [false]);
|
|
});
|
|
}
|