Skip to content

Commit abad372

Browse files
authored
Test raw autocomplete api examples (#148234)
Part of #130459.
1 parent 84876e5 commit abad372

File tree

5 files changed

+275
-4
lines changed

5 files changed

+275
-4
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ final Set<String> _knownMissingTests = <String>{
364364
'examples/api/test/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1_test.dart',
365365
'examples/api/test/rendering/scroll_direction/scroll_direction.0_test.dart',
366366
'examples/api/test/painting/star_border/star_border.0_test.dart',
367-
'examples/api/test/widgets/autocomplete/raw_autocomplete.focus_node.0_test.dart',
368-
'examples/api/test/widgets/autocomplete/raw_autocomplete.2_test.dart',
369-
'examples/api/test/widgets/autocomplete/raw_autocomplete.1_test.dart',
370-
'examples/api/test/widgets/autocomplete/raw_autocomplete.0_test.dart',
371367
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',
372368
'examples/api/test/widgets/navigator/navigator.0_test.dart',
373369
'examples/api/test/widgets/navigator/navigator.restorable_push.0_test.dart',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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/widgets/autocomplete/raw_autocomplete.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Autocomplete example is visible', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.AutocompleteExampleApp());
12+
expect(find.text('RawAutocomplete Basic'), findsOneWidget);
13+
expect(find.byType(TextFormField), findsOneWidget);
14+
15+
expect(find.text('aardvark'), findsNothing);
16+
expect(find.text('bobcat'), findsNothing);
17+
expect(find.text('chameleon'), findsNothing);
18+
});
19+
20+
testWidgets('Options are shown correctly and selectable', (WidgetTester tester) async {
21+
await tester.pumpWidget(const example.AutocompleteExampleApp());
22+
await tester.tap(find.byType(TextFormField));
23+
await tester.pump();
24+
25+
expect(find.byType(ListTile), findsNWidgets(3));
26+
expect(find.text('aardvark'), findsOneWidget);
27+
expect(find.text('bobcat'), findsOneWidget);
28+
expect(find.text('chameleon'), findsOneWidget);
29+
30+
await tester.enterText(find.byType(TextFormField), 'b');
31+
await tester.pump();
32+
33+
expect(find.byType(ListTile), findsOneWidget);
34+
expect(find.text('aardvark'), findsNothing);
35+
expect(find.text('bobcat'), findsOneWidget);
36+
expect(find.text('chameleon'), findsNothing);
37+
38+
await tester.tap(find.text('bobcat'));
39+
await tester.pump();
40+
41+
expect(find.byType(ListTile), findsNothing);
42+
expect(find.descendant(
43+
of: find.byType(TextFormField),
44+
matching: find.text('bobcat'),
45+
), findsOneWidget);
46+
});
47+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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/widgets/autocomplete/raw_autocomplete.1.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Autocomplete example is visible', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.AutocompleteExampleApp());
12+
expect(find.text('RawAutocomplete Custom Type'), findsOneWidget);
13+
expect(find.byType(TextFormField), findsOneWidget);
14+
15+
expect(find.text('Alice'), findsNothing);
16+
expect(find.text('Bob'), findsNothing);
17+
expect(find.text('Charlie'), findsNothing);
18+
});
19+
20+
testWidgets('Options are shown correctly and selectable', (WidgetTester tester) async {
21+
await tester.pumpWidget(const example.AutocompleteExampleApp());
22+
await tester.tap(find.byType(TextFormField));
23+
await tester.pump();
24+
25+
expect(find.byType(ListTile), findsNWidgets(3));
26+
expect(find.text('Alice'), findsOneWidget);
27+
expect(find.text('Bob'), findsOneWidget);
28+
expect(find.text('Charlie'), findsOneWidget);
29+
30+
await tester.enterText(find.byType(TextFormField), 'b');
31+
await tester.pump();
32+
33+
expect(find.byType(ListTile), findsOneWidget);
34+
expect(find.text('Alice'), findsNothing);
35+
expect(find.text('Bob'), findsOneWidget);
36+
expect(find.text('Charlie'), findsNothing);
37+
38+
await tester.tap(find.text('Bob'));
39+
await tester.pump();
40+
41+
expect(find.byType(ListTile), findsNothing);
42+
expect(find.descendant(
43+
of: find.byType(TextFormField),
44+
matching: find.text('Bob'),
45+
), findsOneWidget);
46+
});
47+
48+
testWidgets('Finds users by email address', (WidgetTester tester) async {
49+
await tester.pumpWidget(const example.AutocompleteExampleApp());
50+
51+
await tester.enterText(find.byType(TextFormField), '@');
52+
await tester.pump();
53+
54+
expect(find.byType(ListTile), findsNWidgets(3));
55+
expect(find.text('Alice'), findsOneWidget);
56+
expect(find.text('Bob'), findsOneWidget);
57+
expect(find.text('Charlie'), findsOneWidget);
58+
59+
await tester.enterText(find.byType(TextFormField), '@gmail');
60+
await tester.pump();
61+
62+
expect(find.byType(ListTile), findsOneWidget);
63+
expect(find.text('Alice'), findsNothing);
64+
expect(find.text('Bob'), findsNothing);
65+
expect(find.text('Charlie'), findsOneWidget);
66+
67+
await tester.tap(find.text('Charlie'));
68+
await tester.pump();
69+
70+
expect(find.byType(ListTile), findsNothing);
71+
expect(find.descendant(
72+
of: find.byType(TextFormField),
73+
matching: find.text('Charlie'),
74+
), findsOneWidget);
75+
});
76+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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/widgets/autocomplete/raw_autocomplete.2.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Form is entirely visible and rejects invalid responses', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.AutocompleteExampleApp());
12+
expect(find.text('RawAutocomplete Form'), findsOneWidget);
13+
expect(find.byType(TextFormField), findsNWidgets(2));
14+
expect(find.byIcon(Icons.arrow_downward), findsOneWidget);
15+
expect(find.text('This is a regular DropdownButtonFormField'), findsOneWidget);
16+
expect(find.text('This is a regular TextFormField'), findsOneWidget);
17+
expect(find.text('This is a RawAutocomplete!'), findsOneWidget);
18+
expect(find.text('Submit'), findsOneWidget);
19+
20+
expect(find.text('One'), findsNothing);
21+
expect(find.text('Two'), findsNothing);
22+
expect(find.text('Free'), findsNothing);
23+
expect(find.text('Four'), findsNothing);
24+
expect(find.text('aardvark'), findsNothing);
25+
expect(find.text('bobcat'), findsNothing);
26+
expect(find.text('chameleon'), findsNothing);
27+
28+
expect(find.text('Must make a selection.'), findsNothing);
29+
expect(find.text("Can't be empty."), findsNothing);
30+
expect(find.text('Nothing selected.'), findsNothing);
31+
await tester.tap(find.text('Submit'));
32+
await tester.pump();
33+
expect(find.text('Must make a selection.'), findsOneWidget);
34+
expect(find.text("Can't be empty."), findsOneWidget);
35+
expect(find.text('Nothing selected.'), findsOneWidget);
36+
});
37+
38+
testWidgets('Form accepts valid inputs', (WidgetTester tester) async {
39+
await tester.pumpWidget(const example.AutocompleteExampleApp());
40+
await tester.tap(find.byIcon(Icons.arrow_downward));
41+
await tester.pump();
42+
43+
expect(find.text('One'), findsOneWidget);
44+
expect(find.text('Two'), findsOneWidget);
45+
expect(find.text('Free'), findsOneWidget);
46+
expect(find.text('Four'), findsOneWidget);
47+
await tester.tap(find.text('Free'));
48+
await tester.pump();
49+
expect(find.text('Two'), findsNothing);
50+
expect(find.text('Free'), findsOneWidget);
51+
52+
expect(find.text('This is a regular TextFormField'), findsOneWidget);
53+
await tester.enterText(
54+
find.ancestor(
55+
of: find.text('This is a regular TextFormField'),
56+
matching: find.byType(TextFormField),
57+
),
58+
'regular user input',
59+
);
60+
61+
await tester.tap(find.ancestor(
62+
of: find.text('This is a RawAutocomplete!'),
63+
matching: find.byType(TextFormField),
64+
));
65+
await tester.pump();
66+
expect(find.text('aardvark'), findsOneWidget);
67+
expect(find.text('bobcat'), findsOneWidget);
68+
expect(find.text('chameleon'), findsOneWidget);
69+
await tester.tap(find.text('aardvark'));
70+
await tester.pump();
71+
72+
expect(find.byType(AlertDialog), findsNothing);
73+
await tester.tap(find.text('Submit'));
74+
await tester.pump();
75+
expect(find.byType(AlertDialog), findsOneWidget);
76+
expect(find.text('Successfully submitted'), findsOneWidget);
77+
expect(find.text('DropdownButtonFormField: "Free"'), findsOneWidget);
78+
expect(find.text('TextFormField: "regular user input"'), findsOneWidget);
79+
expect(find.text('RawAutocomplete: "aardvark"'), findsOneWidget);
80+
expect(find.text('Ok'), findsOneWidget);
81+
82+
await tester.tap(find.text('Ok'));
83+
await tester.pump();
84+
expect(find.byType(AlertDialog), findsNothing);
85+
});
86+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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/widgets/autocomplete/raw_autocomplete.focus_node.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Autocomplete example is visible', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.AutocompleteExampleApp());
12+
expect(find.text('Split RawAutocomplete App'), findsOneWidget);
13+
expect(find.byType(AppBar), findsOneWidget);
14+
expect(find.byType(TextFormField), findsOneWidget);
15+
expect(
16+
find.descendant(
17+
of: find.byType(AppBar),
18+
matching: find.byType(TextFormField)
19+
),
20+
findsOneWidget,
21+
);
22+
23+
expect(find.byType(RawAutocomplete<String>), findsOneWidget);
24+
expect(find.text('aardvark'), findsNothing);
25+
expect(find.text('bobcat'), findsNothing);
26+
expect(find.text('chameleon'), findsNothing);
27+
expect(
28+
find.ancestor(
29+
matching: find.byType(AppBar),
30+
of: find.byType(RawAutocomplete)
31+
),
32+
findsNothing,
33+
);
34+
});
35+
36+
testWidgets('Options are shown correctly and selectable', (WidgetTester tester) async {
37+
await tester.pumpWidget(const example.AutocompleteExampleApp());
38+
await tester.tap(find.byType(TextFormField));
39+
await tester.pump();
40+
41+
expect(find.byType(ListTile), findsNWidgets(3));
42+
expect(find.text('aardvark'), findsOneWidget);
43+
expect(find.text('bobcat'), findsOneWidget);
44+
expect(find.text('chameleon'), findsOneWidget);
45+
46+
await tester.enterText(find.byType(TextFormField), 'b');
47+
await tester.pump();
48+
49+
expect(find.byType(ListTile), findsOneWidget);
50+
expect(find.text('aardvark'), findsNothing);
51+
expect(find.text('bobcat'), findsOneWidget);
52+
expect(find.text('chameleon'), findsNothing);
53+
54+
await tester.tap(find.text('bobcat'));
55+
await tester.pump();
56+
57+
expect(find.byType(ListTile), findsNothing);
58+
expect(
59+
find.descendant(
60+
of: find.byType(TextFormField),
61+
matching: find.text('bobcat'),
62+
),
63+
findsOneWidget,
64+
);
65+
});
66+
}

0 commit comments

Comments
 (0)