fix(auth): 登录异常改为居中吐司

This commit is contained in:
Zhou Weidong committed 2026-10-22 09:57:57 +08:00
1 parent 11e37a92b5
commit d076c57283
16 files changed
+341 -175

No files matched your search

+18 -7
View File
@@ -98,10 +98,10 @@ void main() {
expect(find.text('Enter a valid phone number'), findsOneWidget);
expect(adapter.requests, isEmpty);
expect(find.byKey(const Key('centered-error-dialog')), findsNothing);
expect(find.byKey(const Key('centered-toast')), findsNothing);
});
testWidgets('should_show_centered_dialog_when_otp_request_fails', (
testWidgets('should_show_centered_toast_when_otp_request_fails', (
tester,
) async {
final api = _FailingPhoneAuthApi(sendOtpMessage: 'Too many OTP requests');
@@ -117,9 +117,9 @@ void main() {
await tester.tap(find.byKey(const Key('auth-send-code')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('centered-error-dialog')), findsOneWidget);
expect(find.text('Login failed'), findsOneWidget);
expect(find.byKey(const Key('centered-toast')), findsOneWidget);
expect(find.text('Too many OTP requests'), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
expect(api.sendOtpCalls, 1);
expect(
tester
@@ -127,9 +127,12 @@ void main() {
.onPressed,
isNotNull,
);
await _pumpToastAway(tester);
expect(find.byKey(const Key('centered-toast')), findsNothing);
});
testWidgets('should_show_centered_dialog_when_phone_login_fails', (
testWidgets('should_show_centered_toast_when_phone_login_fails', (
tester,
) async {
final api = _FailingPhoneAuthApi(loginMessage: 'Invalid verification code');
@@ -146,9 +149,9 @@ void main() {
await tester.tap(find.byKey(const Key('auth-phone-submit')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('centered-error-dialog')), findsOneWidget);
expect(find.text('Login failed'), findsOneWidget);
expect(find.byKey(const Key('centered-toast')), findsOneWidget);
expect(find.text('Invalid verification code'), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
expect(api.loginWithPhoneCalls, 1);
expect(
tester
@@ -156,6 +159,9 @@ void main() {
.onPressed,
isNotNull,
);
await _pumpToastAway(tester);
expect(find.byKey(const Key('centered-toast')), findsNothing);
});
testWidgets('should_keep_code_above_ios_keyboard', (tester) async {
@@ -191,6 +197,11 @@ void main() {
});
}
Future<void> _pumpToastAway(WidgetTester tester) async {
await tester.pump(const Duration(seconds: 3));
await tester.pumpAndSettle();
}
class _FailingPhoneAuthApi extends AuthApi {
_FailingPhoneAuthApi({
this.sendOtpMessage = 'otp failed',