Skip to content

Commit ebaf160

Browse files
authored
Update Drawer tests for M2/M3 (flutter#135752)
Updated unit tests for `Drawer` to have M2 and M3 versions. More info in flutter#127064
1 parent 7c9feea commit ebaf160

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

packages/flutter/test/material/drawer_test.dart

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1010
import '../widgets/semantics_tester.dart';
1111

1212
void main() {
13-
testWidgetsWithLeakTracking('Drawer control test', (WidgetTester tester) async {
13+
testWidgetsWithLeakTracking('Material2 - Drawer control test', (WidgetTester tester) async {
1414
const Key containerKey = Key('container');
1515

1616
await tester.pumpWidget(
@@ -58,6 +58,54 @@ void main() {
5858
expect(find.text('header'), findsOneWidget);
5959
});
6060

61+
testWidgetsWithLeakTracking('Material3 - Drawer control test', (WidgetTester tester) async {
62+
const Key containerKey = Key('container');
63+
64+
await tester.pumpWidget(
65+
MaterialApp(
66+
theme: ThemeData(useMaterial3: true),
67+
home: Scaffold(
68+
drawer: Drawer(
69+
child: ListView(
70+
children: <Widget>[
71+
DrawerHeader(
72+
child: Container(
73+
key: containerKey,
74+
child: const Text('header'),
75+
),
76+
),
77+
const ListTile(
78+
leading: Icon(Icons.archive),
79+
title: Text('Archive'),
80+
),
81+
],
82+
),
83+
),
84+
),
85+
),
86+
);
87+
88+
expect(find.text('Archive'), findsNothing);
89+
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
90+
state.openDrawer();
91+
92+
await tester.pump();
93+
await tester.pump(const Duration(seconds: 1));
94+
expect(find.text('Archive'), findsOneWidget);
95+
96+
RenderBox box = tester.renderObject(find.byType(DrawerHeader));
97+
expect(box.size.height, equals(160.0 + 8.0 + 1.0)); // height + bottom margin + bottom edge
98+
99+
final double drawerWidth = box.size.width;
100+
final double drawerHeight = box.size.height;
101+
102+
box = tester.renderObject(find.byKey(containerKey));
103+
expect(box.size.width, equals(drawerWidth - 2 * 16.0));
104+
expect(box.size.height, equals(drawerHeight - 2 * 16.0 - 1.0)); // Header divider thickness is 1.0 in Material 3.
105+
106+
expect(find.text('header'), findsOneWidget);
107+
});
108+
61109
testWidgetsWithLeakTracking('Drawer dismiss barrier has label', (WidgetTester tester) async {
62110
final SemanticsTester semantics = SemanticsTester(tester);
63111
await tester.pumpWidget(
@@ -570,7 +618,7 @@ void main() {
570618
expect(box.size.width, equals(smallWidth));
571619
});
572620

573-
testWidgetsWithLeakTracking('Drawer default shape (ltr)', (WidgetTester tester) async {
621+
testWidgetsWithLeakTracking('Material3 - Drawer default shape (ltr)', (WidgetTester tester) async {
574622
await tester.pumpWidget(
575623
MaterialApp(
576624
theme: ThemeData(useMaterial3: true),
@@ -630,7 +678,7 @@ void main() {
630678
);
631679
});
632680

633-
testWidgetsWithLeakTracking('Drawer default shape (rtl)', (WidgetTester tester) async {
681+
testWidgetsWithLeakTracking('Material3 - Drawer default shape (rtl)', (WidgetTester tester) async {
634682
await tester.pumpWidget(
635683
MaterialApp(
636684
theme: ThemeData(useMaterial3: true),
@@ -690,7 +738,7 @@ void main() {
690738
);
691739
});
692740

693-
testWidgetsWithLeakTracking('Drawer clip behavior', (WidgetTester tester) async {
741+
testWidgetsWithLeakTracking('Material3 - Drawer clip behavior', (WidgetTester tester) async {
694742
await tester.pumpWidget(
695743
MaterialApp(
696744
theme: ThemeData(useMaterial3: true),
@@ -746,7 +794,7 @@ void main() {
746794
// support is deprecated and the APIs are removed, these tests
747795
// can be deleted.
748796

749-
testWidgetsWithLeakTracking('Drawer default shape', (WidgetTester tester) async {
797+
testWidgetsWithLeakTracking('Material2 - Drawer default shape', (WidgetTester tester) async {
750798
await tester.pumpWidget(
751799
MaterialApp(
752800
theme: ThemeData(useMaterial3: false),
@@ -787,7 +835,7 @@ void main() {
787835
expect(material.shape, null);
788836
});
789837

790-
testWidgetsWithLeakTracking('Drawer clip behavior', (WidgetTester tester) async {
838+
testWidgetsWithLeakTracking('Material2 - Drawer clip behavior', (WidgetTester tester) async {
791839
await tester.pumpWidget(
792840
MaterialApp(
793841
theme: ThemeData(useMaterial3: false),

0 commit comments

Comments
 (0)