Skip to content

Commit aad70e5

Browse files
Add tests for scaffold drawer and end drawer (#149383)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/material/scaffold/scaffold.drawer.0.dart` - `examples/api/lib/material/scaffold/scaffold.end_drawer.0.dart`
1 parent f05095e commit aad70e5

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,6 @@ final Set<String> _knownMissingTests = <String>{
342342
'examples/api/test/material/search_anchor/search_anchor.2_test.dart',
343343
'examples/api/test/material/about/about_list_tile.0_test.dart',
344344
'examples/api/test/material/selection_area/selection_area.0_test.dart',
345-
'examples/api/test/material/scaffold/scaffold.end_drawer.0_test.dart',
346-
'examples/api/test/material/scaffold/scaffold.drawer.0_test.dart',
347345
'examples/api/test/material/scaffold/scaffold_messenger.of.0_test.dart',
348346
'examples/api/test/material/scaffold/scaffold_messenger.0_test.dart',
349347
'examples/api/test/material/scaffold/scaffold_state.show_bottom_sheet.0_test.dart',
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/material/scaffold/scaffold.drawer.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('The page should contain a drawer than can be opened and closed', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.DrawerExampleApp(),
13+
);
14+
15+
expect(find.byType(Drawer), findsNothing);
16+
17+
// Open the drawer by tapping the button at the center of the screen.
18+
await tester.tap(find.widgetWithText(ElevatedButton, 'Open Drawer'));
19+
await tester.pumpAndSettle();
20+
21+
expect(find.byType(Drawer), findsOne);
22+
expect(tester.getCenter(
23+
find.byType(Drawer)).dx,
24+
lessThan(400),
25+
reason: 'The drawer should be on the left side of the screen',
26+
);
27+
expect(find.text('This is the Drawer'), findsOne);
28+
29+
// Close the drawer by tapping the button inside the drawer.
30+
await tester.tap(find.widgetWithText(ElevatedButton, 'Close Drawer'));
31+
await tester.pumpAndSettle();
32+
33+
expect(find.byType(Drawer), findsNothing);
34+
35+
// Open the drawer by tapping the drawer button in the app bar.
36+
expect(tester.getCenter(
37+
find.byType(DrawerButton)).dx,
38+
lessThan(400),
39+
reason: 'The drawer button should be on the left side of the app bar',
40+
);
41+
await tester.tap(find.byType(DrawerButton));
42+
await tester.pumpAndSettle();
43+
44+
expect(find.byType(Drawer), findsOne);
45+
expect(find.text('This is the Drawer'), findsOne);
46+
47+
// Close the drawer by tapping outside the drawer.
48+
final Rect drawerRect = tester.getRect(find.byType(Drawer));
49+
final Offset outsideDrawer = drawerRect.centerRight + const Offset(50, 0);
50+
await tester.tapAt(outsideDrawer);
51+
await tester.pumpAndSettle();
52+
53+
expect(find.byType(Drawer), findsNothing);
54+
});
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/material/scaffold/scaffold.end_drawer.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('The page should contain an end drawer than can be opened and closed', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.EndDrawerExampleApp(),
13+
);
14+
15+
expect(find.byType(Drawer), findsNothing);
16+
17+
// Open the drawer by tapping the button at the center of the screen.
18+
await tester.tap(find.widgetWithText(ElevatedButton, 'Open End Drawer'));
19+
await tester.pumpAndSettle();
20+
21+
expect(find.byType(Drawer), findsOne);
22+
expect(tester.getCenter(
23+
find.byType(Drawer)).dx,
24+
greaterThan(400),
25+
reason: 'The drawer should be on the right side of the screen',
26+
);
27+
expect(find.text('This is the Drawer'), findsOne);
28+
29+
// Close the drawer by tapping the button inside the drawer.
30+
await tester.tap(find.widgetWithText(ElevatedButton, 'Close Drawer'));
31+
await tester.pumpAndSettle();
32+
33+
expect(find.byType(Drawer), findsNothing);
34+
35+
// Open the drawer by tapping the drawer button in the app bar.
36+
expect(tester.getCenter(
37+
find.byType(EndDrawerButton)).dx,
38+
greaterThan(400),
39+
reason: 'The drawer button should be on the right side of the app bar',
40+
);
41+
await tester.tap(find.byType(EndDrawerButton));
42+
await tester.pumpAndSettle();
43+
44+
expect(find.byType(Drawer), findsOne);
45+
expect(find.text('This is the Drawer'), findsOne);
46+
47+
// Close the drawer by tapping outside the drawer.
48+
final Rect drawerRect = tester.getRect(find.byType(Drawer));
49+
final Offset outsideDrawer = drawerRect.centerLeft - const Offset(50, 0);
50+
await tester.tapAt(outsideDrawer);
51+
await tester.pumpAndSettle();
52+
53+
expect(find.byType(Drawer), findsNothing);
54+
});
55+
}

0 commit comments

Comments
 (0)