Skip to content

Commit 99e201e

Browse files
Add test for search_anchor.0.dart (flutter#152371)
Contributes to flutter#130459 It adds a test for - `examples/api/lib/material/search_anchor/search_anchor.0.dart`
1 parent 1a8e57f commit 99e201e

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ final Set<String> _knownMissingTests = <String>{
319319
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
320320
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
321321
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
322-
'examples/api/test/material/search_anchor/search_anchor.0_test.dart',
323322
'examples/api/test/material/search_anchor/search_anchor.1_test.dart',
324323
'examples/api/test/material/search_anchor/search_anchor.2_test.dart',
325324
'examples/api/test/material/selection_area/selection_area.0_test.dart',
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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/search_anchor/search_anchor.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Search a color in the search bar and choosing an option changes the color scheme', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.SearchBarApp());
12+
13+
expect(find.widgetWithText(AppBar, 'Search Bar Sample'), findsOne);
14+
15+
expect(find.byWidgetPredicate((Widget widget) => widget is Card && widget.color ==const Color(0xff6750a4)), findsOne);
16+
17+
await tester.tap(find.byIcon(Icons.search));
18+
await tester.pumpAndSettle();
19+
20+
expect(find.text('No search history.'), findsOne);
21+
await tester.enterText(find.byType(SearchBar).last, 're');
22+
await tester.pump();
23+
24+
expect(find.widgetWithText(ListTile, 'red'), findsOne);
25+
expect(find.widgetWithText(ListTile, 'green'), findsOne);
26+
expect(find.widgetWithText(ListTile, 'grey'), findsOne);
27+
28+
await tester.tap(find.widgetWithText(ListTile, 'red'));
29+
await tester.pumpAndSettle();
30+
31+
expect(find.byWidgetPredicate((Widget widget) => widget is Card && widget.color ==const Color(0xff904a42)), findsOne);
32+
33+
await tester.tap(find.byIcon(Icons.search));
34+
await tester.pumpAndSettle();
35+
36+
await tester.tap(find.byIcon(Icons.close));
37+
await tester.pump();
38+
39+
expect(find.widgetWithText(ListTile, 'red'), findsOne, reason: 'The search history should be displayed');
40+
expect(find.widgetWithIcon(ListTile, Icons.history), findsOne);
41+
42+
await tester.enterText(find.byType(SearchBar).last, 'b');
43+
await tester.pump();
44+
45+
expect(find.widgetWithText(ListTile, 'blue'), findsOne);
46+
expect(find.widgetWithText(ListTile, 'beige'), findsOne);
47+
expect(find.widgetWithText(ListTile, 'brown'), findsOne);
48+
expect(find.widgetWithText(ListTile, 'black'), findsOne);
49+
50+
await tester.tap(find.widgetWithText(ListTile, 'blue'));
51+
await tester.pumpAndSettle();
52+
53+
expect(find.byWidgetPredicate((Widget widget) => widget is Card && widget.color ==const Color(0xff36618e)), findsOne);
54+
});
55+
}

0 commit comments

Comments
 (0)