|
| 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/chip/deletable_chip_attributes.on_deleted.0.dart' as example; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + testWidgets('Chip.onDeleted can be used to delete chips', (WidgetTester tester) async { |
| 11 | + await tester.pumpWidget( |
| 12 | + const example.OnDeletedExampleApp(), |
| 13 | + ); |
| 14 | + |
| 15 | + expect(find.widgetWithText(AppBar, 'DeletableChipAttributes.onDeleted Sample'), findsOne); |
| 16 | + expect(find.widgetWithText(Chip, 'Aaron Burr'), findsOne); |
| 17 | + expect(find.widgetWithText(Chip, 'Alexander Hamilton'), findsOne); |
| 18 | + expect(find.widgetWithText(Chip, 'Eliza Hamilton'), findsOne); |
| 19 | + expect(find.widgetWithText(Chip, 'James Madison'), findsOne); |
| 20 | + |
| 21 | + Finder cancelIconFinder(String chipText) { |
| 22 | + return find.descendant( |
| 23 | + of: find.widgetWithText(Chip, chipText), |
| 24 | + matching: find.byIcon(Icons.cancel), |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + // Delete Alexander Hamilton. |
| 29 | + await tester.tap(cancelIconFinder('Alexander Hamilton')); |
| 30 | + await tester.pump(); |
| 31 | + |
| 32 | + expect(find.widgetWithText(Chip, 'Aaron Burr'), findsOne); |
| 33 | + expect(find.widgetWithText(Chip, 'Alexander Hamilton'), findsNothing); |
| 34 | + expect(find.widgetWithText(Chip, 'Eliza Hamilton'), findsOne); |
| 35 | + expect(find.widgetWithText(Chip, 'James Madison'), findsOne); |
| 36 | + |
| 37 | + // Delete James Madison. |
| 38 | + await tester.tap(cancelIconFinder('James Madison')); |
| 39 | + await tester.pump(); |
| 40 | + |
| 41 | + expect(find.widgetWithText(Chip, 'Aaron Burr'), findsOne); |
| 42 | + expect(find.widgetWithText(Chip, 'Alexander Hamilton'), findsNothing); |
| 43 | + expect(find.widgetWithText(Chip, 'Eliza Hamilton'), findsOne); |
| 44 | + expect(find.widgetWithText(Chip, 'James Madison'), findsNothing); |
| 45 | + |
| 46 | + // Delete Aaron Burr. |
| 47 | + await tester.tap(cancelIconFinder('Aaron Burr')); |
| 48 | + await tester.pump(); |
| 49 | + |
| 50 | + expect(find.widgetWithText(Chip, 'Aaron Burr'), findsNothing); |
| 51 | + expect(find.widgetWithText(Chip, 'Alexander Hamilton'), findsNothing); |
| 52 | + expect(find.widgetWithText(Chip, 'Eliza Hamilton'), findsOne); |
| 53 | + expect(find.widgetWithText(Chip, 'James Madison'), findsNothing); |
| 54 | + |
| 55 | + // Delete Eliza Hamilton. |
| 56 | + await tester.tap(cancelIconFinder('Eliza Hamilton')); |
| 57 | + await tester.pump(); |
| 58 | + |
| 59 | + expect(find.widgetWithText(Chip, 'Aaron Burr'), findsNothing); |
| 60 | + expect(find.widgetWithText(Chip, 'Alexander Hamilton'), findsNothing); |
| 61 | + expect(find.widgetWithText(Chip, 'Eliza Hamilton'), findsNothing); |
| 62 | + expect(find.widgetWithText(Chip, 'James Madison'), findsNothing); |
| 63 | + }); |
| 64 | +} |
0 commit comments