diff --git a/apps/lib/features/auth/presentation/cubits/register_cubit.dart b/apps/lib/features/auth/presentation/cubits/register_cubit.dart index 44b045c..c9c03dc 100644 --- a/apps/lib/features/auth/presentation/cubits/register_cubit.dart +++ b/apps/lib/features/auth/presentation/cubits/register_cubit.dart @@ -153,7 +153,15 @@ class RegisterCubit extends Cubit { } Future resendCode() async { - if (state.pendingEmail == null) return false; + if (state.pendingEmail == null) { + emit( + state.copyWith( + status: FormzSubmissionStatus.failure, + errorMessage: '验证码发送失败,请返回上一步重试', + ), + ); + return false; + } emit(state.copyWith(status: FormzSubmissionStatus.inProgress)); @@ -200,7 +208,13 @@ class RegisterCubit extends Cubit { ); } catch (e) { final message = e is ApiException ? e.message : '验证码发送失败,请重试'; - emit(state.copyWith(isSending: false, errorMessage: message)); + emit( + state.copyWith( + isSending: false, + status: FormzSubmissionStatus.failure, + errorMessage: message, + ), + ); } } } diff --git a/apps/test/features/auth/presentation/cubits/register_cubit_test.dart b/apps/test/features/auth/presentation/cubits/register_cubit_test.dart index 2afcf8a..5647b18 100644 --- a/apps/test/features/auth/presentation/cubits/register_cubit_test.dart +++ b/apps/test/features/auth/presentation/cubits/register_cubit_test.dart @@ -90,7 +90,7 @@ void main() { ); blocTest( - 'restores isSending to false and sets errorMessage on error', + 'restores isSending to false and sets errorMessage and failure status on error', build: () => cubit, seed: () => RegisterState( username: const Username.dirty('testuser'), @@ -107,7 +107,9 @@ void main() { predicate((state) => state.isSending == true), predicate( (state) => - state.isSending == false && state.errorMessage == 'Network error', + state.isSending == false && + state.errorMessage == 'Network error' && + state.status == FormzSubmissionStatus.failure, ), ], verify: (_) { @@ -148,6 +150,21 @@ void main() { }); group('resendCode', () { + blocTest( + 'returns false and sets failure status when pendingEmail is null', + build: () => cubit, + seed: () => RegisterState(pendingEmail: null), + act: (c) => c.resendCode(), + expect: () => [ + isA() + .having((s) => s.status, 'status', FormzSubmissionStatus.failure) + .having((s) => s.errorMessage, 'errorMessage', '验证码发送失败,请返回上一步重试'), + ], + verify: (_) { + verifyNever(() => mockRepository.signupResend(any())); + }, + ); + blocTest( 'returns true and sets status on success', build: () => cubit,