Add test for navigation_rail.extended_animation.0_test.dart (#157222)

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

It adds a test for
- `examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart`
This commit is contained in:
Valentin Vignal 2024-10-22 11:55:21 +08:00 committed by GitHub
parent b2ca7ebb59
commit 27f0c6a08e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 1 deletions

View File

@ -312,7 +312,6 @@ final Set<String> _knownMissingTests = <String>{
'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',
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
'examples/api/test/painting/star_border/star_border.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push.0_test.dart',

View File

@ -0,0 +1,65 @@
// 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/navigation_rail/navigation_rail.extended_animation.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Navigation rail animates itself between the normal and extended state',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.ExtendedAnimationExampleApp(),
);
expect(find.text('Tap on FloatingActionButton to expand'), findsOne);
expect(find.widgetWithIcon(FloatingActionButton, Icons.add), findsOne);
expect(find.byIcon(Icons.favorite), findsOne);
expect(find.text('First'), findsOne);
expect(find.byIcon(Icons.bookmark_border), findsOne);
expect(find.text('Second'), findsOne);
expect(find.byIcon(Icons.star_border), findsOne);
expect(find.text('First'), findsOne);
// The navigation rail should be in the normal state.
expect(
tester.getCenter(find.byType(FloatingActionButton)),
offsetMoreOrLessEquals(const Offset(40, 36), epsilon: 0.1),
);
expect(find.widgetWithText(FloatingActionButton, 'CREATE'), findsNothing);
// Expand the navigation rail.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
await tester.pump(kThemeAnimationDuration * 0.5);
expect(
tester.getCenter(find.byType(FloatingActionButton)),
offsetMoreOrLessEquals(const Offset(128.1, 36), epsilon: 0.1),
);
await tester.pump(kThemeAnimationDuration * 0.5);
expect(
tester.getCenter(find.byType(FloatingActionButton)),
offsetMoreOrLessEquals(const Offset(132, 36), epsilon: 0.1),
);
expect(find.widgetWithText(FloatingActionButton, 'CREATE'), findsOne);
// Collapse the navigation rail.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
await tester.pump(kThemeAnimationDuration * 0.5);
expect(
tester.getCenter(find.byType(FloatingActionButton)),
offsetMoreOrLessEquals(const Offset(128.1, 36), epsilon: 0.1),
);
await tester.pump(kThemeAnimationDuration * 0.5);
expect(
tester.getCenter(find.byType(FloatingActionButton)),
offsetMoreOrLessEquals(const Offset(40, 36), epsilon: 0.1),
);
expect(find.widgetWithText(FloatingActionButton, 'CREATE'), findsNothing);
});
}