|
| 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