drop_down_test.dart 1.88 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2015 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_test/flutter_test.dart';
import 'package:flutter/material.dart';

void main() {
9
  testWidgets('Drop down screen edges', (WidgetTester tester) async {
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    int value = 4;
    List<DropDownMenuItem<int>> items = <DropDownMenuItem<int>>[];
    for (int i = 0; i < 20; ++i)
      items.add(new DropDownMenuItem<int>(value: i, child: new Text('$i')));

    void handleChanged(int newValue) {
      value = newValue;
    }

    DropDownButton<int> button = new DropDownButton<int>(
      value: value,
      onChanged: handleChanged,
      items: items
    );

25
    await tester.pumpWidget(
26 27 28 29
      new MaterialApp(
        home: new Material(
          child: new Align(
            alignment: FractionalOffset.topCenter,
30
            child: button
31 32 33 34 35
          )
        )
      )
    );

36 37 38
    await tester.tap(find.text('4'));
    await tester.pump();
    await tester.pump(const Duration(seconds: 1)); // finish the menu animation
39

40 41
    // We should have two copies of item 5, one in the menu and one in the
    // button itself.
42
    expect(tester.elementList(find.text('5')), hasLength(2));
43 44 45

    // We should only have one copy of item 19, which is in the button itself.
    // The copy in the menu shouldn't be in the tree because it's off-screen.
46
    expect(tester.elementList(find.text('19')), hasLength(1));
47

48
    expect(value, 4);
49
    await tester.tap(find.byConfig(button));
50 51
    expect(value, 4);
    await tester.idle(); // this waits for the route's completer to complete, which calls handleChanged
52
    expect(value, 4);
53 54 55

    // TODO(abarth): Remove these calls to pump once navigator cleans up its
    // pop transitions.
56 57
    await tester.pump();
    await tester.pump(const Duration(seconds: 1)); // finish the menu animation
58 59 60

  });
}