Skip to content

Commit f2c48af

Browse files
Add test for icon_button.3.dart (#149988)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/material/icon_button/icon_button.3.dart`
1 parent b44c67e commit f2c48af

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

dev/bots/check_code_samples.dart

-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ final Set<String> _knownMissingTests = <String>{
324324
'examples/api/test/material/stepper/stepper.controls_builder.0_test.dart',
325325
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
326326
'examples/api/test/material/chip/deletable_chip_attributes.on_deleted.0_test.dart',
327-
'examples/api/test/material/icon_button/icon_button.3_test.dart',
328327
'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart',
329328
'examples/api/test/material/input_decorator/input_decoration.1_test.dart',
330329
'examples/api/test/material/input_decorator/input_decoration.prefix_icon_constraints.0_test.dart',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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/icon_button/icon_button.3.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('It should select and unselect the icon buttons', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.IconButtonToggleApp(),
13+
);
14+
15+
expect(find.widgetWithIcon(IconButton, Icons.settings_outlined), findsExactly(8));
16+
final Finder unselectedIconButtons = find.widgetWithIcon(IconButton, Icons.settings_outlined);
17+
for (int i = 0; i <= 6; i++) {
18+
final IconButton button = tester.widget<IconButton>(unselectedIconButtons.at(i));
19+
expect(button.onPressed, i.isEven ? isA<VoidCallback>() : isNull);
20+
expect(button.isSelected, isFalse);
21+
}
22+
23+
// Select the icons buttons.
24+
for (int i = 0; i <= 3; i++) {
25+
await tester.tap(unselectedIconButtons.at(2 * i));
26+
}
27+
await tester.pump();
28+
29+
expect(find.widgetWithIcon(IconButton, Icons.settings), findsExactly(8));
30+
final Finder selectedIconButtons = find.widgetWithIcon(IconButton, Icons.settings);
31+
for (int i = 0; i <= 6; i++) {
32+
final IconButton button = tester.widget<IconButton>(selectedIconButtons.at(i));
33+
expect(button.onPressed, i.isEven ? isA<VoidCallback>() : isNull);
34+
expect(button.isSelected, isTrue);
35+
}
36+
37+
// Unselect the icons buttons.
38+
for (int i = 0; i <= 3; i++) {
39+
await tester.tap(selectedIconButtons.at(2 * i));
40+
}
41+
await tester.pump();
42+
43+
expect(find.widgetWithIcon(IconButton, Icons.settings_outlined), findsExactly(8));
44+
for (int i = 0; i <= 6; i++) {
45+
final IconButton button = tester.widget<IconButton>(unselectedIconButtons.at(i));
46+
expect(button.onPressed, i.isEven ? isA<VoidCallback>() : isNull);
47+
expect(button.isSelected, isFalse);
48+
}
49+
});
50+
}

0 commit comments

Comments
 (0)