simple_smoke_test.dart 2.51 KB
Newer Older
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' show GalleryApp;
8 9

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

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

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

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

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

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

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

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

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

    await tester.pump(const Duration(hours: 100)); // for testing
  });
}