about_test.dart 3.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 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() {
  testWidgets('AboutDrawerItem control test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new MaterialApp(
        title: 'Pirate app',
        home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Home'),
          ),
          drawer: new Drawer(
21
            child: new ListView(
22 23 24 25 26 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
              children: <Widget>[
                new AboutDrawerItem(
                  applicationVersion: '0.1.2',
                  applicationIcon: new FlutterLogo(),
                  applicationLegalese: 'I am the very model of a modern major general.',
                  aboutBoxChildren: <Widget>[
                    new Text('About box'),
                  ]
                ),
              ],
            ),
          ),
        ),
      ),
    );

    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));
    await tester.pumpUntilNoTransientCallbacks(const Duration(milliseconds: 100));

    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'));
    await tester.pumpUntilNoTransientCallbacks(const Duration(milliseconds: 100));

    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>[
        new LicenseEntryWithLineBreaks(<String>[ 'Pirate package '], 'Pirate license')
      ]);
    });

    await tester.tap(find.text('VIEW LICENSES'));
    await tester.pumpUntilNoTransientCallbacks(const Duration(milliseconds: 100));

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

68 69 70 71 72 73 74
  testWidgets('About box logic defaults to executable name for app name', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Material(child: new AboutDrawerItem()),
    );
    expect(find.text('About sky_shell'), findsOneWidget);
  });

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  testWidgets('AboutDrawerItem control test', (WidgetTester tester) async {
    List<String> log = <String>[];

    Future<Null> licenseFuture;
    LicenseRegistry.addLicense(() {
      log.add('license1');
      licenseFuture = tester.pumpWidget(new Container());
      return new Stream<LicenseEntry>.fromIterable(<LicenseEntry>[]);
    });

    LicenseRegistry.addLicense(() {
      log.add('license2');
      return new Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
        new LicenseEntryWithLineBreaks(<String>[ 'Another package '], 'Another license')
      ]);
    });

    await tester.pumpWidget(new Center(
      child: new LicensePage()
    ));

    expect(licenseFuture, isNotNull);
    await licenseFuture;

    // We should not hit an exception here.
    await tester.idle();

    expect(log, equals(<String>['license1', 'license2']));
  });
}