Skip to content

Commit 27e53c8

Browse files
Add tests for scaffold messenger examples (flutter#152536)
Contributes to flutter#130459 It adds a test for - `examples/api/lib/material/scaffold/scaffold_messenger.0.dart` - `examples/api/lib/material/scaffold/scaffold_messenger.of.0.dart` - `examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart`
1 parent 99e201e commit 27e53c8

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,8 @@ final Set<String> _knownMissingTests = <String>{
322322
'examples/api/test/material/search_anchor/search_anchor.1_test.dart',
323323
'examples/api/test/material/search_anchor/search_anchor.2_test.dart',
324324
'examples/api/test/material/selection_area/selection_area.0_test.dart',
325-
'examples/api/test/material/scaffold/scaffold_messenger.of.0_test.dart',
326-
'examples/api/test/material/scaffold/scaffold_messenger.0_test.dart',
327325
'examples/api/test/material/scaffold/scaffold_state.show_bottom_sheet.0_test.dart',
328326
'examples/api/test/material/scaffold/scaffold_messenger_state.show_material_banner.0_test.dart',
329-
'examples/api/test/material/scaffold/scaffold_messenger.of.1_test.dart',
330327
'examples/api/test/material/scaffold/scaffold_messenger_state.show_snack_bar.0_test.dart',
331328
'examples/api/test/material/app_bar/sliver_app_bar.2_test.dart',
332329
'examples/api/test/material/app_bar/sliver_app_bar.3_test.dart',
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('The snack bar should be visible after tapping the button', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.ScaffoldMessengerExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'ScaffoldMessenger Sample'), findsOne);
16+
17+
await tester.tap(find.widgetWithText(OutlinedButton, 'Show SnackBar'));
18+
await tester.pumpAndSettle();
19+
20+
expect(find.widgetWithText(SnackBar, 'A SnackBar has been shown.'), findsOne);
21+
});
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.of.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('The snack bar should be visible after tapping the button', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.OfExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'ScaffoldMessenger.of Sample'), findsOne);
16+
17+
await tester.tap(find.widgetWithText(ElevatedButton, 'SHOW A SNACKBAR'));
18+
await tester.pumpAndSettle();
19+
20+
expect(find.widgetWithText(SnackBar, 'Have a snack!'), findsOne);
21+
});
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.of.1.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('A snack bar is displayed after 10 taps', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.OfExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'ScaffoldMessenger Demo'), findsOne);
16+
expect(find.text('You have pushed the button this many times:'), findsOne);
17+
18+
for (int i = 0; i < 9; i++) {
19+
await tester.tap(find.byType(FloatingActionButton));
20+
await tester.pump();
21+
expect(find.text('${i + 1}'), findsOne);
22+
}
23+
expect(find.byType(SnackBar), findsNothing);
24+
25+
await tester.tap(find.byType(FloatingActionButton));
26+
await tester.pumpAndSettle();
27+
expect(find.text('10'), findsOne);
28+
29+
expect(find.widgetWithText(SnackBar, 'A multiple of ten!'), findsOne);
30+
});
31+
}

0 commit comments

Comments
 (0)