Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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';

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);
});
}