Skip to content

Commit b7997cb

Browse files
Add tests for scaffold messenger state (flutter#152735)
Contributes to flutter#130459 It adds a test for - `examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart` - `examples/api/lib/material/scaffold/scaffold_messenger_state.show_material_banner.0.dart`
1 parent 5c5b3c5 commit b7997cb

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,6 @@ final Set<String> _knownMissingTests = <String>{
320320
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
321321
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
322322
'examples/api/test/material/selection_area/selection_area.0_test.dart',
323-
'examples/api/test/material/scaffold/scaffold_messenger_state.show_material_banner.0_test.dart',
324-
'examples/api/test/material/scaffold/scaffold_messenger_state.show_snack_bar.0_test.dart',
325323
'examples/api/test/material/app_bar/sliver_app_bar.2_test.dart',
326324
'examples/api/test/material/app_bar/sliver_app_bar.3_test.dart',
327325
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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/scaffold/scaffold_messenger_state.show_material_banner.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Pressing the button should show a material banner', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.ShowMaterialBannerExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'ScaffoldMessengerState Sample'), findsOne);
16+
await tester.tap(find.widgetWithText(OutlinedButton, 'Show MaterialBanner'));
17+
await tester.pumpAndSettle();
18+
19+
expect(find.widgetWithText(MaterialBanner, 'This is a MaterialBanner'), findsOne);
20+
expect(
21+
find.descendant(of: find.byType(MaterialBanner), matching: find.widgetWithText(TextButton, 'DISMISS')),
22+
findsOne,
23+
);
24+
});
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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/scaffold/scaffold_messenger_state.show_snack_bar.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Pressing the button should display a snack bar', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.ShowSnackBarExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'ScaffoldMessengerState Sample'), findsOne);
16+
await tester.tap(find.widgetWithText(OutlinedButton, 'Show SnackBar'));
17+
await tester.pumpAndSettle();
18+
19+
expect(find.widgetWithText(SnackBar, 'A SnackBar has been shown.'), findsOne);
20+
});
21+
}

0 commit comments

Comments
 (0)