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