-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathactions_test.dart
78 lines (64 loc) · 2.14 KB
/
actions_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
// Copyright 2023, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../utils.dart';
void main() {
setUpTests();
group('getControllerForType', () {
setUp(() async {
await auth.createUserWithEmailAndPassword(
email: '[email protected]',
password: '123456',
);
});
Future<void> authenticate(WidgetTester tester) async {
final inputs = find.byType(TextFormField);
await tester.enterText(inputs.at(0), '[email protected]');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();
await tester.enterText(inputs.at(1), '123456');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();
}
testWidgets(
'getControllerForState returns correct controller type',
(tester) async {
late AuthController controller;
await render(
tester,
FirebaseUIActions(
actions: [
AuthStateChangeAction<SignedIn>((context, state) {
controller = getControllerForState(state);
})
],
child: const EmailForm(action: AuthAction.signIn),
),
);
await authenticate(tester);
expect(controller, isA<EmailAuthController>());
},
);
testWidgets(
'throws a StateError if used outside of the FirebaseUIAction',
(tester) async {
late AuthState state;
await render(
tester,
AuthStateListener(
listener: (oldState, newState, _) {
state = newState;
return null;
},
child: const EmailForm(action: AuthAction.signIn),
),
);
await authenticate(tester);
expect(() => getControllerForState(state), throwsStateError);
},
);
});
}