drawer_demo_test.dart 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2017 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_gallery/demo/material/drawer_demo.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
10
  testWidgets('Drawer header does not scroll', (WidgetTester tester) async {
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    await tester.pumpWidget(new MaterialApp(
      theme: new ThemeData(platform: TargetPlatform.iOS),
      home: new DrawerDemo(),
    ));

    await tester.tap(find.text('Tap here to open the drawer'));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 500));

    expect(tester.getTopLeft(find.byType(UserAccountsDrawerHeader)).dy, 0.0);
    final double initialTopItemSaneY = tester.getTopLeft(find.text('Drawer item A')).dy;
    expect(initialTopItemSaneY, greaterThan(0.0));

    await tester.drag(find.text('Drawer item B'), const Offset(0.0, 400.0));
    await tester.pump();

    expect(tester.getTopLeft(find.byType(UserAccountsDrawerHeader)).dy, 0.0);
    expect(tester.getTopLeft(find.text('Drawer item A')).dy, greaterThan(initialTopItemSaneY));
    expect(tester.getTopLeft(find.text('Drawer item A')).dy, lessThanOrEqualTo(initialTopItemSaneY + 400.0));
  });
}