feat(mobile): UI-01 theme system, shared components and navigation
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/// StateBadge widget 测试(UI-01 Task 3)。
|
||||
///
|
||||
/// 覆盖:五个语义变体均渲染图标 + 文案 + 语义色(不只靠颜色)、
|
||||
/// compact/normal 两档高度、深色主题取提亮变体。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:photo_live/app/theme.dart';
|
||||
import 'package:photo_live/ui/components/state_badge.dart';
|
||||
import 'package:photo_live/ui/tokens.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> pumpBadge(
|
||||
WidgetTester tester, {
|
||||
required BadgeVariant variant,
|
||||
bool compact = false,
|
||||
bool dark = false,
|
||||
}) {
|
||||
return tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: dark ? AppTheme.dark : AppTheme.light,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: StateBadge(
|
||||
variant: variant,
|
||||
label: 'badge-label',
|
||||
compact: compact,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Finder containerOf() => find
|
||||
.descendant(of: find.byType(StateBadge), matching: find.byType(Container))
|
||||
.first;
|
||||
|
||||
for (final entry in <(BadgeVariant, IconData, Color)>[
|
||||
(BadgeVariant.success, Icons.check_circle, kColorSuccess),
|
||||
(BadgeVariant.warning, Icons.hourglass_top, kColorWaiting),
|
||||
(BadgeVariant.error, Icons.error_outline, kColorError),
|
||||
(BadgeVariant.neutral, Icons.remove_circle_outline, kColorTextSecondary),
|
||||
(BadgeVariant.info, Icons.info_outline, kColorInfo),
|
||||
]) {
|
||||
final (variant, icon, color) = entry;
|
||||
testWidgets('${variant.name}:图标 + 文案 + 语义色', (tester) async {
|
||||
await pumpBadge(tester, variant: variant);
|
||||
|
||||
expect(find.byIcon(icon), findsOneWidget, reason: '内置语义图标');
|
||||
expect(find.text('badge-label'), findsOneWidget, reason: '状态文案');
|
||||
expect(find.byType(StateBadge), findsOneWidget);
|
||||
|
||||
final container = tester.widget<Container>(containerOf());
|
||||
final decoration = container.decoration as BoxDecoration;
|
||||
expect(
|
||||
decoration.color,
|
||||
color.withValues(alpha: 0.12),
|
||||
reason: '浅色底:语义色 12% 透明度',
|
||||
);
|
||||
|
||||
final text = tester.widget<Text>(find.text('badge-label'));
|
||||
expect(text.style!.color, color, reason: '文字用语义色');
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('compact 高 24 / normal 高 32', (tester) async {
|
||||
await pumpBadge(tester, variant: BadgeVariant.success, compact: true);
|
||||
expect(tester.getSize(find.byType(StateBadge)).height, 24);
|
||||
|
||||
await pumpBadge(tester, variant: BadgeVariant.success);
|
||||
expect(tester.getSize(find.byType(StateBadge)).height, 32);
|
||||
});
|
||||
|
||||
testWidgets('深色主题取提亮变体(success 例)', (tester) async {
|
||||
await pumpBadge(tester, variant: BadgeVariant.success, dark: true);
|
||||
|
||||
expect(find.byIcon(Icons.check_circle), findsOneWidget);
|
||||
final text = tester.widget<Text>(find.text('badge-label'));
|
||||
expect(text.style!.color, kColorSuccessDark);
|
||||
expect(kColorSuccessDark, isNot(kColorSuccess), reason: '深浅变体不同值');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user