pesto_test.dart 2.24 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4 5 6
// Copyright 2016 The Chromium 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
import 'package:flutter_gallery/gallery/app.dart';
Hans Muller's avatar
Hans Muller committed
8 9

void main() {
10
  final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
11
  if (binding is LiveTestWidgetsFlutterBinding)
12
    binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
Hans Muller's avatar
Hans Muller committed
13

14 15 16
  // Regression test for https://github.com/flutter/flutter/pull/5168
  testWidgets('Pesto appbar heroics', (WidgetTester tester) async {
    await tester.pumpWidget(
17
      // The bug only manifests itself when the screen's orientation is portrait
18 19
      const Center(
        child: const SizedBox(
20 21
          width: 400.0,
          height: 800.0,
22
          child: const GalleryApp()
23 24 25 26 27 28 29 30 31 32
        )
      )
    );
    await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
    await tester.pump(); // triggers a frame

    await tester.tap(find.text('Pesto'));
    await tester.pump(); // Launch pesto
    await tester.pump(const Duration(seconds: 1)); // transition is complete

33
    await tester.tap(find.text('Pesto Bruschetta'));
34 35 36
    await tester.pump(); // Launch the recipe page
    await tester.pump(const Duration(seconds: 1)); // transition is complete

37
    await tester.drag(find.text('Pesto Bruschetta'), const Offset(0.0, -300.0));
38 39 40 41 42 43
    await tester.pump();

    Navigator.pop(find.byType(Scaffold).evaluate().single);
    await tester.pump();
    await tester.pump(const Duration(seconds: 1)); // transition is complete
  });
Ian Hickson's avatar
Ian Hickson committed
44 45

  testWidgets('Pesto can be scrolled all the way down', (WidgetTester tester) async {
46
    await tester.pumpWidget(const GalleryApp());
Ian Hickson's avatar
Ian Hickson committed
47 48 49 50 51 52 53
    await tester.pump(); // see https://github.com/flutter/flutter/issues/1865

    await tester.tap(find.text('Pesto'));
    await tester.pump(); // Launch pesto
    await tester.pump(const Duration(seconds: 1)); // transition is complete

    await tester.fling(find.text('Pesto Bruschetta'), const Offset(0.0, -200.0), 10000.0);
54
    await tester.pumpAndSettle(); // start and finish fling
Ian Hickson's avatar
Ian Hickson committed
55 56
    expect(find.text('Sicilian-Style sardines'), findsOneWidget);
  });
Hans Muller's avatar
Hans Muller committed
57
}