positioned_box_test.dart 1.73 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
import 'package:sky/rendering.dart';
import 'package:test/test.dart';

import 'rendering_tester.dart';

void main() {
  test('RenderPositionedBox expands', () {
    RenderConstrainedBox sizer = new RenderConstrainedBox(
      additionalConstraints: new BoxConstraints.tight(new Size(100.0, 100.0)),
      child: new RenderDecoratedBox(decoration: new BoxDecoration())
    );
    RenderPositionedBox positioner = new RenderPositionedBox(child: sizer);
    layout(positioner, constraints: new BoxConstraints.loose(new Size(200.0, 200.0)));

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

  test('RenderPositionedBox shrink wraps', () {
    RenderConstrainedBox sizer = new RenderConstrainedBox(
      additionalConstraints: new BoxConstraints.tight(new Size(100.0, 100.0)),
      child: new RenderDecoratedBox(decoration: new BoxDecoration())
    );
    RenderPositionedBox positioner = new RenderPositionedBox(child: sizer, shrinkWrap: ShrinkWrap.width);
Hixie's avatar
Hixie committed
25
    layout(positioner, constraints: new BoxConstraints.loose(new Size(200.0, 200.0)));
26 27 28 29 30

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

    positioner.shrinkWrap = ShrinkWrap.height;
Hixie's avatar
Hixie committed
31
    pumpFrame();
32 33 34 35 36

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

    positioner.shrinkWrap = ShrinkWrap.both;
Hixie's avatar
Hixie committed
37
    pumpFrame();
38 39 40 41 42

    expect(positioner.size.width, equals(100.0), reason: "positioner width");
    expect(positioner.size.height, equals(100.0), reason: "positioner height");
  });
}