Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(firebase_ui_auth): clear the error on ForgotPasswordScreen after submitting a valid email #9992

Merged
merged 1 commit into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,7 +53,11 @@ class _ForgotPasswordViewState extends State<ForgotPasswordView> {
FirebaseAuthException? exception;

Future<void> _submit(String email) async {
setState(() => isLoading = true);
setState(() {
exception = null;
isLoading = true;
});

try {
await auth.sendPasswordResetEmail(
email: email,
Expand Down
2 changes: 2 additions & 0 deletions packages/firebase_ui_auth/test/firebase_ui_test.dart
Expand Up @@ -4,11 +4,13 @@ import 'flows/universal_email_sign_in_flow_test.dart'
as universal_email_sign_in_flow;
import 'flows/phone_auth_flow_test.dart' as phone_auth_flow;
import 'widgets/email_form_test.dart' as email_form;
import 'views/forgot_password_view_test.dart' as forgot_password_view;

void main() {
email_auth_flow.main();
email_link_flow.main();
universal_email_sign_in_flow.main();
phone_auth_flow.main();
email_form.main();
forgot_password_view.main();
}
@@ -0,0 +1,81 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';

import '../test_utils.dart';

class MockFirebaseAuth extends Mock implements FirebaseAuth {
@override
Future<void> sendPasswordResetEmail({
String? email,
ActionCodeSettings? actionCodeSettings,
}) {
return super.noSuchMethod(
Invocation.method(
#sendPasswordResetEmail,
[],
{
#email: email,
#actionCodeSettings: actionCodeSettings,
},
),
returnValue: Future.value(),
returnValueForMissingStub: Future.value(),
);
}
}

void main() {
group('Forgot password view', () {
late Widget widget;
late MockFirebaseAuth auth;

setUpAll(() {
auth = MockFirebaseAuth();

widget = TestMaterialApp(
child: ForgotPasswordView(auth: auth),
);

when(auth.sendPasswordResetEmail(email: 'invalid@email')).thenThrow(
FirebaseAuthException(
message: 'invalid-email',
code: 'invalid-email',
),
);

when(auth.sendPasswordResetEmail(email: 'valid@email.com')).thenAnswer(
(_) => Future.value(),
);
});

testWidgets('shows error if sendPasswordResetEmail failed', (tester) async {
await tester.pumpWidget(widget);

final input = find.byType(TextField);
await tester.enterText(input, 'invalid@email');

await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();

expect(find.text('invalid-email'), findsOneWidget);
});

testWidgets(
"doesn't show ana error on next successful attempt after error",
(tester) async {
await tester.pumpWidget(widget);

final input = find.byType(TextField);
await tester.enterText(input, 'valid@email.com');

await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();

expect(find.byType(ErrorText), findsNothing);
},
);
});
}