Test raw autocomplete api examples (#148234)

Part of #130459.
This commit is contained in:
derdilla 2024-05-23 10:52:13 +02:00 committed by GitHub
parent 84876e58ce
commit abad37204e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 275 additions and 4 deletions

View File

@ -364,10 +364,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1_test.dart',
'examples/api/test/rendering/scroll_direction/scroll_direction.0_test.dart',
'examples/api/test/painting/star_border/star_border.0_test.dart',
'examples/api/test/widgets/autocomplete/raw_autocomplete.focus_node.0_test.dart',
'examples/api/test/widgets/autocomplete/raw_autocomplete.2_test.dart',
'examples/api/test/widgets/autocomplete/raw_autocomplete.1_test.dart',
'examples/api/test/widgets/autocomplete/raw_autocomplete.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',
'examples/api/test/widgets/navigator/navigator.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push.0_test.dart',

View File

@ -0,0 +1,47 @@
// 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.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Autocomplete example is visible', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('RawAutocomplete Basic'), findsOneWidget);
expect(find.byType(TextFormField), findsOneWidget);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
});
testWidgets('Options are shown correctly and selectable', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
await tester.tap(find.byType(TextFormField));
await tester.pump();
expect(find.byType(ListTile), findsNWidgets(3));
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
await tester.enterText(find.byType(TextFormField), 'b');
await tester.pump();
expect(find.byType(ListTile), findsOneWidget);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsNothing);
await tester.tap(find.text('bobcat'));
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(find.descendant(
of: find.byType(TextFormField),
matching: find.text('bobcat'),
), findsOneWidget);
});
}

View File

@ -0,0 +1,76 @@
// 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.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Autocomplete example is visible', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('RawAutocomplete Custom Type'), findsOneWidget);
expect(find.byType(TextFormField), findsOneWidget);
expect(find.text('Alice'), findsNothing);
expect(find.text('Bob'), findsNothing);
expect(find.text('Charlie'), findsNothing);
});
testWidgets('Options are shown correctly and selectable', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
await tester.tap(find.byType(TextFormField));
await tester.pump();
expect(find.byType(ListTile), findsNWidgets(3));
expect(find.text('Alice'), findsOneWidget);
expect(find.text('Bob'), findsOneWidget);
expect(find.text('Charlie'), findsOneWidget);
await tester.enterText(find.byType(TextFormField), 'b');
await tester.pump();
expect(find.byType(ListTile), findsOneWidget);
expect(find.text('Alice'), findsNothing);
expect(find.text('Bob'), findsOneWidget);
expect(find.text('Charlie'), findsNothing);
await tester.tap(find.text('Bob'));
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(find.descendant(
of: find.byType(TextFormField),
matching: find.text('Bob'),
), findsOneWidget);
});
testWidgets('Finds users by email address', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
await tester.enterText(find.byType(TextFormField), '@');
await tester.pump();
expect(find.byType(ListTile), findsNWidgets(3));
expect(find.text('Alice'), findsOneWidget);
expect(find.text('Bob'), findsOneWidget);
expect(find.text('Charlie'), findsOneWidget);
await tester.enterText(find.byType(TextFormField), '@gmail');
await tester.pump();
expect(find.byType(ListTile), findsOneWidget);
expect(find.text('Alice'), findsNothing);
expect(find.text('Bob'), findsNothing);
expect(find.text('Charlie'), findsOneWidget);
await tester.tap(find.text('Charlie'));
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(find.descendant(
of: find.byType(TextFormField),
matching: find.text('Charlie'),
), findsOneWidget);
});
}

View File

@ -0,0 +1,86 @@
// 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);
});
}

View File

@ -0,0 +1,66 @@
// 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.focus_node.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Autocomplete example is visible', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('Split RawAutocomplete App'), findsOneWidget);
expect(find.byType(AppBar), findsOneWidget);
expect(find.byType(TextFormField), findsOneWidget);
expect(
find.descendant(
of: find.byType(AppBar),
matching: find.byType(TextFormField)
),
findsOneWidget,
);
expect(find.byType(RawAutocomplete<String>), findsOneWidget);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
expect(
find.ancestor(
matching: find.byType(AppBar),
of: find.byType(RawAutocomplete)
),
findsNothing,
);
});
testWidgets('Options are shown correctly and selectable', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
await tester.tap(find.byType(TextFormField));
await tester.pump();
expect(find.byType(ListTile), findsNWidgets(3));
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
await tester.enterText(find.byType(TextFormField), 'b');
await tester.pump();
expect(find.byType(ListTile), findsOneWidget);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsNothing);
await tester.tap(find.text('bobcat'));
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(
find.descendant(
of: find.byType(TextFormField),
matching: find.text('bobcat'),
),
findsOneWidget,
);
});
}