-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
forgot_password_view_test.dart
81 lines (66 loc) 路 2.12 KB
/
forgot_password_view_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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);
},
);
});
}