From 1ec4907b40cded7a28d695984afae36451c31406 Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Fri, 26 Jul 2024 04:49:32 +0800 Subject: [PATCH] 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` --- dev/bots/check_code_samples.dart | 1 - ...ist.expansion_panel_list_radio.0_test.dart | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 03ca6f1c8f..384fe25189 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -321,7 +321,6 @@ final Set _knownMissingTests = { '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', diff --git a/examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart b/examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart new file mode 100644 index 0000000000..403c006748 --- /dev/null +++ b/examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart @@ -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(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(find.byType(ExpandIcon).at(i)).isExpanded, + i == index, + reason: 'Only the panel $index should be expanded', + ); + } + } + }); +}