-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign_in_screen_widget_test.dart
56 lines (55 loc) · 2.53 KB
/
sign_in_screen_widget_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
/*import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zip/business/auth.dart';
import 'package:zip/business/validator.dart';
import 'package:flutter/services.dart';
import 'package:zip/ui/screens/sign_in_screen.dart';
import 'package:mockito/mockito.dart';
class MockAuth extends Mock implements AuthService {}
void main() {
Widget makeTestableWidget({Widget child, AuthService auth}) {
return GoogleAuthProvider(
auth: auth,
child: MaterialApp(
home: child,
),
);
}
testWidgets('email or password is empty, does not sign in', (WidgetTester tester) async {
MockAuth mockAuth = MockAuth();
bool didSignIn = false;
SignInScreen page = SignInScreen(onSignIn: () => didSignIn = true);
await tester.pumpWidget(makeTestableWidget(child: page, auth: mockAuth));
await tester.tap(find.byKey(Key('signIn')));
verifyNever(mockAuth.signInWithEmailAndPassword('', ''));
expect(didSignIn, false);
});
testWidgets('non-empty email and password, valid account, call sign in, succeed', (WidgetTester tester) async {
MockAuth mockAuth = MockAuth();
when(mockAuth.signInWithEmailAndPassword('email', 'password')).thenAnswer((invocation) => Future.value('uid'));
bool didSignIn = false;
SignInScreen page = SignInScreen(onSignedIn: () => didSignIn = true);
await tester.pumpWidget(makeTestableWidget(child: page, auth: mockAuth));
Finder emailField = find.byKey(Key('email'));
await tester.enterText(emailField, 'email');
Finder passwordField = find.byKey(Key('password'));
await tester.enterText(passwordField, 'password');
await tester.tap(find.byKey(Key('signIn')));
verify(mockAuth.signInWithEmailAndPassword('email', 'password')).called(1);
expect(didSignIn, true);
});
testWidgets('non-empty email and password, valid account, call sign in, fails', (WidgetTester tester) async {
MockAuth mockAuth = MockAuth();
when(mockAuth.signIn('email', 'password')).thenThrow(StateError('invalid credentials'));
bool didSignIn = false;
SignInScreen page = SignInScreen(onSignedIn: () => didSignIn = true);
await tester.pumpWidget(makeTestableWidget(child: page, auth: mockAuth));
Finder emailField = find.byKey(Key('email'));
await tester.enterText(emailField, 'email');
Finder passwordField = find.byKey(Key('password'));
await tester.enterText(passwordField, 'password');
await tester.tap(find.byKey(Key('signIn')));
verify(mockAuth.signInWithEmailAndPassword('email', 'password')).called(1);
expect(didSignIn, false);
});
}*/