mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.2 KiB
112 lines
4.2 KiB
2 years ago
|
import 'package:context_menus/email_button_page.dart';
|
||
|
import 'package:context_menus/main.dart';
|
||
2 years ago
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:flutter/foundation.dart';
|
||
|
import 'package:flutter/gestures.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter/services.dart';
|
||
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
||
|
import 'utils.dart';
|
||
|
|
||
|
void main() {
|
||
2 years ago
|
testWidgets('Selecting the email address shows a custom button',
|
||
|
(tester) async {
|
||
|
await tester.pumpWidget(const MyApp());
|
||
2 years ago
|
|
||
2 years ago
|
// Navigate to the EmailButtonPage example.
|
||
|
await tester.dragUntilVisible(
|
||
|
find.text(EmailButtonPage.title),
|
||
|
find.byType(ListView),
|
||
|
const Offset(0.0, -100.0),
|
||
|
);
|
||
|
await tester.pumpAndSettle();
|
||
|
await tester.tap(find.text(EmailButtonPage.title));
|
||
|
await tester.pumpAndSettle();
|
||
2 years ago
|
|
||
2 years ago
|
// Select the first word, then right click to show the context menu.
|
||
|
expect(find.byType(TextField), findsOneWidget);
|
||
|
await tester.tapAt(tester.getTopLeft(find.byType(EditableText)));
|
||
|
await tester.pumpAndSettle();
|
||
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
|
||
|
for (int i = 0; i < 6; i++) {
|
||
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||
|
}
|
||
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
|
||
|
await tester.pumpAndSettle();
|
||
|
final TestGesture gesture1 = await tester.startGesture(
|
||
|
textOffsetToPosition(tester, 4),
|
||
|
kind: PointerDeviceKind.mouse,
|
||
|
buttons: kSecondaryMouseButton,
|
||
|
);
|
||
|
await tester.pump();
|
||
|
await gesture1.up();
|
||
|
await gesture1.removePointer();
|
||
|
await tester.pumpAndSettle();
|
||
2 years ago
|
|
||
2 years ago
|
// The context menu is shown, but no email button appears.
|
||
|
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
|
||
|
expect(find.text('Send email'), findsNothing);
|
||
|
switch (defaultTargetPlatform) {
|
||
|
case TargetPlatform.iOS:
|
||
|
expect(
|
||
|
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(2));
|
||
|
case TargetPlatform.macOS:
|
||
|
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
|
||
|
findsNWidgets(2));
|
||
|
case TargetPlatform.android:
|
||
|
case TargetPlatform.fuchsia:
|
||
|
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(3));
|
||
|
case TargetPlatform.linux:
|
||
|
case TargetPlatform.windows:
|
||
|
expect(
|
||
|
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(3));
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
// Click on "Copy" to hide the context menu.
|
||
|
await tester.tap(find.text('Copy'));
|
||
|
await tester.pumpAndSettle();
|
||
|
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
|
||
2 years ago
|
|
||
2 years ago
|
// Select the email address, then right click it to show the context menu.
|
||
|
for (int i = 0; i < 38; i++) {
|
||
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||
|
}
|
||
|
await tester.pumpAndSettle();
|
||
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
|
||
|
for (int i = 0; i < 15; i++) {
|
||
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||
|
}
|
||
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
|
||
|
final TestGesture gesture2 = await tester.startGesture(
|
||
|
textOffsetToPosition(tester, 48),
|
||
|
kind: PointerDeviceKind.mouse,
|
||
|
buttons: kSecondaryMouseButton,
|
||
|
);
|
||
|
await tester.pump();
|
||
|
await gesture2.up();
|
||
|
await gesture2.removePointer();
|
||
|
await tester.pumpAndSettle();
|
||
2 years ago
|
|
||
2 years ago
|
// The context menu is shown, and the email button now appears.
|
||
|
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
|
||
|
expect(find.text('Send email'), findsOneWidget);
|
||
|
switch (defaultTargetPlatform) {
|
||
|
case TargetPlatform.iOS:
|
||
|
expect(
|
||
|
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(3));
|
||
|
case TargetPlatform.macOS:
|
||
|
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
|
||
|
findsNWidgets(3));
|
||
|
case TargetPlatform.android:
|
||
|
case TargetPlatform.fuchsia:
|
||
|
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(4));
|
||
|
case TargetPlatform.linux:
|
||
|
case TargetPlatform.windows:
|
||
|
expect(
|
||
|
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(4));
|
||
|
}
|
||
11 months ago
|
// TODO: Test failing on Flutter 3.18.0-7.0.pre.57 https://github.com/flutter/samples/issues/2110
|
||
|
}, skip: true);
|
||
2 years ago
|
}
|