desktop_text_selection_toolbar_button_test.dart 1.28 KB
Newer Older
1 2 3 4 5 6
// 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/material.dart';
import 'package:flutter_test/flutter_test.dart';
7

8 9 10
void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

11
  testWidgets('can press', (WidgetTester tester) async {
12 13 14 15 16 17 18 19
    bool pressed = false;
    await tester.pumpWidget(
      MaterialApp(
        home: Center(
          child: DesktopTextSelectionToolbarButton(
            onPressed: () {
              pressed = true;
            },
20
            child: const Text('Tap me'),
21 22 23 24 25 26 27 28 29 30
          ),
        ),
      ),
    );

    expect(pressed, false);

    await tester.tap(find.byType(DesktopTextSelectionToolbarButton));
    expect(pressed, true);
  });
31

32
  testWidgets('passing null to onPressed disables the button', (WidgetTester tester) async {
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    await tester.pumpWidget(
      const MaterialApp(
        home: Center(
          child: DesktopTextSelectionToolbarButton(
            onPressed: null,
            child: Text('Cannot tap me'),
          ),
        ),
      ),
    );

    expect(find.byType(TextButton), findsOneWidget);
    final TextButton button = tester.widget(find.byType(TextButton));
    expect(button.enabled, isFalse);
  });
48
}