mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add tests for action_listener.0.dart (#150606)
Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/lib/widgets/actions/action_listener.0.dart`
This commit is contained in:
parent
ad6166a8b8
commit
af522e2a1f
@ -378,7 +378,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'examples/api/test/widgets/single_child_scroll_view/single_child_scroll_view.1_test.dart',
|
||||
'examples/api/test/widgets/single_child_scroll_view/single_child_scroll_view.0_test.dart',
|
||||
'examples/api/test/widgets/restoration/restoration_mixin.0_test.dart',
|
||||
'examples/api/test/widgets/actions/action_listener.0_test.dart',
|
||||
'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart',
|
||||
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
|
||||
'examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart',
|
||||
|
@ -0,0 +1,50 @@
|
||||
// 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/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/actions/action_listener.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('ActionListener can be enabled, triggered, and disabled', (WidgetTester tester) async {
|
||||
final List<String?> log = <String?>[];
|
||||
|
||||
final DebugPrintCallback originalDebugPrint = debugPrint;
|
||||
debugPrint = (String? message, {int? wrapWidth}) {
|
||||
log.add(message);
|
||||
};
|
||||
try {
|
||||
await tester.pumpWidget(
|
||||
const example.ActionListenerExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.widgetWithText(AppBar, 'ActionListener Sample'), findsOne);
|
||||
expect(find.widgetWithText(OutlinedButton, 'Enable'), findsOne);
|
||||
|
||||
await tester.tap(find.byType(OutlinedButton));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.widgetWithText(OutlinedButton, 'Disable'), findsOne);
|
||||
expect(find.widgetWithText(ElevatedButton, 'Call Action Listener'), findsOne);
|
||||
expect(log, const <String?>['Action Listener was added']);
|
||||
|
||||
await tester.tap(find.text('Call Action Listener'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.widgetWithText(SnackBar, 'Action Listener Called'), findsOne);
|
||||
|
||||
await tester.tap(find.text('Disable'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.widgetWithText(OutlinedButton, 'Enable'), findsOne);
|
||||
expect(
|
||||
log,
|
||||
const <String?>['Action Listener was added', 'Action Listener was removed'],
|
||||
);
|
||||
} finally {
|
||||
debugPrint = originalDebugPrint;
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user