|
| 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 | +import '../test_utils.dart'; |
| 12 | + |
| 13 | +void main() { |
| 14 | + const labels = DefaultLocalizations(); |
| 15 | + late MockAuth auth; |
| 16 | + late MockDynamicLinks dynamicLinks; |
| 17 | + late EmailLinkAuthProvider emailLinkProvider; |
| 18 | + |
| 19 | + setUp(() { |
| 20 | + auth = MockAuth(); |
| 21 | + dynamicLinks = MockDynamicLinks(); |
| 22 | + final actionCodeSettings = ActionCodeSettings( |
| 23 | + url: 'https://example.com', |
| 24 | + ); |
| 25 | + emailLinkProvider = EmailLinkAuthProvider( |
| 26 | + actionCodeSettings: actionCodeSettings, |
| 27 | + dynamicLinks: dynamicLinks, |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + /// If EmailLinkSignInView is the root view, there should be |
| 32 | + /// no option to go back. |
| 33 | + testWidgets('no go back option if root view', (tester) async { |
| 34 | + await tester.pumpWidget(TestMaterialApp( |
| 35 | + child: EmailLinkSignInView( |
| 36 | + provider: emailLinkProvider, |
| 37 | + auth: auth, |
| 38 | + ), |
| 39 | + )); |
| 40 | + |
| 41 | + final button = find.text(labels.goBackButtonLabel); |
| 42 | + expect(button, findsNothing); |
| 43 | + }); |
| 44 | + |
| 45 | + /// If EmailLinkSignInView is pushed from another view, there |
| 46 | + /// should be a button allowing a user to go back. |
| 47 | + testWidgets('show go back option if not root', (tester) async { |
| 48 | + await tester.pumpWidget( |
| 49 | + TestMaterialApp( |
| 50 | + child: Builder( |
| 51 | + builder: (context) => TextButton( |
| 52 | + child: const Text("Push"), |
| 53 | + onPressed: () => Navigator.push( |
| 54 | + context, |
| 55 | + MaterialPageRoute( |
| 56 | + builder: (context) => Scaffold( |
| 57 | + body: EmailLinkSignInView( |
| 58 | + provider: emailLinkProvider, auth: auth), |
| 59 | + ), |
| 60 | + ), |
| 61 | + ), |
| 62 | + ), |
| 63 | + ), |
| 64 | + ), |
| 65 | + ); |
| 66 | + |
| 67 | + await tester.tap(find.textContaining("Push")); |
| 68 | + await tester.pumpAndSettle(); |
| 69 | + final button = find.text(labels.goBackButtonLabel); |
| 70 | + expect(button, findsOneWidget); |
| 71 | + }); |
| 72 | +} |
0 commit comments