drawer_test.dart 1.73 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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';

void main() {
  testWidgets('Drawer control test', (WidgetTester tester) async {
10
    const Key containerKey = const Key('container');
11

12
    await tester.pumpWidget(
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
      new MaterialApp(
        home: new Scaffold(
          drawer: new Drawer(
            child: new ListView(
              children: <Widget>[
                new DrawerHeader(
                  child: new Container(
                    key: containerKey,
                    child: const Text('header'),
                  ),
                ),
                const ListTile(
                  leading: const Icon(Icons.archive),
                  title: const Text('Archive'),
                ),
              ],
            ),
          ),
        ),
      ),
33 34 35
    );

    expect(find.text('Archive'), findsNothing);
36
    final ScaffoldState state = tester.firstState(find.byType(Scaffold));
37
    state.openDrawer();
38

39 40 41
    await tester.pump();
    await tester.pump(const Duration(seconds: 1));
    expect(find.text('Archive'), findsOneWidget);
42 43 44 45 46 47 48 49 50

    RenderBox box = tester.renderObject(find.byType(DrawerHeader));
    expect(box.size.height, equals(160.0 + 8.0 + 1.0)); // height + bottom margin + bottom edge

    final double drawerWidth = box.size.width;
    final double drawerHeight = box.size.height;

    box = tester.renderObject(find.byKey(containerKey));
    expect(box.size.width, equals(drawerWidth - 2 * 16.0));
51
    expect(box.size.height, equals(drawerHeight - 2 * 16.0));
52 53

    expect(find.text('header'), findsOneWidget);
54 55
  });
}