update_test.dart 1.79 KB
Newer Older
1 2 3 4 5
// 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_test/flutter_test.dart';
6
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
7 8 9 10 11 12 13

Future<String> mockUpdateUrlFetcher() {
  // A real implementation would connect to the network to retrieve this value
  return new Future<String>.value('http://www.example.com/');
}

void main() {
14
  final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
15
  if (binding is LiveTestWidgetsFlutterBinding)
16
    binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
17 18 19

  // Regression test for https://github.com/flutter/flutter/pull/5168
  testWidgets('update dialog', (WidgetTester tester) async {
20 21 22 23 24 25
    await tester.pumpWidget(
      const GalleryApp(
        testMode: true,
        updateUrlFetcher: mockUpdateUrlFetcher
      )
    );
26 27 28 29 30 31 32 33
    await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
    await tester.pump(); // triggers a frame

    expect(find.text('UPDATE'), findsOneWidget);

    await tester.tap(find.text('NO THANKS'));
    await tester.pump();

34
    await tester.tap(find.text('Studies'));
35
    await tester.pump(); // Launch
36 37
    await tester.pump(const Duration(seconds: 1)); // transition is complete

38
    final Finder backButton = find.byTooltip('Back');
39 40 41
    expect(backButton, findsOneWidget);
    await tester.tap(backButton);
    await tester.pump(); // Start the pop "back" operation.
42
    await tester.pump(); // Complete the willPop() Future.
43
    await tester.pump(const Duration(seconds: 1)); // transition is complete
44
    //await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1));
45 46 47 48

    expect(find.text('UPDATE'), findsNothing);
  });
}