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/date_picker/show_date_picker.1.dart' as example; |
7 | import 'package:flutter_test/flutter_test.dart'; |
8 | |
9 | void main() { |
10 | testWidgets('Can show date picker', (WidgetTester tester) async { |
11 | const String datePickerTitle = 'Select date'; |
12 | const String initialDate = 'Sun, Jul 25'; |
13 | |
14 | await tester.pumpWidget(const example.DatePickerApp()); |
15 | |
16 | // The date picker is not shown initially. |
17 | expect(find.text(datePickerTitle), findsNothing); |
18 | expect(find.text(initialDate), findsNothing); |
19 | |
20 | expect(find.text('No date selected'), findsOneWidget); |
21 | expect(find.byType(OutlinedButton), findsOneWidget); |
22 | |
23 | // Tap the button to show the date picker. |
24 | await tester.tap(find.byType(OutlinedButton)); |
25 | await tester.pumpAndSettle(); |
26 | |
27 | // The initial date is shown. |
28 | expect(find.text(datePickerTitle), findsOneWidget); |
29 | expect(find.text(initialDate), findsOneWidget); |
30 | |
31 | // Tap another date to select it. |
32 | await tester.tap(find.text('30')); |
33 | await tester.pumpAndSettle(); |
34 | |
35 | // The selected date is shown. |
36 | expect(find.text(datePickerTitle), findsOneWidget); |
37 | expect(find.text('Fri, Jul 30'), findsOneWidget); |
38 | |
39 | // Tap OK to confirm the selection and close the date picker. |
40 | await tester.tap(find.text('OK')); |
41 | await tester.pumpAndSettle(); |
42 | |
43 | // The date picker is closed and the selected date is shown. |
44 | expect(find.text(datePickerTitle), findsNothing); |
45 | expect(find.text('30/7/2021'), findsOneWidget); |
46 | }); |
47 | } |
48 |