-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui_auth): add a way to customize ErrorText message (#119)
* feat(ui_auth): add a way to customize ErrorText * add tests * add license header
- Loading branch information
Showing
2 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/firebase_ui_auth/test/widgets/error_text_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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_auth/firebase_auth.dart'; | ||
import 'package:firebase_ui_auth/firebase_ui_auth.dart'; | ||
import 'package:firebase_ui_localizations/firebase_ui_localizations.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
final exception = FirebaseAuthException( | ||
code: 'invalid-email', | ||
message: 'The email address is badly formatted.', | ||
); | ||
|
||
group('$ErrorText', () { | ||
tearDown(() { | ||
ErrorText.localizeError = null; | ||
}); | ||
|
||
testWidgets('uses localizations', (tester) async { | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: ErrorText(exception: exception), | ||
localizationsDelegates: [ | ||
FirebaseUILocalizations.delegate, | ||
], | ||
), | ||
); | ||
expect( | ||
find.text('The email address is badly formatted.'), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('allows to override error text', (tester) async { | ||
String localizeError( | ||
BuildContext context, | ||
FirebaseAuthException exception, | ||
) { | ||
expect(exception.code, 'invalid-email'); | ||
return 'Custom error text'; | ||
} | ||
|
||
ErrorText.localizeError = localizeError; | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: ErrorText(exception: exception), | ||
localizationsDelegates: [ | ||
FirebaseUILocalizations.delegate, | ||
], | ||
), | ||
); | ||
|
||
expect( | ||
find.text('Custom error text'), | ||
findsOneWidget, | ||
); | ||
}); | ||
}); | ||
} |