Add test for expansion_panel_list.expansion_panel_list_radio.0_test.dart (#151730)

Contributes to https://github.com/flutter/flutter/issues/130459

It adds a test for
- `examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart`
This commit is contained in:
Valentin Vignal
2024-07-26 04:49:32 +08:00
committed by GitHub
parent f2c1c72d19
commit 1ec4907b40
2 changed files with 44 additions and 1 deletions

View File

@@ -321,7 +321,6 @@ final Set<String> _knownMissingTests = <String>{
'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/chip/deletable_chip_attributes.on_deleted.0_test.dart',
'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.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',

View File

@@ -0,0 +1,44 @@
// 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/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ExpansionPanelList.radio can expand one item at the time', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ExpansionPanelListRadioExampleApp(),
);
expect(find.widgetWithText(AppBar, 'ExpansionPanelList.radio Sample'), findsOne);
expect(find.byType(ExpansionPanelList), findsOne);
for (int i = 0; i < 8; i++) {
expect(find.widgetWithText(ListTile, 'Panel $i'), findsOne);
}
// The default expanded item is 2.
for (int i = 0; i < 8; i++) {
expect(
tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(i)).isExpanded,
i == 2,
reason: 'Only the panel 2 should be expanded',
);
}
// Open all the panels one by one.
for (int index = 0; index < 8; index++) {
await tester.ensureVisible(find.byType(ExpandIcon).at(index));
await tester.tap(find.byType(ExpandIcon).at(index));
await tester.pumpAndSettle();
for (int i = 0; i < 8; i++) {
expect(
tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(i)).isExpanded,
i == index,
reason: 'Only the panel $index should be expanded',
);
}
}
});
}