c94b9e5e58
Co-Authored-By: Claude Code <noreply@anthropic.com>
61 lines
1.8 KiB
Dart
61 lines
1.8 KiB
Dart
/// EmptyState widget 测试(UI-01 Task 3)。
|
|
///
|
|
/// 覆盖:图标 + 标题 + 说明 + 可选操作按钮全量渲染;操作回调触发;
|
|
/// 无说明/无按钮时不占位。
|
|
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/empty_state.dart';
|
|
|
|
void main() {
|
|
Future<void> pumpState(
|
|
WidgetTester tester, {
|
|
String? subtitle,
|
|
String? actionLabel,
|
|
VoidCallback? onAction,
|
|
}) {
|
|
return tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: AppTheme.light,
|
|
home: Scaffold(
|
|
body: EmptyState(
|
|
icon: Icons.photo_library_outlined,
|
|
title: 'No albums yet',
|
|
subtitle: subtitle,
|
|
actionLabel: actionLabel,
|
|
onAction: onAction,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('渲染图标 + 标题 + 说明 + 操作按钮', (tester) async {
|
|
var taps = 0;
|
|
await pumpState(
|
|
tester,
|
|
subtitle: 'Create one to get started',
|
|
actionLabel: 'Create album',
|
|
onAction: () => taps++,
|
|
);
|
|
|
|
expect(find.byIcon(Icons.photo_library_outlined), findsOneWidget);
|
|
expect(find.text('No albums yet'), findsOneWidget);
|
|
expect(find.text('Create one to get started'), findsOneWidget);
|
|
expect(find.text('Create album'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Create album'));
|
|
expect(taps, 1, reason: '操作回调触发');
|
|
});
|
|
|
|
testWidgets('无说明/无按钮 → 仅图标与标题', (tester) async {
|
|
await pumpState(tester);
|
|
|
|
expect(find.byIcon(Icons.photo_library_outlined), findsOneWidget);
|
|
expect(find.text('No albums yet'), findsOneWidget);
|
|
expect(find.byType(FilledButton), findsNothing);
|
|
});
|
|
}
|