2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ import 'package:firebase_ui_localizations/firebase_ui_localizations.dart' ;
5
6
import 'package:flutter/material.dart' ;
6
7
import 'package:flutter_test/flutter_test.dart' ;
7
8
import 'package:firebase_ui_auth/firebase_ui_auth.dart' ;
@@ -15,6 +16,8 @@ import '../test_utils.dart';
15
16
class MockFirebaseAuth extends Mock implements fba.FirebaseAuth {}
16
17
17
18
void main () {
19
+ const labels = DefaultLocalizations ();
20
+
18
21
group ('EmailForm' , () {
19
22
late Widget widget;
20
23
@@ -153,5 +156,128 @@ void main() {
153
156
isFalse,
154
157
);
155
158
});
159
+
160
+ testWidgets ('validates email' , (tester) async {
161
+ await tester.pumpWidget (
162
+ TestMaterialApp (
163
+ child: EmailForm (
164
+ auth: MockAuth (),
165
+ ),
166
+ ),
167
+ );
168
+
169
+ final inputs = find.byType (TextFormField );
170
+ final emailInput = inputs.first;
171
+
172
+ await tester.enterText (emailInput, 'not a vailid email' );
173
+ await tester.testTextInput.receiveAction (TextInputAction .done);
174
+ await tester.pumpAndSettle ();
175
+
176
+ expect (find.text (labels.isNotAValidEmailErrorText), findsOneWidget);
177
+ });
178
+
179
+ testWidgets ('requires password' , (tester) async {
180
+ await tester.pumpWidget (
181
+ TestMaterialApp (
182
+ child: EmailForm (
183
+ auth: MockAuth (),
184
+ ),
185
+ ),
186
+ );
187
+
188
+ final inputs = find.byType (TextFormField );
189
+ final emailInput = inputs.first;
190
+ final passwordInput = inputs.at (1 );
191
+
192
+ await tester.
enterText (emailInput,
'[email protected] ' );
193
+ await tester.testTextInput.receiveAction (TextInputAction .done);
194
+
195
+ await tester.enterText (passwordInput, '' );
196
+ await tester.pumpAndSettle ();
197
+
198
+ expect (find.text (labels.passwordIsRequiredErrorText), findsOneWidget);
199
+ });
200
+
201
+ testWidgets (
202
+ 'shows password confirmation if action is sign up' ,
203
+ (tester) async {
204
+ await tester.pumpWidget (
205
+ TestMaterialApp (
206
+ child: EmailForm (
207
+ auth: MockAuth (),
208
+ action: AuthAction .signUp,
209
+ ),
210
+ ),
211
+ );
212
+
213
+ final inputs = find.byType (TextFormField );
214
+ expect (inputs, findsNWidgets (3 ));
215
+ },
216
+ );
217
+
218
+ testWidgets (
219
+ 'requires password confirmation' ,
220
+ (tester) async {
221
+ await tester.pumpWidget (
222
+ TestMaterialApp (
223
+ child: EmailForm (
224
+ auth: MockAuth (),
225
+ action: AuthAction .signUp,
226
+ ),
227
+ ),
228
+ );
229
+
230
+ final inputs = find.byType (TextFormField );
231
+
232
+ await tester.
enterText (inputs.
at (
0 ),
'[email protected] ' );
233
+ await tester.testTextInput.receiveAction (TextInputAction .done);
234
+
235
+ await tester.enterText (inputs.at (1 ), 'password' );
236
+ await tester.testTextInput.receiveAction (TextInputAction .done);
237
+
238
+ await tester.enterText (inputs.at (2 ), '' );
239
+ await tester.testTextInput.receiveAction (TextInputAction .done);
240
+
241
+ await tester.pumpAndSettle ();
242
+
243
+ expect (
244
+ find.text (labels.confirmPasswordIsRequiredErrorText),
245
+ findsOneWidget,
246
+ );
247
+ },
248
+ );
249
+
250
+ testWidgets (
251
+ 'verifies that password confirmation matches password' ,
252
+ (tester) async {
253
+ await tester.pumpWidget (
254
+ TestMaterialApp (
255
+ child: EmailForm (
256
+ auth: MockAuth (),
257
+ action: AuthAction .signUp,
258
+ ),
259
+ ),
260
+ );
261
+
262
+ final inputs = find.byType (TextFormField );
263
+
264
+ await tester.
enterText (inputs.
at (
0 ),
'[email protected] ' );
265
+ await tester.testTextInput.receiveAction (TextInputAction .done);
266
+ await tester.pump ();
267
+
268
+ await tester.enterText (inputs.at (1 ), 'password' );
269
+ await tester.testTextInput.receiveAction (TextInputAction .done);
270
+ await tester.pump ();
271
+
272
+ await tester.enterText (inputs.at (2 ), 'psasword' );
273
+ await tester.testTextInput.receiveAction (TextInputAction .done);
274
+ await tester.pumpAndSettle ();
275
+
276
+ expect (
277
+ find.text (labels.confirmPasswordDoesNotMatchErrorText),
278
+ findsOneWidget,
279
+ );
280
+ },
281
+ );
156
282
});
157
283
}
0 commit comments