Skip to content

Commit 1e091cc

Browse files
fix(ui_auth): Pass correct AuthAction to the footerBuilder (#70)
* fix: Wrong action value for authentication footer This change is needed to rebuild the footer when the action changes (for example when the user click on the header auth action switch) * test: ✅ (ui_auth) Add test for Login View footer update on action switch * docs: 📄 Add license header on test file
1 parent 326fd27 commit 1e091cc

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

Diff for: packages/firebase_ui_auth/lib/src/views/login_view.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class _LoginViewState extends State<LoginView> {
242242
if (widget.footerBuilder != null)
243243
widget.footerBuilder!(
244244
context,
245-
widget.action,
245+
_action,
246246
),
247247
],
248248
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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_ui_auth/firebase_ui_auth.dart';
6+
import 'package:flutter/gestures.dart';
7+
import 'package:flutter/material.dart';
8+
import 'package:flutter/rendering.dart';
9+
import 'package:flutter_test/flutter_test.dart';
10+
11+
import '../../test_utils.dart';
12+
13+
void main() {
14+
group("$LoginView", () {
15+
testWidgets(
16+
'rebuilds the footer when the $AuthAction changes',
17+
(tester) async {
18+
const signInKey = ValueKey("Sign in");
19+
const registerKey = ValueKey("Register");
20+
21+
const widgetSignIn = SizedBox(key: signInKey);
22+
const widgetRegister = SizedBox(key: registerKey);
23+
24+
final view = TestMaterialApp(
25+
child: LoginView(
26+
providers: [EmailAuthProvider()],
27+
auth: MockAuth(),
28+
action: AuthAction.signIn,
29+
showAuthActionSwitch: true,
30+
footerBuilder: (context, action) {
31+
switch (action) {
32+
case AuthAction.signIn:
33+
return widgetSignIn;
34+
case AuthAction.signUp:
35+
return widgetRegister;
36+
default:
37+
return const SizedBox();
38+
}
39+
},
40+
),
41+
);
42+
await tester.pumpWidget(view);
43+
44+
expect(find.byKey(signInKey), findsOneWidget);
45+
expect(find.byKey(registerKey), findsNothing);
46+
47+
await _tapOnRegisterActionText(tester);
48+
49+
expect(find.byKey(signInKey), findsNothing);
50+
expect(find.byKey(registerKey), findsOneWidget);
51+
},
52+
);
53+
});
54+
}
55+
56+
/// Taps on the Register text in the action switch of the [LoginView].
57+
///
58+
/// We have to do this because the [WidgetTester] API does not enable the search
59+
/// for a particular TextSpan.
60+
/// See https://stackoverflow.com/a/60247474/19586032 for more details.
61+
Future<void> _tapOnRegisterActionText(WidgetTester tester) async {
62+
final actionSwitchRichText = find
63+
.byWidgetPredicate(
64+
(widget) =>
65+
widget is RichText &&
66+
widget.text.toPlainText().contains("Register"),
67+
)
68+
.evaluate()
69+
.first
70+
.renderObject! as RenderParagraph;
71+
72+
actionSwitchRichText.text.visitChildren((InlineSpan span) {
73+
if (span is! TextSpan) return true;
74+
75+
span.visitChildren((InlineSpan span) {
76+
if (span is! TextSpan) return true;
77+
78+
if (span.text != 'Register') return true;
79+
80+
(span.recognizer! as TapGestureRecognizer).onTap!();
81+
return false;
82+
});
83+
84+
return true;
85+
});
86+
87+
await tester.pumpAndSettle();
88+
}

0 commit comments

Comments
 (0)