test: 按新 UI 基线重写过期用例

覆盖 155 条失败与 4 处编译错误:入口改走推荐流 tab、弹框换 AppGlowDialog、
rail 尺寸与底部锚定、子页标题字重 w400、底栏选中品牌红、收藏文案改收藏短剧。
全量 flutter test 775 通过。
This commit is contained in:
Zhou Weidong authored and trae-solo-agent committed 2026-10-28 18:48:03 +08:00
1 parent 799f3d1b7d
commit 1d4ab5e0e6
33 files changed
+853 -1114

No files matched your search

+28 -9
View File
@@ -25,6 +25,21 @@ void main() {
setUp(() {
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.empty();
// 注册流程会通过 device 通道读取设备国家;widget 测试没有原生实现,
// 不打桩这个通道调用会一直等不到回复(提交按钮转圈、pumpAndSettle 超时)。
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('com.stormg.lumadrama/device'),
(call) async => call.method == 'region' ? 'ID' : null,
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('com.stormg.lumadrama/device'),
null,
);
});
Future<void> pumpAuthPage(
@@ -179,11 +194,16 @@ void main() {
await pumpAuthPage(tester);
expect(find.text('Welcome back'), findsOneWidget);
await tester.tap(find.text('New here? Create an account'));
// 新版用顶部 Sign In / Sign Up 分段切换,不再有底部文字链接。
await tester.tap(find.byKey(const Key('auth-mode-sign-up')));
await tester.pumpAndSettle();
expect(find.text('Create your account'), findsOneWidget);
expect(find.text('Already have an account? Sign in'), findsOneWidget);
expect(find.text('Welcome back'), findsNothing);
await tester.tap(find.byKey(const Key('auth-mode-sign-in')));
await tester.pumpAndSettle();
expect(find.text('Welcome back'), findsOneWidget);
},
);
@@ -208,10 +228,6 @@ void main() {
tester.getSize(find.byKey(const Key('auth-password-visibility'))).height,
greaterThanOrEqualTo(44),
);
expect(
tester.getSize(find.byKey(const Key('auth-switch-mode'))).height,
greaterThanOrEqualTo(44),
);
});
testWidgets('should_toggle_password_visibility_when_eye_button_is_tapped', (
@@ -287,8 +303,8 @@ void main() {
);
expect(
tester
.widget<TextButton>(find.byKey(const Key('auth-switch-mode')))
.onPressed,
.widget<GestureDetector>(find.byKey(const Key('auth-mode-sign-up')))
.onTap,
isNull,
);
@@ -316,12 +332,14 @@ void main() {
(tester) async {
tester.view.physicalSize = const Size(320, 568);
tester.view.devicePixelRatio = 1;
tester.view.viewInsets = const FakeViewPadding(bottom: 260);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.view.resetViewInsets);
await pumpAuthPage(tester);
// 键盘在邮箱表单打开之后再弹出(落地页按可用高度分段排版,不适合压到 240 高)。
tester.view.viewInsets = const FakeViewPadding(bottom: 260);
await tester.pumpAndSettle();
await tester.scrollUntilVisible(
find.byKey(const Key('auth-submit')),
120,
@@ -474,6 +492,7 @@ class _FailingAuthApi extends AuthApi {
required String email,
required String password,
required String deviceId,
String countryCode = '',
String platform = '',
String osVersion = '',
String appVersion = '',
+52 -45
View File
@@ -13,7 +13,6 @@ import 'package:fruitshorts/core/data/services/auth_controller.dart';
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
import 'package:fruitshorts/core/platform/haptics.dart';
import 'package:fruitshorts/core/theme/app_colors.dart';
import 'package:fruitshorts/core/theme/app_dimens.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
import 'package:fruitshorts/pages/auth/auth_view.dart';
@@ -78,13 +77,13 @@ void main() {
expect(find.byKey(const Key('auth-landing')), findsOneWidget);
expect(find.text('FruitShorts'), findsOneWidget);
expect(
find.text('Sign in to sync progress, favorites and coins'),
findsOneWidget,
);
final brand = tester.widget<Text>(find.text('FruitShorts'));
expect(brand.style?.fontSize, 26);
expect(brand.style?.fontWeight, FontWeight.w700);
expect(brand.style?.letterSpacing, 2);
expect(
tester.getSize(find.byKey(const Key('auth-brand-logo'))),
const Size(72, 72),
const Size(88, 88),
);
expect(find.byKey(const Key('auth-entry-google')), findsNothing);
expect(find.byKey(const Key('auth-entry-phone')), findsOneWidget);
@@ -92,11 +91,11 @@ void main() {
expect(find.byKey(const Key('auth-legal')), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('auth-entry-phone'))).height,
50,
52,
);
expect(
tester.getSize(find.byKey(const Key('auth-entry-email'))).height,
50,
52,
);
final phoneButton = tester.widget<Material>(
find.descendant(
@@ -104,67 +103,68 @@ void main() {
matching: find.byType(Material),
),
);
expect(phoneButton.color, AppColors.blue);
expect(phoneButton.color, AppColors.brandRed);
expect(
(phoneButton.shape! as RoundedRectangleBorder).borderRadius,
BorderRadius.circular(26),
);
final emailButton = tester.widget<Material>(
find.descendant(
of: find.byKey(const Key('auth-entry-email')),
matching: find.byType(Material),
),
);
expect(emailButton.color, AppColors.card);
expect(
(emailButton.shape! as RoundedRectangleBorder).side.color,
AppColors.border,
);
// 次按钮是「白 6%」玻璃拟态,不再有描边。
expect(emailButton.color, Colors.white.withValues(alpha: 0.06));
final glow = tester.widget<Container>(
find.byKey(const Key('auth-background-glow')),
final glow = tester.widget<DecoratedBox>(
find.byKey(const Key('auth-red-glow')),
);
final glowDecoration = glow.decoration! as BoxDecoration;
final glowDecoration = glow.decoration as BoxDecoration;
final gradient = glowDecoration.gradient! as RadialGradient;
expect(gradient.colors.first, AppColors.surfaceTop);
expect(gradient.colors.last.a, 0);
expect(gradient.colors, const [
AppColors.primaryBorder,
AppColors.transparent,
]);
await tester.tap(find.byKey(const Key('auth-entry-email')));
await tester.pumpAndSettle();
final card = tester.widget<Container>(find.byKey(const Key('auth-card')));
final cardDecoration = card.decoration! as BoxDecoration;
expect(cardDecoration.color, AppColors.card);
expect(
cardDecoration.borderRadius,
BorderRadius.circular(AppDimens.authCardRadius),
);
expect(cardDecoration.boxShadow, isNull);
expect(card.padding, const EdgeInsets.all(20));
// 新版表单不再套卡片盒子,直接排在光晕背景上。
expect(find.byKey(const Key('auth-card')), findsOneWidget);
final email = tester.widget<TextField>(
find.byKey(const Key('auth-email')),
);
expect(email.decoration?.fillColor, AppColors.card);
expect(
email.decoration?.fillColor,
Colors.white.withValues(alpha: 0.05),
);
expect(email.style?.color, AppColors.onSurface);
expect(email.style?.fontSize, 15);
expect(email.cursorColor, AppColors.blue);
expect(email.cursorColor, AppColors.brandRed);
expect(tester.getSize(find.byKey(const Key('auth-email'))).height, 52);
final emailBorder =
email.decoration!.enabledBorder! as OutlineInputBorder;
expect(emailBorder.borderRadius, BorderRadius.circular(14));
expect(emailBorder.borderSide.color, AppColors.border);
expect(emailBorder.borderSide.width, 1);
expect(emailBorder.borderRadius, BorderRadius.circular(12));
expect(emailBorder.borderSide, BorderSide.none);
final password = tester.widget<TextField>(
find.byKey(const Key('auth-password')),
);
expect(password.style?.color, AppColors.onSurface);
expect(password.style?.fontSize, 15);
expect(password.cursorColor, AppColors.blue);
expect(password.cursorColor, AppColors.brandRed);
final submit = tester.widget<FilledButton>(
find.byKey(const Key('auth-submit')),
);
expect(submit.style!.backgroundColor!.resolve(const {}), AppColors.blue);
expect(
submit.style!.backgroundColor!.resolve(const {}),
AppColors.brandRed,
);
expect(
submit.style!.backgroundColor!.resolve(const {WidgetState.pressed}),
AppColors.bluePressed,
AppColors.brandRedPressed,
);
expect(tester.getSize(find.byKey(const Key('auth-submit'))).height, 50);
expect(
@@ -201,9 +201,14 @@ void main() {
(image.image as AssetImage).assetName,
'assets/icon/fruitshorts.png',
);
// 新版落地页用三等分 Spacer 排版,Logo 居中且落在两个入口按钮上方。
final logo = find.byKey(const Key('auth-brand-logo'));
expect(tester.getCenter(logo).dx, closeTo(195, 0.1));
expect(
tester.getTopLeft(find.byKey(const Key('auth-brand-logo'))).dy,
84,
tester.getBottomLeft(logo).dy,
lessThan(
tester.getTopLeft(find.byKey(const Key('auth-entry-phone'))).dy,
),
);
},
);
@@ -250,7 +255,7 @@ void main() {
expect(find.text('Create your account'), findsOneWidget);
expect(find.text('Welcome back'), findsNothing);
expect(_segmentColor(tester, 'auth-mode-sign-up'), AppColors.blue);
expect(_segmentColor(tester, 'auth-mode-sign-up'), AppColors.brandRed);
expect(_segmentColor(tester, 'auth-mode-sign-in'), Colors.transparent);
await tester.tap(find.byKey(const Key('auth-mode-sign-in')));
@@ -258,7 +263,7 @@ void main() {
expect(find.text('Welcome back'), findsOneWidget);
expect(find.text('Create your account'), findsNothing);
expect(_segmentColor(tester, 'auth-mode-sign-in'), AppColors.blue);
expect(_segmentColor(tester, 'auth-mode-sign-in'), AppColors.brandRed);
expect(_segmentColor(tester, 'auth-mode-sign-up'), Colors.transparent);
},
);
@@ -330,8 +335,10 @@ void main() {
);
expect(
tester
.widget<TextButton>(find.byKey(const Key('auth-switch-mode')))
.onPressed,
.widget<GestureDetector>(
find.byKey(const Key('auth-mode-sign-up')),
)
.onTap,
isNull,
);
expect(
@@ -379,10 +386,10 @@ void main() {
Color? _segmentColor(WidgetTester tester, String key) {
final segment = find.byKey(Key(key));
final animated = tester.widget<AnimatedContainer>(
find.descendant(of: segment, matching: find.byType(AnimatedContainer)),
final underline = tester.widget<Container>(
find.descendant(of: segment, matching: find.byType(Container)),
);
return (animated.decoration! as BoxDecoration).color;
return (underline.decoration! as BoxDecoration).color;
}
class _PendingAuthApi extends AuthApi {