-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(firebase_ui_auth): clear the error on ForgotPasswordScreen after …
…submitting a valid email (#9992)
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/firebase_ui_auth/test/views/forgot_password_view_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}, | ||
); | ||
}); | ||
} |