stack_test.dart 2.5 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
import 'package:test/test.dart';

8
import 'rendering_tester.dart';
9 10 11

void main() {
  test('Stack can layout with top, right, bottom, left 0.0', () {
12
    final RenderBox size = new RenderConstrainedBox(
13 14
      additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
    );
15

16
    final RenderBox red = new RenderDecoratedBox(
17
      decoration: const BoxDecoration(
18
        color: const Color(0xFFFF0000),
19
      ),
20 21
      child: size
    );
22

23
    final RenderBox green = new RenderDecoratedBox(
24
      decoration: const BoxDecoration(
25 26
        color: const Color(0xFFFF0000),
      ),
27
    );
28

29 30 31 32
    final RenderBox stack = new RenderStack(
      textDirection: TextDirection.ltr,
      children: <RenderBox>[red, green],
    );
33
    final StackParentData greenParentData = green.parentData;
Hixie's avatar
Hixie committed
34
    greenParentData
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      ..top = 0.0
      ..right = 0.0
      ..bottom = 0.0
      ..left = 0.0;

    layout(stack, constraints: const BoxConstraints());

    expect(stack.size.width, equals(100.0));
    expect(stack.size.height, equals(100.0));

    expect(red.size.width, equals(100.0));
    expect(red.size.height, equals(100.0));

    expect(green.size.width, equals(100.0));
    expect(green.size.height, equals(100.0));
  });
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65

  group('RenderIndexedStack', () {
    test('visitChildrenForSemantics only visits displayed child', () {
      final RenderBox child1 = new RenderConstrainedBox(
          additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
      );
      final RenderBox child2 = new RenderConstrainedBox(
          additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
      );
      final RenderBox child3 = new RenderConstrainedBox(
          additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
      );
      final RenderBox stack = new RenderIndexedStack(
          index: 1,
66 67
          textDirection: TextDirection.ltr,
          children: <RenderBox>[child1, child2, child3],
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
      );

      final List<RenderObject> vistedChildren = <RenderObject>[];
      final RenderObjectVisitor visitor = (RenderObject child) {
        vistedChildren.add(child);
      };

      stack.visitChildrenForSemantics(visitor);

      expect(vistedChildren, hasLength(1));
      expect(vistedChildren.first, child2);
    });

  });

83
  // More tests in ../widgets/stack_test.dart
84
}