expansion_panel_test.dart 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 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
// 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('ExpansionPanelList test', (WidgetTester tester) async {
    int index;
    bool isExpanded;

    await tester.pumpWidget(
      new ScrollableViewport(
        child: new ExpansionPanelList(
          expansionCallback: (int _index, bool _isExpanded) {
            index = _index;
            isExpanded = _isExpanded;
          },
          children: <ExpansionPanel>[
            new ExpansionPanel(
              headerBuilder: (BuildContext context, bool isExpanded) {
                return new Text(isExpanded ? 'B' : 'A');
              },
              body: new SizedBox(height: 100.0)
            )
          ]
        )
      )
    );

    expect(find.text('A'), findsOneWidget);
    expect(find.text('B'), findsNothing);
    RenderBox box = tester.renderObject(find.byType(ExpansionPanelList));
    double oldHeight = box.size.height;
    expect(find.byType(ExpandIcon), findsOneWidget);
    await tester.tap(find.byType(ExpandIcon));
    expect(index, 0);
    expect(isExpanded, isFalse);
    box = tester.renderObject(find.byType(ExpansionPanelList));
    expect(box.size.height, equals(oldHeight));

43
    // now expand the child panel
44 45 46 47 48 49 50 51 52 53 54 55 56
    await tester.pumpWidget(
      new ScrollableViewport(
        child: new ExpansionPanelList(
          expansionCallback: (int _index, bool _isExpanded) {
            index = _index;
            isExpanded = _isExpanded;
          },
          children: <ExpansionPanel>[
            new ExpansionPanel(
              headerBuilder: (BuildContext context, bool isExpanded) {
                return new Text(isExpanded ? 'B' : 'A');
              },
              body: new SizedBox(height: 100.0),
57
              isExpanded: true // this is the addition
58 59 60 61 62
            )
          ]
        )
      )
    );
63

64 65
    await tester.pump(const Duration(milliseconds: 200));

66

67 68 69 70 71 72
    expect(find.text('A'), findsNothing);
    expect(find.text('B'), findsOneWidget);
    box = tester.renderObject(find.byType(ExpansionPanelList));
    expect(box.size.height - oldHeight, greaterThanOrEqualTo(100.0)); // 100 + some margin
  });
}