From 94f63e24551c0dd3c92ea91f9c5aafe921624226 Mon Sep 17 00:00:00 2001 From: Ron Stieger Date: Fri, 18 Aug 2023 12:57:17 -0700 Subject: [PATCH 1/7] Add "Go Back" button to EmailLinkSignInView --- .../lib/src/views/email_link_sign_in_view.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart b/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart index da825aed..e9c8a594 100644 --- a/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart +++ b/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart @@ -83,6 +83,14 @@ class _EmailLinkSignInViewState extends State { ), ], const SizedBox(height: 8), + UniversalButton( + text: l.goBackButtonLabel, + variant: ButtonVariant.text, + onPressed: () { + Navigator.of(context).pop(); + }, + ), + const SizedBox(height: 8), if (state is AuthFailed) ErrorText(exception: state.exception), ], ); From 5062821e9e7fa7aada8053b975936ee0182742e5 Mon Sep 17 00:00:00 2001 From: Ron Stieger Date: Tue, 22 Aug 2023 17:31:04 -0700 Subject: [PATCH 2/7] Protect against going back if this is the root view --- .../lib/src/views/email_link_sign_in_view.dart | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart b/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart index e9c8a594..4a3db427 100644 --- a/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart +++ b/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart @@ -82,14 +82,16 @@ class _EmailLinkSignInViewState extends State { }, ), ], - const SizedBox(height: 8), - UniversalButton( - text: l.goBackButtonLabel, - variant: ButtonVariant.text, - onPressed: () { - Navigator.of(context).pop(); - }, - ), + if (Navigator.canPop(context)) ...[ + const SizedBox(height: 8), + UniversalButton( + text: l.goBackButtonLabel, + variant: ButtonVariant.text, + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], const SizedBox(height: 8), if (state is AuthFailed) ErrorText(exception: state.exception), ], From 124c1b07fecbb74340573c299a09c7720584a885 Mon Sep 17 00:00:00 2001 From: Ron Stieger Date: Wed, 23 Aug 2023 08:09:55 -0700 Subject: [PATCH 3/7] Only check Navigator.canPop() on state init --- .../lib/src/views/email_link_sign_in_view.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart b/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart index 4a3db427..2dc90ac9 100644 --- a/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart +++ b/packages/firebase_ui_auth/lib/src/views/email_link_sign_in_view.dart @@ -39,6 +39,8 @@ class EmailLinkSignInView extends StatefulWidget { class _EmailLinkSignInViewState extends State { final emailCtrl = TextEditingController(); + late final canPop = Navigator.canPop(context); + @override Widget build(BuildContext context) { final l = FirebaseUILocalizations.labelsOf(context); @@ -82,7 +84,7 @@ class _EmailLinkSignInViewState extends State { }, ), ], - if (Navigator.canPop(context)) ...[ + if (canPop) ...[ const SizedBox(height: 8), UniversalButton( text: l.goBackButtonLabel, From 0e56ed668e2cbc8f30ff972467dd34f099aa8e40 Mon Sep 17 00:00:00 2001 From: Ron Stieger Date: Wed, 23 Aug 2023 09:38:30 -0700 Subject: [PATCH 4/7] Add unit tests --- .../views/email_link_sign_in_view_test.dart | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart diff --git a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart new file mode 100644 index 00000000..07512adf --- /dev/null +++ b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart @@ -0,0 +1,57 @@ +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:firebase_ui_localizations/firebase_ui_localizations.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:firebase_ui_auth/firebase_ui_auth.dart'; + +import '../flows/email_link_flow_test.dart'; +import '../test_utils.dart'; + +void main() { + const labels = DefaultLocalizations(); + late MockAuth auth; + late MockDynamicLinks dynamicLinks; + late EmailLinkAuthProvider emailLinkProvider; + + setUp(() { + auth = MockAuth(); + dynamicLinks = MockDynamicLinks(); + final actionCodeSettings = ActionCodeSettings( + url: 'https://example.com', + ); + emailLinkProvider = EmailLinkAuthProvider( + actionCodeSettings: actionCodeSettings, dynamicLinks: dynamicLinks); + }); + + /// If EmailLinkSignInView is the root view, there should be + /// no option to go back. + testWidgets('no go back option if root view', (tester) async { + await tester.pumpWidget(TestMaterialApp( + child: EmailLinkSignInView(provider: emailLinkProvider, auth: auth), + )); + + final button = find.text(labels.goBackButtonLabel); + expect(button, findsNothing); + }); + + /// If EmailLinkSignInView is pushed from another view, there + /// should be a button allowing a user to go back. + testWidgets('show go back option if not root', (tester) async { + await tester.pumpWidget(TestMaterialApp( + child: Builder( + builder: (context) => TextButton( + child: const Text("Push"), + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Scaffold( + body: EmailLinkSignInView( + provider: emailLinkProvider, auth: auth), + ), + )))))); + await tester.tap(find.textContaining("Push")); + await tester.pumpAndSettle(); + final button = find.text(labels.goBackButtonLabel); + expect(button, findsOneWidget); + }); +} From 8a4ebbd483d262a874402d7708267a1fa09b427e Mon Sep 17 00:00:00 2001 From: Ron Stieger Date: Thu, 24 Aug 2023 08:34:15 -0700 Subject: [PATCH 5/7] Add license header and fix formatting --- .../test/views/email_link_sign_in_view_test.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart index 07512adf..f04b7ae0 100644 --- a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart +++ b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart @@ -1,10 +1,13 @@ +// 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_localizations/firebase_ui_localizations.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:firebase_ui_auth/firebase_ui_auth.dart'; -import '../flows/email_link_flow_test.dart'; import '../test_utils.dart'; void main() { @@ -20,14 +23,19 @@ void main() { url: 'https://example.com', ); emailLinkProvider = EmailLinkAuthProvider( - actionCodeSettings: actionCodeSettings, dynamicLinks: dynamicLinks); + actionCodeSettings: actionCodeSettings, + dynamicLinks: dynamicLinks, + ); }); /// If EmailLinkSignInView is the root view, there should be /// no option to go back. testWidgets('no go back option if root view', (tester) async { await tester.pumpWidget(TestMaterialApp( - child: EmailLinkSignInView(provider: emailLinkProvider, auth: auth), + child: EmailLinkSignInView( + provider: emailLinkProvider, + auth: auth, + ), )); final button = find.text(labels.goBackButtonLabel); From e97d8ceb6bcfb9cedf6ee6ace7ce39574fa9dd38 Mon Sep 17 00:00:00 2001 From: Andrei Lesnitsky Date: Thu, 24 Aug 2023 17:43:46 +0200 Subject: [PATCH 6/7] Update packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart --- .../test/views/email_link_sign_in_view_test.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart index f04b7ae0..e12edb29 100644 --- a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart +++ b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart @@ -56,7 +56,12 @@ void main() { body: EmailLinkSignInView( provider: emailLinkProvider, auth: auth), ), - )))))); + ), + ), + ), + ), + ), + ); await tester.tap(find.textContaining("Push")); await tester.pumpAndSettle(); final button = find.text(labels.goBackButtonLabel); From 203db8cafdff939473f43a381e23a62e2dd6391f Mon Sep 17 00:00:00 2001 From: Andrei Lesnitsky Date: Thu, 24 Aug 2023 17:51:13 +0200 Subject: [PATCH 7/7] fix formatting --- .../views/email_link_sign_in_view_test.dart | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart index e12edb29..f0e6b417 100644 --- a/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart +++ b/packages/firebase_ui_auth/test/views/email_link_sign_in_view_test.dart @@ -3,10 +3,10 @@ // 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'; -import 'package:firebase_ui_auth/firebase_ui_auth.dart'; import '../test_utils.dart'; @@ -45,23 +45,25 @@ void main() { /// If EmailLinkSignInView is pushed from another view, there /// should be a button allowing a user to go back. testWidgets('show go back option if not root', (tester) async { - await tester.pumpWidget(TestMaterialApp( + await tester.pumpWidget( + TestMaterialApp( child: Builder( - builder: (context) => TextButton( - child: const Text("Push"), - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => Scaffold( - body: EmailLinkSignInView( - provider: emailLinkProvider, auth: auth), - ), - ), - ), + builder: (context) => TextButton( + child: const Text("Push"), + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Scaffold( + body: EmailLinkSignInView( + provider: emailLinkProvider, auth: auth), ), ), ), - ); + ), + ), + ), + ); + await tester.tap(find.textContaining("Push")); await tester.pumpAndSettle(); final button = find.text(labels.goBackButtonLabel);