about_test.dart 3.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
12
  testWidgets('AboutListTile control test', (WidgetTester tester) async {
13 14 15 16 17
    await tester.pumpWidget(
      new MaterialApp(
        title: 'Pirate app',
        home: new Scaffold(
          appBar: new AppBar(
18
            title: const Text('Home'),
19 20
          ),
          drawer: new Drawer(
21
            child: new ListView(
22
              children: const <Widget>[
23
                AboutListTile(
24
                  applicationVersion: '0.1.2',
25
                  applicationIcon: FlutterLogo(),
26
                  applicationLegalese: 'I am the very model of a modern major general.',
27 28
                  aboutBoxChildren: <Widget>[
                    Text('About box'),
29 30 31 32 33 34 35 36 37 38 39 40 41 42
                  ]
                ),
              ],
            ),
          ),
        ),
      ),
    );

    expect(find.text('About Pirate app'), findsNothing);
    expect(find.text('0.1.2'), findsNothing);
    expect(find.text('About box'), findsNothing);

    await tester.tap(find.byType(IconButton));
43
    await tester.pumpAndSettle(const Duration(milliseconds: 100));
44 45 46 47 48 49

    expect(find.text('About Pirate app'), findsOneWidget);
    expect(find.text('0.1.2'), findsNothing);
    expect(find.text('About box'), findsNothing);

    await tester.tap(find.text('About Pirate app'));
50
    await tester.pumpAndSettle(const Duration(milliseconds: 100));
51 52 53 54 55 56 57

    expect(find.text('About Pirate app'), findsOneWidget);
    expect(find.text('0.1.2'), findsOneWidget);
    expect(find.text('About box'), findsOneWidget);

    LicenseRegistry.addLicense(() {
      return new Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
58
        const LicenseEntryWithLineBreaks(<String>[ 'Pirate package '], 'Pirate license')
59 60 61 62
      ]);
    });

    await tester.tap(find.text('VIEW LICENSES'));
63
    await tester.pumpAndSettle(const Duration(milliseconds: 100));
64 65 66 67

    expect(find.text('Pirate license'), findsOneWidget);
  });

68 69
  testWidgets('About box logic defaults to executable name for app name', (WidgetTester tester) async {
    await tester.pumpWidget(
Hans Muller's avatar
Hans Muller committed
70 71
      new MaterialApp(
        title: 'flutter_tester',
72
        home: const Material(child: AboutListTile()),
73
      ),
74
    );
75
    expect(find.text('About flutter_tester'), findsOneWidget);
76 77
  });

78
  testWidgets('AboutListTile control test', (WidgetTester tester) async {
79
    LicenseRegistry.addLicense(() {
80
      return new Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
81
        const LicenseEntryWithLineBreaks(<String>['AAA'], 'BBB')
82
      ]);
83 84 85 86
    });

    LicenseRegistry.addLicense(() {
      return new Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
87
        const LicenseEntryWithLineBreaks(<String>['Another package'], 'Another license')
88 89 90
      ]);
    });

91 92 93
    await tester.pumpWidget(
      new MaterialApp(
        home: const Center(
94
          child: LicensePage(),
95 96 97
        ),
      ),
    );
98

99 100 101 102
    expect(find.text('AAA'), findsNothing);
    expect(find.text('BBB'), findsNothing);
    expect(find.text('Another package'), findsNothing);
    expect(find.text('Another license'), findsNothing);
103

104
    await tester.pumpAndSettle();
105

106 107 108 109
    expect(find.text('AAA'), findsOneWidget);
    expect(find.text('BBB'), findsOneWidget);
    expect(find.text('Another package'), findsOneWidget);
    expect(find.text('Another license'), findsOneWidget);
110 111
  });
}