Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firebase_ui_auth): Add "Go Back" button to EmailLinkSignInView #63

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class EmailLinkSignInView extends StatefulWidget {

class _EmailLinkSignInViewState extends State<EmailLinkSignInView> {
final emailCtrl = TextEditingController();
late final canPop = Navigator.canPop(context);

@override
Widget build(BuildContext context) {
final l = FirebaseUILocalizations.labelsOf(context);
Expand Down Expand Up @@ -82,6 +84,16 @@ class _EmailLinkSignInViewState extends State<EmailLinkSignInView> {
},
),
],
if (canPop) ...[
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),
],
Expand Down
lesnitsky marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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);
lesnitsky marked this conversation as resolved.
Show resolved Hide resolved
});

/// 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),
),
))))));
lesnitsky marked this conversation as resolved.
Show resolved Hide resolved
await tester.tap(find.textContaining("Push"));
await tester.pumpAndSettle();
final button = find.text(labels.goBackButtonLabel);
expect(button, findsOneWidget);
});
}