user_accounts_drawer_header_test.dart 2.5 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/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
10
  testWidgets('UserAccountsDrawerHeader test', (WidgetTester tester) async {
11 12 13 14 15 16 17 18 19 20 21 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 68 69 70 71 72 73 74
    final Key avatarA = new Key('A');
    final Key avatarC = new Key('C');
    final Key avatarD = new Key('D');

    await tester.pumpWidget(
      new Material(
        child: new UserAccountsDrawerHeader(
          currentAccountPicture: new CircleAvatar(
            key: avatarA,
            child: new Text('A')
          ),
          otherAccountsPictures: <Widget>[
            new CircleAvatar(
              child: new Text('B')
            ),
            new CircleAvatar(
              key: avatarC,
              child: new Text('C')
            ),
            new CircleAvatar(
              key: avatarD,
              child: new Text('D')
            ),
            new CircleAvatar(
              child: new Text('E')
            )
          ],
          accountName: new Text("name"),
          accountEmail: new Text("email")
        )
      )
    );

    expect(find.text('A'), findsOneWidget);
    expect(find.text('B'), findsOneWidget);
    expect(find.text('C'), findsOneWidget);
    expect(find.text('D'), findsOneWidget);
    expect(find.text('E'), findsNothing);

    expect(find.text('name'), findsOneWidget);
    expect(find.text('email'), findsOneWidget);

    RenderBox box = tester.renderObject(find.byKey(avatarA));
    expect(box.size.width, equals(72.0));
    expect(box.size.height, equals(72.0));

    box = tester.renderObject(find.byKey(avatarC));
    expect(box.size.width, equals(40.0));
    expect(box.size.height, equals(40.0));

    Point topLeft = tester.getTopLeft(find.byType(UserAccountsDrawerHeader));
    Point topRight = tester.getTopRight(find.byType(UserAccountsDrawerHeader));

    Point avatarATopLeft = tester.getTopLeft(find.byKey(avatarA));
    Point avatarDTopRight = tester.getTopRight(find.byKey(avatarD));
    Point avatarCTopRight = tester.getTopRight(find.byKey(avatarC));

    expect(avatarATopLeft.x - topLeft.x, equals(16.0));
    expect(avatarATopLeft.y - topLeft.y, equals(16.0));
    expect(topRight.x - avatarDTopRight.x, equals(16.0));
    expect(avatarDTopRight.y - topRight.y, equals(16.0));
    expect(avatarDTopRight.x - avatarCTopRight.x, equals(40.0 + 16.0)); // size + space between
  });
}