feat: 迁移珊瑚橙主题体系并新增认证基础组件(ADR-005)
- app_theme.dart 重写为语义 token(AppColors/AppRadius),落地 primaryStrong/error 等 AA 对比度色 - 五个页面与公共组件的旧靛蓝硬编码色值全部替换为 token,仅换色不动布局 - 新增 BrandMark/AppTextField/PrimaryButton/InlineErrorBanner/AuthScaffold 及 6 个 widget 测试 - 门禁:dart format(0 changed)/ flutter analyze(0 issues)/ flutter test(7 passed) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:patbond_flutter/core/theme/app_theme.dart';
|
||||
import 'package:patbond_flutter/core/widgets/app_text_field.dart';
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: buildAppTheme(),
|
||||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('errorText 展示在输入框下方', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const AppTextField(label: '密码', errorText: '请输入密码')),
|
||||
);
|
||||
|
||||
expect(find.text('请输入密码'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('errorText 为 null 时不显示错误', (tester) async {
|
||||
await tester.pumpWidget(wrap(const AppTextField(label: '密码')));
|
||||
|
||||
expect(find.text('请输入密码'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('密码模式默认遮蔽,点击切换按钮后可见', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const AppTextField(label: '密码', obscurable: true)),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.visibility_off), findsOneWidget);
|
||||
var editable = tester.widget<EditableText>(find.byType(EditableText));
|
||||
expect(editable.obscureText, isTrue);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.visibility_off));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byIcon(Icons.visibility), findsOneWidget);
|
||||
editable = tester.widget<EditableText>(find.byType(EditableText));
|
||||
expect(editable.obscureText, isFalse);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:patbond_flutter/core/theme/app_theme.dart';
|
||||
import 'package:patbond_flutter/core/widgets/primary_button.dart';
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: buildAppTheme(),
|
||||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('默认态显示文字,点击触发回调', (tester) async {
|
||||
var tapped = 0;
|
||||
await tester.pumpWidget(
|
||||
wrap(PrimaryButton(label: '登录', onPressed: () => tapped++)),
|
||||
);
|
||||
|
||||
expect(find.text('登录'), findsOneWidget);
|
||||
await tester.tap(find.byType(PrimaryButton));
|
||||
expect(tapped, 1);
|
||||
});
|
||||
|
||||
testWidgets('loading 态显示转圈、隐藏文字且不可点击', (tester) async {
|
||||
var tapped = 0;
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
PrimaryButton(label: '登录', isLoading: true, onPressed: () => tapped++),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
expect(find.text('登录'), findsNothing);
|
||||
|
||||
await tester.tap(find.byType(PrimaryButton), warnIfMissed: false);
|
||||
await tester.pump();
|
||||
expect(tapped, 0);
|
||||
|
||||
// loading 不是禁用态:填充保持 primaryStrong,尺寸保持 52 高。
|
||||
final button = tester.widget<FilledButton>(find.byType(FilledButton));
|
||||
expect(button.onPressed, isNull);
|
||||
expect(
|
||||
button.style?.backgroundColor?.resolve({WidgetState.disabled}),
|
||||
AppColors.primaryStrong,
|
||||
);
|
||||
expect(tester.getSize(find.byType(PrimaryButton)).height, 52);
|
||||
});
|
||||
|
||||
testWidgets('onPressed 为 null 时进入禁用态', (tester) async {
|
||||
await tester.pumpWidget(wrap(const PrimaryButton(label: '登录')));
|
||||
|
||||
final button = tester.widget<FilledButton>(find.byType(FilledButton));
|
||||
expect(button.onPressed, isNull);
|
||||
expect(find.text('登录'), findsOneWidget);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user