tasq/test/theme_overhaul_test.dart

129 lines
4.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tasq/theme/app_theme.dart';
import 'package:tasq/theme/app_surfaces.dart';
import 'package:tasq/widgets/tasq_adaptive_list.dart';
void main() {
testWidgets('AppTheme sets cardTheme elevation to 3 (M2-style)', (
WidgetTester tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
home: Builder(
builder: (context) {
final elevation = Theme.of(context).cardTheme.elevation;
expect(elevation, isNotNull);
expect(elevation, inInclusiveRange(2.0, 4.0));
expect(elevation, equals(3));
return const SizedBox.shrink();
},
),
),
);
});
testWidgets('Card without explicit elevation uses theme elevation', (
WidgetTester tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
home: const Scaffold(
body: Card(child: SizedBox(width: 20, height: 20)),
),
),
);
// Find the Material that actually paints the Card and assert elevation
final materialFinder = find.descendant(
of: find.byType(Card),
matching: find.byType(Material),
);
expect(materialFinder, findsWidgets);
final material = tester.widget<Material>(materialFinder.first);
expect(material.elevation, isNotNull);
expect(material.elevation, inInclusiveRange(2.0, 4.0));
});
testWidgets(
'TasQAdaptiveList mobile Card inherits theme elevation and uses compact radius',
(WidgetTester tester) async {
final theme = AppTheme.light();
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: MediaQuery(
data: const MediaQueryData(size: Size(320, 800)),
child: Scaffold(
body: Center(
child: SizedBox(
width: 320,
child: TasQAdaptiveList<int>(
items: const [1],
columns: const [],
mobileTileBuilder: (context, item, actions) =>
const Card(child: SizedBox(width: 100, height: 40)),
),
),
),
),
),
),
);
// the Card returned by the mobile tile builder should be re-wrapped by
// _MobileTile; assert that the visible Card uses theme elevation and a
// compact 12px radius (per mobile rules).
final cardFinder = find.byType(Card);
expect(cardFinder, findsWidgets);
final Card cardWidget = tester.widget<Card>(cardFinder.first);
final shape = cardWidget.shape as RoundedRectangleBorder;
final radius = (shape.borderRadius as BorderRadius).topLeft.x;
expect(
radius,
equals(
AppSurfaces.of(tester.element(cardFinder.first)).compactCardRadius,
),
);
// Verify the painted Material has the theme elevation
final materialFinder = find.descendant(
of: find.byType(Card),
matching: find.byType(Material),
);
final material = tester.widget<Material>(materialFinder.first);
expect(material.elevation, equals(theme.cardTheme.elevation));
},
);
testWidgets('AppSurfaces tokens are present and dialog/card radii differ', (
WidgetTester tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
home: Builder(
builder: (context) {
final surfaces = AppSurfaces.of(context);
expect(surfaces.compactCardRadius, lessThan(surfaces.cardRadius));
expect(surfaces.dialogRadius, greaterThanOrEqualTo(18));
final dialogShape =
(surfaces.dialogShape.borderRadius as BorderRadius).topLeft.x;
final compactShape =
(surfaces.compactShape.borderRadius as BorderRadius).topLeft.x;
expect(dialogShape, greaterThan(compactShape));
return const SizedBox.shrink();
},
),
),
);
});
}