simple_smoke_test.dart 2.61 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// 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';
6
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
7
import 'package:flutter_test/flutter_test.dart';
8 9

void main() {
10
  final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
11
  if (binding is LiveTestWidgetsFlutterBinding) {
12
    binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
13
  }
14 15

  testWidgets('Flutter Gallery app simple smoke test', (WidgetTester tester) async {
16 17 18
    await tester.pumpWidget(
      const GalleryApp(testMode: true) // builds the app and schedules a frame but doesn't trigger one
    );
19 20 21
    await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
    await tester.pump(); // triggers a frame

22
    final Finder showOptionsPageButton = find.byTooltip('Toggle options page');
23

24 25 26
    // Show the options page
    await tester.tap(showOptionsPageButton);
    await tester.pumpAndSettle();
27

28 29 30
    // Switch to the dark theme: the first switch control
    await tester.tap(find.byType(Switch).first);
    await tester.pumpAndSettle();
31

32 33 34 35
    // Close the options page
    expect(showOptionsPageButton, findsOneWidget);
    await tester.tap(showOptionsPageButton);
    await tester.pumpAndSettle();
36

37 38
    // Show the studies (aka "vignettes", aka "demos")
    await tester.tap(find.text('Studies'));
39
    await tester.pumpAndSettle();
40

41
    // Show the Contact profile demo and scroll it upwards
42
    await tester.tap(find.text('Contact profile'));
43
    await tester.pumpAndSettle();
44

45
    await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
46
    await tester.pump(const Duration(milliseconds: 200));
47
    await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
48
    await tester.pump(const Duration(milliseconds: 200));
49
    await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
50
    await tester.pump(const Duration(milliseconds: 200));
51
    await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
52
    await tester.pump(const Duration(milliseconds: 200));
53
    await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
54
    await tester.pump(const Duration(milliseconds: 200));
55
    await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
56 57 58
    await tester.pump(const Duration(milliseconds: 200));

    await tester.pump(const Duration(hours: 100)); // for testing
59
  }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.macOS }));
60
}