Files
platforms/apps/user_app/test/ui/login_page_test.dart
2026-09-02 21:07:47 +08:00

40 lines
1.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能描述:验证用户端登录页字段、手机号校验和接口错误中文化。
// 版本1.1.0
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:user_app/app/dependencies.dart';
import 'package:user_app/data/services/api_client.dart';
import 'package:user_app/data/services/secure_session_store.dart';
import 'package:user_app/ui/features/auth/login_page.dart';
/// 验证用户端登录界面的关键交互。
void main() {
testWidgets('login page exposes phone and password fields', (tester) async {
final session = UserSession(SecureSessionStore());
await tester.pumpWidget(MaterialApp(home: LoginPage(session: session)));
expect(find.text('瓶安芯'), findsOneWidget);
expect(find.byType(TextField), findsNWidgets(2));
expect(find.text('安全登录'), findsOneWidget);
});
testWidgets('手机号格式错误显示输入框中文提示', (tester) async {
final session = UserSession(SecureSessionStore());
await tester.pumpWidget(MaterialApp(home: LoginPage(session: session)));
await tester.enterText(find.byType(TextField).first, '+8613800138000');
await tester.tap(find.text('安全登录'));
await tester.pump();
expect(find.text('请输入正确的11位手机号'), findsOneWidget);
expect(find.text('Invalid Argument'), findsNothing);
});
test('接口错误优先按错误码中文化并屏蔽未知英文', () {
expect(localizeApiErrorMessage(1704, 'Invalid Argument'), '请求参数错误');
expect(localizeApiErrorMessage(1108, 'Password Incorrect'), '密码错误');
expect(localizeApiErrorMessage(9999, '业务处理失败'), '业务处理失败');
expect(localizeApiErrorMessage(9999, 'Unexpected Error'), '操作失败,请稍后重试');
});
}