Add Tests for bottom_app_bar api examples (#156501)

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

It adds a test for

`examples/api/test/material/bottom_app_bar/bottom_app_bar.1_test.dart` and
`examples/api/test/material/bottom_app_bar/bottom_app_bar.2_test.dart`

This are tests of snippets used in [AutofillGroup class](https://api.flutter.dev/flutter/widgets/AutofillGroup-class.html)
This commit is contained in:
Ildeberto Vasconcelos 2024-10-21 13:31:21 +01:00 committed by GitHub
parent 47035a0102
commit 8aa25aeff2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 165 additions and 2 deletions

View File

@ -309,8 +309,6 @@ class SampleChecker {
// TODO(gspencergoog): implement the missing tests.
// See https://github.com/flutter/flutter/issues/130459
final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/bottom_app_bar/bottom_app_bar.2_test.dart',
'examples/api/test/material/bottom_app_bar/bottom_app_bar.1_test.dart',
'examples/api/test/material/selectable_region/selectable_region.0_test.dart',
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',

View File

@ -0,0 +1,70 @@
// 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_app_bar/bottom_app_bar.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'BottomAppBarDemo shows FloatingActionButton and responds to toggle',
(WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
expect(find.byType(FloatingActionButton), findsOneWidget);
// Tap the 'Floating Action Button' switch to hide the FAB.
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();
expect(find.byType(FloatingActionButton), findsNothing);
},
);
testWidgets('Notch can be toggled on and off', (WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
// Check the BottomAppBar has a notch initially.
BottomAppBar bottomAppBar = tester.widget(find.byType(BottomAppBar));
expect(bottomAppBar.shape, isNotNull);
// Toggle the 'Notch' switch to remove the notch.
await tester.tap(find.byType(SwitchListTile).last);
await tester.pump();
bottomAppBar = tester.widget(find.byType(BottomAppBar));
expect(bottomAppBar.shape, isNull);
});
testWidgets('FAB location can be changed', (WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
final Offset initialPosition =
tester.getCenter(find.byType(FloatingActionButton));
// Verify the initial position is near the right side (docked to the end).
final Size screenSize = tester.getSize(
find.byType(Scaffold),
);
expect(
initialPosition.dx,
greaterThan(screenSize.width * 0.5),
);
// Tap the radio button to move the FAB to centerDocked.
await tester.tap(find.text('Docked - Center'));
await tester.pumpAndSettle();
// Get the new FAB position (centerDocked).
final Offset newPosition = tester.getCenter(
find.byType(FloatingActionButton),
);
expect(
newPosition.dx,
closeTo(screenSize.width * 0.5, 10), // Center of the screen.
);
});
}

View File

@ -0,0 +1,95 @@
// 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_app_bar/bottom_app_bar.2.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Floating Action Button visibility can be toggled',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomAppBarDemo(),
);
expect(find.byType(FloatingActionButton), findsOneWidget);
// Tap the switch to hide the FAB.
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();
expect(find.byType(FloatingActionButton), findsNothing);
},
);
testWidgets('BottomAppBar elevation can be toggled',
(WidgetTester tester) async {
// Build the app.
await tester.pumpWidget(const example.BottomAppBarDemo());
// Verify the BottomAppBar has elevation initially.
BottomAppBar bottomAppBar = tester.widget(
find.byType(BottomAppBar),
);
expect(bottomAppBar.elevation, isNot(0.0));
await tester.tap(find.text('Bottom App Bar Elevation'));
await tester.pumpAndSettle();
bottomAppBar = tester.widget(
find.byType(BottomAppBar),
);
expect(bottomAppBar.elevation, equals(0.0));
});
testWidgets(
'BottomAppBar hides on scroll down and shows on scroll up',
(WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
// Ensure the BottomAppBar is visible initially.
expect(find.byType(BottomAppBar), findsOneWidget);
// Scroll down to hide the BottomAppBar.
await tester.drag(
find.byType(ListView),
const Offset(0, -300),
);
await tester.pumpAndSettle();
// Verify the BottomAppBar is hidden.
final Size hiddenSize = tester.getSize(
find.byType(AnimatedContainer),
);
expect(hiddenSize.height, equals(0.0)); // AnimatedContainer's height
// Scroll up to show the BottomAppBar again.
await tester.drag(find.byType(ListView), const Offset(0, 300));
await tester.pumpAndSettle();
// Verify the BottomAppBar is visible again.
final Size visibleSize = tester.getSize(
find.byType(AnimatedContainer),
);
expect(visibleSize.height, equals(80.0));
},
);
testWidgets(
'SnackBar is shown when Open popup menu is pressed',
(WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
// Trigger the SnackBar.
await tester.tap(find.byTooltip('Open popup menu'));
await tester.pump();
expect(find.text('Yay! A SnackBar!'), findsOneWidget);
expect(find.text('Undo'), findsOneWidget);
},
);
}