pesto_test.dart 3.16 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 10 11 12 13 14 15 16 17 18 19

Finder byTooltip(WidgetTester tester, String message) {
  return find.byWidgetPredicate((Widget widget) {
    return widget is Tooltip && widget.message == message;
  });
}

Finder findNavigationMenuButton(WidgetTester tester) {
  return byTooltip(tester, 'Open navigation menu');
}

void main() {
20 21 22
  TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
  if (binding is LiveTestWidgetsFlutterBinding)
    binding.allowAllFrames = true;
Hans Muller's avatar
Hans Muller committed
23 24 25

  // Regression test for https://github.com/flutter/flutter/pull/5168
  testWidgets('Pesto route management', (WidgetTester tester) async {
26
    await tester.pumpWidget(new GalleryApp());
Hans Muller's avatar
Hans Muller committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
    await tester.pump(); // triggers a frame

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

    Future<Null> tapDrawerItem(String title) async {
      await tester.tap(findNavigationMenuButton(tester));
      await tester.pump();
      await tester.pump(const Duration(seconds: 1)); // drawer opening animation
      await tester.tap(find.text(title));
      await tester.pump();
      await tester.pump(const Duration(seconds: 1)); // drawer closing animation
      await tester.pump(); // maybe open a new page
      return tester.pump(const Duration(seconds: 1)); // new page transition
    }
    await tapDrawerItem('Home');
    await tapDrawerItem('Favorites');
    await tapDrawerItem('Home');
    await tapDrawerItem('Favorites');
    await tapDrawerItem('Home');
    await tapDrawerItem('Return to Gallery');

52
    expect(find.text('Flutter Gallery'), findsOneWidget);
Hans Muller's avatar
Hans Muller committed
53
  });
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

  // Regression test for https://github.com/flutter/flutter/pull/5168
  testWidgets('Pesto appbar heroics', (WidgetTester tester) async {
    await tester.pumpWidget(
      // The bug only manifests itself when the screen's orientation is portait
      new Center(
        child: new SizedBox(
          width: 400.0,
          height: 800.0,
          child: new GalleryApp()
        )
      )
    );
    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

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

    await tester.scroll(find.text('Pesto Bruchetta'), const Offset(0.0, -300.0));
    await tester.pump();

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