mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add test for selectable_region.0.dart
(#157258)
Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/test/material/selectable_region/selectable_region.0_test.dart`
This commit is contained in:
parent
ba1017d81e
commit
a484aa260b
@ -309,7 +309,6 @@ class SampleChecker {
|
||||
// TODO(gspencergoog): implement the missing tests.
|
||||
// See https://github.com/flutter/flutter/issues/130459
|
||||
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/painting/star_border/star_border.0_test.dart',
|
||||
|
@ -322,6 +322,8 @@ class _RenderSelectableAdapter extends RenderProxyBox with Selectable, Selection
|
||||
@override
|
||||
void dispose() {
|
||||
_geometry.dispose();
|
||||
_startHandle = null;
|
||||
_endHandle = null;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
// 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/services.dart';
|
||||
import 'package:flutter_api_samples/material/selectable_region/selectable_region.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> sendKeyCombination(
|
||||
WidgetTester tester,
|
||||
LogicalKeyboardKey key,
|
||||
) async {
|
||||
final LogicalKeyboardKey modifier = switch (defaultTargetPlatform) {
|
||||
TargetPlatform.iOS || TargetPlatform.macOS => LogicalKeyboardKey.meta,
|
||||
_ => LogicalKeyboardKey.control,
|
||||
};
|
||||
await tester.sendKeyDownEvent(modifier);
|
||||
await tester.sendKeyDownEvent(key);
|
||||
await tester.sendKeyUpEvent(key);
|
||||
await tester.sendKeyUpEvent(modifier);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
testWidgets('The icon can be selected with the text', (WidgetTester tester) async {
|
||||
String? clipboard;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
|
||||
if (methodCall.method == 'Clipboard.setData') {
|
||||
clipboard = (methodCall.arguments as Map<String, dynamic>)['text'] as String;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
addTearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, null);
|
||||
});
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.SelectableRegionExampleApp(),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.key)); // Focus the application.
|
||||
await tester.pump();
|
||||
|
||||
// Keyboard select all.
|
||||
await sendKeyCombination(tester,LogicalKeyboardKey.keyA);
|
||||
// Keyboard copy.
|
||||
await sendKeyCombination(tester,LogicalKeyboardKey.keyC);
|
||||
|
||||
expect(clipboard, 'SelectableRegion SampleSelect this iconCustom Text');
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
}
|
Loading…
Reference in New Issue
Block a user