|
| 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/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart' as example; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + testWidgets('ExpansionPanelList.radio can expand one item at the time', (WidgetTester tester) async { |
| 11 | + await tester.pumpWidget( |
| 12 | + const example.ExpansionPanelListRadioExampleApp(), |
| 13 | + ); |
| 14 | + |
| 15 | + expect(find.widgetWithText(AppBar, 'ExpansionPanelList.radio Sample'), findsOne); |
| 16 | + expect(find.byType(ExpansionPanelList), findsOne); |
| 17 | + for (int i = 0; i < 8; i++) { |
| 18 | + expect(find.widgetWithText(ListTile, 'Panel $i'), findsOne); |
| 19 | + } |
| 20 | + |
| 21 | + // The default expanded item is 2. |
| 22 | + for (int i = 0; i < 8; i++) { |
| 23 | + expect( |
| 24 | + tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(i)).isExpanded, |
| 25 | + i == 2, |
| 26 | + reason: 'Only the panel 2 should be expanded', |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + // Open all the panels one by one. |
| 31 | + for (int index = 0; index < 8; index++) { |
| 32 | + await tester.ensureVisible(find.byType(ExpandIcon).at(index)); |
| 33 | + await tester.tap(find.byType(ExpandIcon).at(index)); |
| 34 | + await tester.pumpAndSettle(); |
| 35 | + for (int i = 0; i < 8; i++) { |
| 36 | + expect( |
| 37 | + tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(i)).isExpanded, |
| 38 | + i == index, |
| 39 | + reason: 'Only the panel $index should be expanded', |
| 40 | + ); |
| 41 | + } |
| 42 | + } |
| 43 | + }); |
| 44 | +} |
0 commit comments