mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Write tests for API examples of BottomNavigationBar and IconButton (#138188)
This PR writes tests for a few of the API examples (not all), as requested in #130459. For the test names, I used the existing tests in the `api` folder as guide.
This commit is contained in:
parent
9a930dd6f9
commit
ec639f359c
@ -338,13 +338,9 @@ final Set<String> _knownMissingTests = <String>{
|
|||||||
'examples/api/test/material/snack_bar/snack_bar.0_test.dart',
|
'examples/api/test/material/snack_bar/snack_bar.0_test.dart',
|
||||||
'examples/api/test/material/snack_bar/snack_bar.2_test.dart',
|
'examples/api/test/material/snack_bar/snack_bar.2_test.dart',
|
||||||
'examples/api/test/material/snack_bar/snack_bar.1_test.dart',
|
'examples/api/test/material/snack_bar/snack_bar.1_test.dart',
|
||||||
'examples/api/test/material/bottom_navigation_bar/bottom_navigation_bar.0_test.dart',
|
|
||||||
'examples/api/test/material/bottom_navigation_bar/bottom_navigation_bar.1_test.dart',
|
|
||||||
'examples/api/test/material/outlined_button/outlined_button.0_test.dart',
|
'examples/api/test/material/outlined_button/outlined_button.0_test.dart',
|
||||||
'examples/api/test/material/icon_button/icon_button.2_test.dart',
|
'examples/api/test/material/icon_button/icon_button.2_test.dart',
|
||||||
'examples/api/test/material/icon_button/icon_button.3_test.dart',
|
'examples/api/test/material/icon_button/icon_button.3_test.dart',
|
||||||
'examples/api/test/material/icon_button/icon_button.0_test.dart',
|
|
||||||
'examples/api/test/material/icon_button/icon_button.1_test.dart',
|
|
||||||
'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart',
|
'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart',
|
||||||
'examples/api/test/material/input_decorator/input_decoration.1_test.dart',
|
'examples/api/test/material/input_decorator/input_decoration.1_test.dart',
|
||||||
'examples/api/test/material/input_decorator/input_decoration.prefix_icon_constraints.0_test.dart',
|
'examples/api/test/material/input_decorator/input_decoration.prefix_icon_constraints.0_test.dart',
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
// 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/bottom_navigation_bar/bottom_navigation_bar.0.dart' as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.BottomNavigationBarExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.widgetWithText(AppBar, 'BottomNavigationBar Sample'), findsOneWidget);
|
||||||
|
expect(find.byType(BottomNavigationBar), findsOneWidget);
|
||||||
|
expect(find.widgetWithText(Center, 'Index 0: Home'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.business));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 1: Business'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.school));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 2: School'), findsOneWidget);
|
||||||
|
|
||||||
|
// Verify we can go back
|
||||||
|
await tester.tap(find.byIcon(Icons.home));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 0: Home'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
// 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/bottom_navigation_bar/bottom_navigation_bar.1.dart' as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.BottomNavigationBarExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.widgetWithText(AppBar, 'BottomNavigationBar Sample'), findsOneWidget);
|
||||||
|
expect(find.byType(BottomNavigationBar), findsOneWidget);
|
||||||
|
expect(find.widgetWithText(Center, 'Index 0: Home'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.business));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 1: Business'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.school));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 2: School'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.settings));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 3: Settings'), findsOneWidget);
|
||||||
|
|
||||||
|
// Verify we can go back
|
||||||
|
await tester.tap(find.byIcon(Icons.home));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.widgetWithText(Center, 'Index 0: Home'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
// 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/icon_button/icon_button.0.dart' as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('IconButton increments volume when tapped', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.IconButtonExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byIcon(Icons.volume_up), findsOneWidget);
|
||||||
|
expect(find.text('Volume : 0.0'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byType(IconButton));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Volume : 10.0'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('IconButton shows tooltip when long pressed', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.IconButtonExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.text('Increase volume by 10'), findsNothing);
|
||||||
|
await tester.longPress(find.byType(IconButton));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Increase volume by 10'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
// 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/icon_button/icon_button.1.dart' as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('IconButton', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.IconButtonExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byIcon(Icons.android), findsOneWidget);
|
||||||
|
final Ink ink = tester.widget<Ink>(
|
||||||
|
find.ancestor(
|
||||||
|
of: find.byIcon(Icons.android),
|
||||||
|
matching: find.byType(Ink),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final ShapeDecoration decoration = ink.decoration! as ShapeDecoration;
|
||||||
|
expect(decoration.color, Colors.lightBlue);
|
||||||
|
expect(decoration.shape, const CircleBorder());
|
||||||
|
|
||||||
|
final IconButton iconButton = ink.child! as IconButton;
|
||||||
|
expect(iconButton.color, Colors.white) ;
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user