Skip to content

Commit

Permalink
Add test for search_anchor.0.dart (flutter#152371)
Browse files Browse the repository at this point in the history
Contributes to flutter#130459

It adds a test for
- `examples/api/lib/material/search_anchor/search_anchor.0.dart`
  • Loading branch information
ValentinVignal authored and TytaniumDev committed Aug 7, 2024
1 parent 133897a commit a227e6b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
1 change: 0 additions & 1 deletion dev/bots/check_code_samples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
'examples/api/test/material/search_anchor/search_anchor.0_test.dart',
'examples/api/test/material/search_anchor/search_anchor.1_test.dart',
'examples/api/test/material/search_anchor/search_anchor.2_test.dart',
'examples/api/test/material/selection_area/selection_area.0_test.dart',
Expand Down
55 changes: 55 additions & 0 deletions examples/api/test/material/search_anchor/search_anchor.0_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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/material/search_anchor/search_anchor.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('Search a color in the search bar and choosing an option changes the color scheme', (WidgetTester tester) async {
await tester.pumpWidget(const example.SearchBarApp());

expect(find.widgetWithText(AppBar, 'Search Bar Sample'), findsOne);

expect(find.byWidgetPredicate((Widget widget) => widget is Card && widget.color ==const Color(0xff6750a4)), findsOne);

await tester.tap(find.byIcon(Icons.search));
await tester.pumpAndSettle();

expect(find.text('No search history.'), findsOne);
await tester.enterText(find.byType(SearchBar).last, 're');
await tester.pump();

expect(find.widgetWithText(ListTile, 'red'), findsOne);
expect(find.widgetWithText(ListTile, 'green'), findsOne);
expect(find.widgetWithText(ListTile, 'grey'), findsOne);

await tester.tap(find.widgetWithText(ListTile, 'red'));
await tester.pumpAndSettle();

expect(find.byWidgetPredicate((Widget widget) => widget is Card && widget.color ==const Color(0xff904a42)), findsOne);

await tester.tap(find.byIcon(Icons.search));
await tester.pumpAndSettle();

await tester.tap(find.byIcon(Icons.close));
await tester.pump();

expect(find.widgetWithText(ListTile, 'red'), findsOne, reason: 'The search history should be displayed');
expect(find.widgetWithIcon(ListTile, Icons.history), findsOne);

await tester.enterText(find.byType(SearchBar).last, 'b');
await tester.pump();

expect(find.widgetWithText(ListTile, 'blue'), findsOne);
expect(find.widgetWithText(ListTile, 'beige'), findsOne);
expect(find.widgetWithText(ListTile, 'brown'), findsOne);
expect(find.widgetWithText(ListTile, 'black'), findsOne);

await tester.tap(find.widgetWithText(ListTile, 'blue'));
await tester.pumpAndSettle();

expect(find.byWidgetPredicate((Widget widget) => widget is Card && widget.color ==const Color(0xff36618e)), findsOne);
});
}

0 comments on commit a227e6b

Please sign in to comment.