semantics_4_test.dart 3.33 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4 5 6 7 8 9 10 11
// 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/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'test_semantics.dart';

void main() {
12
  testWidgets('Semantics 4', (WidgetTester tester) async {
13
    TestSemanticsListener client = new TestSemanticsListener();
Hixie's avatar
Hixie committed
14

15 16 17 18 19 20
    //    O
    //   / \       O=root
    //  L   L      L=node with label
    //     / \     C=node with checked
    //    C   C*   *=node removed next pass
    //
21
    await tester.pumpWidget(
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      new Stack(
        children: <Widget>[
          new Semantics(
            label: 'L1'
          ),
          new Semantics(
            label: 'L2',
            child: new Stack(
              children: <Widget>[
                new Semantics(
                  checked: true
                ),
                new Semantics(
                  checked: false
                )
              ]
Hixie's avatar
Hixie committed
38
            )
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
          )
        ]
      )
    );
    expect(client.updates.length, equals(2));
    expect(client.updates[0].id, equals(0));
    expect(client.updates[0].children.length, equals(2));
    expect(client.updates[0].children[0].id, equals(1));
    expect(client.updates[0].children[0].children.length, equals(0));
    expect(client.updates[0].children[1].id, equals(2));
    expect(client.updates[0].children[1].children.length, equals(2));
    expect(client.updates[0].children[1].children[0].id, equals(3));
    expect(client.updates[0].children[1].children[0].children.length, equals(0));
    expect(client.updates[0].children[1].children[1].id, equals(4));
    expect(client.updates[0].children[1].children[1].children.length, equals(0));
    expect(client.updates[1], isNull);
    client.updates.clear();
Hixie's avatar
Hixie committed
56

57 58 59 60 61
    //    O        O=root
    //   / \       L=node with label
    //  L* LC      C=node with checked
    //             *=node removed next pass
    //
62
    await tester.pumpWidget(
63 64 65 66 67 68 69 70 71 72 73 74 75 76
      new Stack(
        children: <Widget>[
          new Semantics(
            label: 'L1'
          ),
          new Semantics(
            label: 'L2',
            child: new Stack(
              children: <Widget>[
                new Semantics(
                  checked: true
                ),
                new Semantics()
              ]
Hixie's avatar
Hixie committed
77
            )
78 79 80 81 82 83 84 85 86
          )
        ]
      )
    );
    expect(client.updates.length, equals(2));
    expect(client.updates[0].id, equals(2));
    expect(client.updates[0].children.length, equals(0));
    expect(client.updates[1], isNull);
    client.updates.clear();
Hixie's avatar
Hixie committed
87

88 89 90 91
    //             O=root
    //    OLC      L=node with label
    //             C=node with checked
    //
92
    await tester.pumpWidget(
93 94 95 96 97 98 99 100 101 102 103 104
      new Stack(
        children: <Widget>[
          new Semantics(),
          new Semantics(
            label: 'L2',
            child: new Stack(
              children: <Widget>[
                new Semantics(
                  checked: true
                ),
                new Semantics()
              ]
Hixie's avatar
Hixie committed
105
            )
106 107 108 109 110 111 112 113 114
          )
        ]
      )
    );
    expect(client.updates.length, equals(2));
    expect(client.updates[0].id, equals(0));
    expect(client.updates[0].children.length, equals(0));
    expect(client.updates[1], isNull);
    client.updates.clear();
Hixie's avatar
Hixie committed
115 116 117

  });
}