Fix and reenable context_menus email button test (#1585)

pull/1586/head
Parker Lougheed 2 years ago committed by GitHub
parent be309ecc07
commit 4ab7f6c36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,111 +10,109 @@ import 'package:flutter_test/flutter_test.dart';
import 'utils.dart'; import 'utils.dart';
void main() { void main() {
testWidgets( testWidgets('Selecting the email address shows a custom button',
'Selecting the email address shows a custom button', (tester) async {
(tester) async { await tester.pumpWidget(const MyApp());
await tester.pumpWidget(const MyApp());
// Navigate to the EmailButtonPage example. // Navigate to the EmailButtonPage example.
await tester.dragUntilVisible( await tester.dragUntilVisible(
find.text(EmailButtonPage.title), find.text(EmailButtonPage.title),
find.byType(ListView), find.byType(ListView),
const Offset(0.0, -200.0), const Offset(0.0, -100.0),
); );
await tester.tap(find.text(EmailButtonPage.title)); await tester.pumpAndSettle();
await tester.pumpAndSettle(); await tester.tap(find.text(EmailButtonPage.title));
await tester.pumpAndSettle();
// Select the first word, then right click to show the context menu. // Select the first word, then right click to show the context menu.
expect(find.byType(TextField), findsOneWidget); expect(find.byType(TextField), findsOneWidget);
await tester.tapAt(tester.getTopLeft(find.byType(EditableText))); await tester.tapAt(tester.getTopLeft(find.byType(EditableText)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift); await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
} }
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift); await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final TestGesture gesture1 = await tester.startGesture( final TestGesture gesture1 = await tester.startGesture(
textOffsetToPosition(tester, 4), textOffsetToPosition(tester, 4),
kind: PointerDeviceKind.mouse, kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton, buttons: kSecondaryMouseButton,
); );
await tester.pump(); await tester.pump();
await gesture1.up(); await gesture1.up();
await gesture1.removePointer(); await gesture1.removePointer();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The context menu is shown, but no email button appears. // The context menu is shown, but no email button appears.
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget); expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
expect(find.text('Send email'), findsNothing); expect(find.text('Send email'), findsNothing);
switch (defaultTargetPlatform) { switch (defaultTargetPlatform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
expect(find.byType(CupertinoTextSelectionToolbarButton), expect(
findsNWidgets(2)); find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(2));
break; break;
case TargetPlatform.macOS: case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton), expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(2)); findsNWidgets(2));
break; break;
case TargetPlatform.android: case TargetPlatform.android:
case TargetPlatform.fuchsia: case TargetPlatform.fuchsia:
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(3)); expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(3));
break; break;
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
expect( expect(
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(3)); find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(3));
break; break;
} }
// Click on "Copy" to hide the context menu. // Click on "Copy" to hide the context menu.
await tester.tap(find.text('Copy')); await tester.tap(find.text('Copy'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing); expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
// Select the email address, then right click it to show the context menu. // Select the email address, then right click it to show the context menu.
for (int i = 0; i < 38; i++) { for (int i = 0; i < 38; i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
} }
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift); await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
} }
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift); await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
final TestGesture gesture2 = await tester.startGesture( final TestGesture gesture2 = await tester.startGesture(
textOffsetToPosition(tester, 48), textOffsetToPosition(tester, 48),
kind: PointerDeviceKind.mouse, kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton, buttons: kSecondaryMouseButton,
); );
await tester.pump(); await tester.pump();
await gesture2.up(); await gesture2.up();
await gesture2.removePointer(); await gesture2.removePointer();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The context menu is shown, and the email button now appears. // The context menu is shown, and the email button now appears.
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget); expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
expect(find.text('Send email'), findsOneWidget); expect(find.text('Send email'), findsOneWidget);
switch (defaultTargetPlatform) { switch (defaultTargetPlatform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
expect(find.byType(CupertinoTextSelectionToolbarButton), expect(
findsNWidgets(3)); find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(3));
break; break;
case TargetPlatform.macOS: case TargetPlatform.macOS:
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton), expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
findsNWidgets(3)); findsNWidgets(3));
break; break;
case TargetPlatform.android: case TargetPlatform.android:
case TargetPlatform.fuchsia: case TargetPlatform.fuchsia:
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(4)); expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(4));
break; break;
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
expect( expect(
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(4)); find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(4));
break; break;
} }
}, });
skip: true, // TODO(justinmc): Make this test pass and re-enable.
);
} }

Loading…
Cancel
Save