forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
1 parent
a227e6b
commit c4c0d97
Showing
4 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
examples/api/test/material/scaffold/scaffold_messenger.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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/scaffold/scaffold_messenger.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('The snack bar should be visible after tapping the button', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.ScaffoldMessengerExampleApp(), | ||
); | ||
|
||
expect(find.widgetWithText(AppBar, 'ScaffoldMessenger Sample'), findsOne); | ||
|
||
await tester.tap(find.widgetWithText(OutlinedButton, 'Show SnackBar')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.widgetWithText(SnackBar, 'A SnackBar has been shown.'), findsOne); | ||
}); | ||
} |
22 changes: 22 additions & 0 deletions
22
examples/api/test/material/scaffold/scaffold_messenger.of.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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/scaffold/scaffold_messenger.of.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('The snack bar should be visible after tapping the button', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.OfExampleApp(), | ||
); | ||
|
||
expect(find.widgetWithText(AppBar, 'ScaffoldMessenger.of Sample'), findsOne); | ||
|
||
await tester.tap(find.widgetWithText(ElevatedButton, 'SHOW A SNACKBAR')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.widgetWithText(SnackBar, 'Have a snack!'), findsOne); | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/api/test/material/scaffold/scaffold_messenger.of.1_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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/scaffold/scaffold_messenger.of.1.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('A snack bar is displayed after 10 taps', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.OfExampleApp(), | ||
); | ||
|
||
expect(find.widgetWithText(AppBar, 'ScaffoldMessenger Demo'), findsOne); | ||
expect(find.text('You have pushed the button this many times:'), findsOne); | ||
|
||
for (int i = 0; i < 9; i++) { | ||
await tester.tap(find.byType(FloatingActionButton)); | ||
await tester.pump(); | ||
expect(find.text('${i + 1}'), findsOne); | ||
} | ||
expect(find.byType(SnackBar), findsNothing); | ||
|
||
await tester.tap(find.byType(FloatingActionButton)); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('10'), findsOne); | ||
|
||
expect(find.widgetWithText(SnackBar, 'A multiple of ten!'), findsOne); | ||
}); | ||
} |