Skip to content

Commit 6c90b6b

Browse files
authored
fix(firebase_ui_auth): clear the error on ForgotPasswordScreen after submitting a valid email (#9992)
1 parent a118269 commit 6c90b6b

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

packages/firebase_ui_auth/lib/src/views/forgot_password_view.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ class _ForgotPasswordViewState extends State<ForgotPasswordView> {
5353
FirebaseAuthException? exception;
5454

5555
Future<void> _submit(String email) async {
56-
setState(() => isLoading = true);
56+
setState(() {
57+
exception = null;
58+
isLoading = true;
59+
});
60+
5761
try {
5862
await auth.sendPasswordResetEmail(
5963
email: email,

packages/firebase_ui_auth/test/firebase_ui_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import 'flows/universal_email_sign_in_flow_test.dart'
44
as universal_email_sign_in_flow;
55
import 'flows/phone_auth_flow_test.dart' as phone_auth_flow;
66
import 'widgets/email_form_test.dart' as email_form;
7+
import 'views/forgot_password_view_test.dart' as forgot_password_view;
78

89
void main() {
910
email_auth_flow.main();
1011
email_link_flow.main();
1112
universal_email_sign_in_flow.main();
1213
phone_auth_flow.main();
1314
email_form.main();
15+
forgot_password_view.main();
1416
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import 'package:firebase_auth/firebase_auth.dart';
2+
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
import 'package:mockito/mockito.dart';
6+
7+
import '../test_utils.dart';
8+
9+
class MockFirebaseAuth extends Mock implements FirebaseAuth {
10+
@override
11+
Future<void> sendPasswordResetEmail({
12+
String? email,
13+
ActionCodeSettings? actionCodeSettings,
14+
}) {
15+
return super.noSuchMethod(
16+
Invocation.method(
17+
#sendPasswordResetEmail,
18+
[],
19+
{
20+
#email: email,
21+
#actionCodeSettings: actionCodeSettings,
22+
},
23+
),
24+
returnValue: Future.value(),
25+
returnValueForMissingStub: Future.value(),
26+
);
27+
}
28+
}
29+
30+
void main() {
31+
group('Forgot password view', () {
32+
late Widget widget;
33+
late MockFirebaseAuth auth;
34+
35+
setUpAll(() {
36+
auth = MockFirebaseAuth();
37+
38+
widget = TestMaterialApp(
39+
child: ForgotPasswordView(auth: auth),
40+
);
41+
42+
when(auth.sendPasswordResetEmail(email: 'invalid@email')).thenThrow(
43+
FirebaseAuthException(
44+
message: 'invalid-email',
45+
code: 'invalid-email',
46+
),
47+
);
48+
49+
when(auth.sendPasswordResetEmail(email: '[email protected]')).thenAnswer(
50+
(_) => Future.value(),
51+
);
52+
});
53+
54+
testWidgets('shows error if sendPasswordResetEmail failed', (tester) async {
55+
await tester.pumpWidget(widget);
56+
57+
final input = find.byType(TextField);
58+
await tester.enterText(input, 'invalid@email');
59+
60+
await tester.testTextInput.receiveAction(TextInputAction.done);
61+
await tester.pumpAndSettle();
62+
63+
expect(find.text('invalid-email'), findsOneWidget);
64+
});
65+
66+
testWidgets(
67+
"doesn't show ana error on next successful attempt after error",
68+
(tester) async {
69+
await tester.pumpWidget(widget);
70+
71+
final input = find.byType(TextField);
72+
await tester.enterText(input, '[email protected]');
73+
74+
await tester.testTextInput.receiveAction(TextInputAction.done);
75+
await tester.pumpAndSettle();
76+
77+
expect(find.byType(ErrorText), findsNothing);
78+
},
79+
);
80+
});
81+
}

0 commit comments

Comments
 (0)