|
| 1 | +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:firebase_auth/firebase_auth.dart'; |
| 6 | +import 'package:firebase_ui_auth/firebase_ui_auth.dart'; |
| 7 | +import 'package:firebase_ui_localizations/firebase_ui_localizations.dart'; |
| 8 | +import 'package:flutter/material.dart'; |
| 9 | +import 'package:flutter_test/flutter_test.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + final exception = FirebaseAuthException( |
| 13 | + code: 'invalid-email', |
| 14 | + message: 'The email address is badly formatted.', |
| 15 | + ); |
| 16 | + |
| 17 | + group('$ErrorText', () { |
| 18 | + tearDown(() { |
| 19 | + ErrorText.localizeError = null; |
| 20 | + }); |
| 21 | + |
| 22 | + testWidgets('uses localizations', (tester) async { |
| 23 | + await tester.pumpWidget( |
| 24 | + MaterialApp( |
| 25 | + home: ErrorText(exception: exception), |
| 26 | + localizationsDelegates: [ |
| 27 | + FirebaseUILocalizations.delegate, |
| 28 | + ], |
| 29 | + ), |
| 30 | + ); |
| 31 | + expect( |
| 32 | + find.text('The email address is badly formatted.'), |
| 33 | + findsOneWidget, |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + testWidgets('allows to override error text', (tester) async { |
| 38 | + String localizeError( |
| 39 | + BuildContext context, |
| 40 | + FirebaseAuthException exception, |
| 41 | + ) { |
| 42 | + expect(exception.code, 'invalid-email'); |
| 43 | + return 'Custom error text'; |
| 44 | + } |
| 45 | + |
| 46 | + ErrorText.localizeError = localizeError; |
| 47 | + |
| 48 | + await tester.pumpWidget( |
| 49 | + MaterialApp( |
| 50 | + home: ErrorText(exception: exception), |
| 51 | + localizationsDelegates: [ |
| 52 | + FirebaseUILocalizations.delegate, |
| 53 | + ], |
| 54 | + ), |
| 55 | + ); |
| 56 | + |
| 57 | + expect( |
| 58 | + find.text('Custom error text'), |
| 59 | + findsOneWidget, |
| 60 | + ); |
| 61 | + }); |
| 62 | + }); |
| 63 | +} |
0 commit comments