grid_test.dart 1.54 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4
// 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.

5
import 'package:flutter/rendering.dart';
6 7 8 9 10 11
import 'package:test/test.dart';

import 'rendering_tester.dart';

void main() {
  test('Basic grid layout test', () {
12
    List<RenderBox> children = <RenderBox>[
13 14 15 16 17 18
      new RenderDecoratedBox(decoration: new BoxDecoration()),
      new RenderDecoratedBox(decoration: new BoxDecoration()),
      new RenderDecoratedBox(decoration: new BoxDecoration()),
      new RenderDecoratedBox(decoration: new BoxDecoration())
    ];

Adam Barth's avatar
Adam Barth committed
19
    RenderGrid grid = new RenderGrid(children: children, maxChildExtent: 100.0);
Hixie's avatar
Hixie committed
20
    layout(grid, constraints: const BoxConstraints(maxWidth: 200.0));
21

22
    children.forEach((RenderBox child) {
23 24 25 26 27 28 29 30 31 32 33
      expect(child.size.width, equals(100.0), reason: "child width");
      expect(child.size.height, equals(100.0), reason: "child height");
    });

    expect(grid.size.width, equals(200.0), reason: "grid width");
    expect(grid.size.height, equals(200.0), reason: "grid height");

    expect(grid.needsLayout, equals(false));
    grid.maxChildExtent = 60.0;
    expect(grid.needsLayout, equals(true));

Hixie's avatar
Hixie committed
34
    pumpFrame();
35

36
    children.forEach((RenderBox child) {
37 38 39 40 41 42 43 44
      expect(child.size.width, equals(50.0), reason: "child width");
      expect(child.size.height, equals(50.0), reason: "child height");
    });

    expect(grid.size.width, equals(200.0), reason: "grid width");
    expect(grid.size.height, equals(50.0), reason: "grid height");
  });
}