Skip to content

Commit 955e5c2

Browse files
fix(firebase_ui_auth): sendPasswordResetEmail should not be executed when isLoading=true (#315)
Co-authored-by: russellwheatley <[email protected]>
1 parent 1d8329d commit 955e5c2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: packages/firebase_ui_auth/lib/src/views/forgot_password_view.dart

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class _ForgotPasswordViewState extends State<ForgotPasswordView> {
5454
fba.FirebaseAuthException? exception;
5555

5656
Future<void> _submit(String email) async {
57+
if (isLoading) {
58+
return;
59+
}
60+
5761
setState(() {
5862
exception = null;
5963
isLoading = true;

Diff for: packages/firebase_ui_auth/test/views/forgot_password_view_test.dart

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:firebase_auth/firebase_auth.dart' as fba;
66
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
7+
import 'package:firebase_ui_shared/firebase_ui_shared.dart';
78
import 'package:flutter/material.dart';
89
import 'package:flutter_test/flutter_test.dart';
910
import 'package:mockito/mockito.dart';
@@ -53,6 +54,10 @@ void main() {
5354
when(auth.sendPasswordResetEmail(email: '[email protected]')).thenAnswer(
5455
(_) => Future.value(),
5556
);
57+
58+
when(auth.sendPasswordResetEmail(email: '[email protected]')).thenAnswer(
59+
(_) => Future.delayed(const Duration(milliseconds: 200)),
60+
);
5661
});
5762

5863
testWidgets('shows error if sendPasswordResetEmail failed', (tester) async {
@@ -81,5 +86,20 @@ void main() {
8186
expect(find.byType(ErrorText), findsNothing);
8287
},
8388
);
89+
90+
testWidgets("doesn't sendPasswordResetEmail on loading", (tester) async {
91+
await tester.pumpWidget(widget);
92+
93+
final input = find.byType(TextField);
94+
await tester.enterText(input, '[email protected]');
95+
96+
final button = find.byType(LoadingButton);
97+
await tester.tap(button);
98+
await tester.tap(button);
99+
await tester.pumpAndSettle();
100+
101+
expect(find.byType(ErrorText), findsNothing);
102+
verify(auth.sendPasswordResetEmail(email: '[email protected]')).called(1);
103+
});
84104
});
85105
}

0 commit comments

Comments
 (0)