完善移动端错误提示中文化
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
// 功能描述:验证用户端登录页字段、手机号校验和接口错误中文化。
|
||||
// 版本: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());
|
||||
@@ -13,4 +17,23 @@ void main() {
|
||||
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'), '操作失败,请稍后重试');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user