|
| 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