context_menu_controller.0_test.dart 1.66 KB
Newer Older
1 2 3 4
// 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.

5
import 'package:flutter/foundation.dart';
6 7
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
8
import 'package:flutter/services.dart';
9 10 11 12 13 14
import 'package:flutter_api_samples/material/context_menu/context_menu_controller.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('showing and hiding the custom context menu in the whole app', (WidgetTester tester) async {
    await tester.pumpWidget(
15
      const example.ContextMenuControllerExampleApp(),
16 17
    );

18 19
    expect(BrowserContextMenu.enabled, !kIsWeb);

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);

    // Right clicking the middle of the app shows the custom context menu.
    final Offset center = tester.getCenter(find.byType(Scaffold));
    final TestGesture gesture = await tester.startGesture(
      center,
      kind: PointerDeviceKind.mouse,
      buttons: kSecondaryMouseButton,
    );
    await tester.pump();
    await gesture.up();
    await tester.pumpAndSettle();

    expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
    expect(find.text('Print'), findsOneWidget);

    // Tap to dismiss.
    await tester.tapAt(center);
    await tester.pumpAndSettle();

    expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);

    // Long pressing also shows the custom context menu.
    await tester.longPressAt(center);

    expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
    expect(find.text('Print'), findsOneWidget);
  });
}