File size: 3,642 Bytes
b91a53d 9fc1476 b91a53d 9fc1476 b91a53d | 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 89 90 91 | // Copyright 2014 The Flutter Authors. 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:flutter/material.dart';
import 'package:flutter_api_samples/widgets/autocomplete/raw_autocomplete.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Form is entirely visible and rejects invalid responses', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('RawAutocomplete Form'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(2));
expect(find.byIcon(Icons.arrow_downward), findsOneWidget);
expect(find.text('This is a regular DropdownButtonFormField'), findsOneWidget);
expect(find.text('This is a regular TextFormField'), findsOneWidget);
expect(find.text('This is a RawAutocomplete!'), findsOneWidget);
expect(find.text('Submit'), findsOneWidget);
expect(find.text('One'), findsNothing);
expect(find.text('Two'), findsNothing);
expect(find.text('Free'), findsNothing);
expect(find.text('Four'), findsNothing);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
expect(find.text('Must make a selection.'), findsNothing);
expect(find.text("Can't be empty."), findsNothing);
expect(find.text('Nothing selected.'), findsNothing);
await tester.tap(find.text('Submit'));
await tester.pump();
expect(find.text('Must make a selection.'), findsOneWidget);
expect(find.text("Can't be empty."), findsOneWidget);
expect(find.text('Nothing selected.'), findsOneWidget);
});
testWidgets('Form accepts valid inputs', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
await tester.tap(find.byIcon(Icons.arrow_downward));
await tester.pump();
expect(find.text('One'), findsOneWidget);
expect(find.text('Two'), findsOneWidget);
expect(find.text('Free'), findsOneWidget);
expect(find.text('Four'), findsOneWidget);
await tester.tap(find.text('Free'));
await tester.pump();
expect(find.text('Two'), findsNothing);
expect(find.text('Free'), findsOneWidget);
expect(find.text('This is a regular TextFormField'), findsOneWidget);
await tester.enterText(
find.ancestor(
of: find.text('This is a regular TextFormField'),
matching: find.byType(TextFormField),
),
'regular user input',
);
await tester.tap(
find.ancestor(
of: find.text('This is a RawAutocomplete!'),
matching: find.byType(TextFormField),
),
);
await tester.pump();
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
await tester.tap(find.text('aardvark'));
await tester.pump();
expect(find.byType(AlertDialog), findsNothing);
await tester.tap(find.text('Submit'));
await tester.pump();
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.text('Successfully submitted'), findsOneWidget);
expect(find.text('DropdownButtonFormField: "Free"'), findsOneWidget);
expect(find.text('TextFormField: "regular user input"'), findsOneWidget);
expect(find.text('RawAutocomplete: "aardvark"'), findsOneWidget);
expect(find.text('Ok'), findsOneWidget);
await tester.tap(find.text('Ok'));
await tester.pump();
expect(find.byType(AlertDialog), findsNothing);
});
}
|