semantics_4_test.dart 4.35 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hixie's avatar
Hixie committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

Hixie's avatar
Hixie committed
7 8
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
9
import 'package:flutter/rendering.dart';
Hixie's avatar
Hixie committed
10 11
import 'package:flutter_test/flutter_test.dart';

12
import 'semantics_tester.dart';
Hixie's avatar
Hixie committed
13 14

void main() {
15
  testWidgets('Semantics 4', (WidgetTester tester) async {
16
    final SemanticsTester semantics = SemanticsTester(tester);
Hixie's avatar
Hixie committed
17

18 19 20 21 22 23
    //    O
    //   / \       O=root
    //  L   L      L=node with label
    //     / \     C=node with checked
    //    C   C*   *=node removed next pass
    //
24
    await tester.pumpWidget(Directionality(
Ian Hickson's avatar
Ian Hickson committed
25
      textDirection: TextDirection.ltr,
26
      child: Stack(
27
        fit: StackFit.expand,
28
        children: <Widget>[
29
          Semantics(
30
            container: true,
31
            label: 'L1',
32
          ),
33
          Semantics(
34
            label: 'L2',
35
            container: true,
36
            child: Stack(
37
              fit: StackFit.expand,
38
              children: <Widget>[
39
                Semantics(
40
                  checked: true,
41
                ),
42
                Semantics(
43 44 45 46 47 48 49
                  checked: false,
                ),
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
50
    ));
51 52

    expect(semantics, hasSemantics(
53
      TestSemantics.root(
54
        children: <TestSemantics>[
55
          TestSemantics.rootChild(
56
            id: 1,
57
            label: 'L1',
58
            rect: TestSemantics.fullScreen,
59
          ),
60
          TestSemantics.rootChild(
61
            id: 2,
62
            label: 'L2',
63
            rect: TestSemantics.fullScreen,
64
            children: <TestSemantics>[
65
              TestSemantics(
66
                id: 3,
67
                flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
68
                rect: TestSemantics.fullScreen,
69
              ),
70
              TestSemantics(
71
                id: 4,
72
                flags: SemanticsFlag.hasCheckedState.index,
73
                rect: TestSemantics.fullScreen,
74
              ),
75
            ],
76 77
          ),
        ],
78
      ),
79
    ));
Hixie's avatar
Hixie committed
80

81 82 83 84 85
    //    O        O=root
    //   / \       L=node with label
    //  L* LC      C=node with checked
    //             *=node removed next pass
    //
86
    await tester.pumpWidget(Directionality(
Ian Hickson's avatar
Ian Hickson committed
87
      textDirection: TextDirection.ltr,
88
      child: Stack(
89
        fit: StackFit.expand,
90
        children: <Widget>[
91
          Semantics(
92
            label: 'L1',
93
            container: true,
94
          ),
95
          Semantics(
96
            label: 'L2',
97
            container: true,
98
            child: Stack(
99
              fit: StackFit.expand,
100
              children: <Widget>[
101
                Semantics(
102
                  checked: true,
103
                ),
104
                Semantics(),
105 106 107 108 109
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
110
    ));
111 112

    expect(semantics, hasSemantics(
113
      TestSemantics.root(
114
        children: <TestSemantics>[
115
          TestSemantics.rootChild(
116
            id: 1,
117
            label: 'L1',
118
            rect: TestSemantics.fullScreen,
119
          ),
120
          TestSemantics.rootChild(
121
            id: 2,
122
            label: 'L2',
123
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
124
            rect: TestSemantics.fullScreen,
125 126
          ),
        ],
127
      ),
128
    ));
Hixie's avatar
Hixie committed
129

130 131 132 133
    //             O=root
    //    OLC      L=node with label
    //             C=node with checked
    //
134
    await tester.pumpWidget(Directionality(
Ian Hickson's avatar
Ian Hickson committed
135
      textDirection: TextDirection.ltr,
136
      child: Stack(
137
        fit: StackFit.expand,
138
        children: <Widget>[
139 140
          Semantics(),
          Semantics(
141
            label: 'L2',
142
            container: true,
143
            child: Stack(
144
              fit: StackFit.expand,
145
              children: <Widget>[
146
                Semantics(
147
                  checked: true,
148
                ),
149
                Semantics(),
150 151 152 153 154
              ],
            ),
          ),
        ],
      ),
Ian Hickson's avatar
Ian Hickson committed
155
    ));
156 157

    expect(semantics, hasSemantics(
158
      TestSemantics.root(
159
        children: <TestSemantics>[
160
          TestSemantics.rootChild(
161
            id: 2,
162
            label: 'L2',
163
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
164 165 166
            rect: TestSemantics.fullScreen,
          ),
        ],
167
      ),
168 169 170
    ));

    semantics.dispose();
Hixie's avatar
Hixie committed
171 172
  });
}