semantics_7_test.dart 3.61 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
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

7 8 9 10
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

11
import 'semantics_tester.dart';
12

13
void main() {
14
  testWidgets('Semantics 7 - Merging', (WidgetTester tester) async {
15
    final SemanticsTester semantics = SemanticsTester(tester);
16

17
    String label;
18

19
    label = '1';
20
    await tester.pumpWidget(
21
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
22
        textDirection: TextDirection.ltr,
23
        child: Stack(
Ian Hickson's avatar
Ian Hickson committed
24 25
          fit: StackFit.expand,
          children: <Widget>[
26 27
            MergeSemantics(
              child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
28
                checked: true,
29
                container: true,
30
                child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
31
                  container: true,
32 33
                  label: label,
                ),
Ian Hickson's avatar
Ian Hickson committed
34 35
              ),
            ),
36 37
            MergeSemantics(
              child: Stack(
Ian Hickson's avatar
Ian Hickson committed
38 39
                fit: StackFit.expand,
                children: <Widget>[
40
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
41 42
                    checked: true,
                  ),
43
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
44 45 46 47 48 49 50 51
                    label: label,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
52
    );
53 54

    expect(semantics, hasSemantics(
55
      TestSemantics.root(
56
        children: <TestSemantics>[
57
          TestSemantics.rootChild(
58
            id: 1,
59
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
60
            label: label,
61
            rect: TestSemantics.fullScreen,
62 63
          ),
          // IDs 2 and 3 are used up by the nodes that get merged in
64
          TestSemantics.rootChild(
65
            id: 4,
66
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
67
            label: label,
68
            rect: TestSemantics.fullScreen,
69 70 71
          ),
          // IDs 5 and 6 are used up by the nodes that get merged in
        ],
72
      ),
73
    ));
74

75
    label = '2';
76
    await tester.pumpWidget(
77
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
78
        textDirection: TextDirection.ltr,
79
        child: Stack(
Ian Hickson's avatar
Ian Hickson committed
80 81
          fit: StackFit.expand,
          children: <Widget>[
82 83
            MergeSemantics(
              child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
84
                checked: true,
85
                container: true,
86
                child: Semantics(
Ian Hickson's avatar
Ian Hickson committed
87
                  container: true,
88
                  label: label,
Ian Hickson's avatar
Ian Hickson committed
89 90 91
                ),
              ),
            ),
92 93
            MergeSemantics(
              child: Stack(
Ian Hickson's avatar
Ian Hickson committed
94 95
                fit: StackFit.expand,
                children: <Widget>[
96
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
97 98
                    checked: true,
                  ),
99
                  Semantics(
Ian Hickson's avatar
Ian Hickson committed
100 101 102 103 104 105 106 107
                    label: label,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
108 109
    );

110
    expect(semantics, hasSemantics(
111
      TestSemantics.root(
112
        children: <TestSemantics>[
113
          TestSemantics.rootChild(
114
            id: 1,
115
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
116
            label: label,
117
            rect: TestSemantics.fullScreen,
118 119
          ),
          // IDs 2 and 3 are used up by the nodes that get merged in
120
          TestSemantics.rootChild(
121
            id: 4,
122
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
123
            label: label,
124
            rect: TestSemantics.fullScreen,
125 126 127
          ),
          // IDs 5 and 6 are used up by the nodes that get merged in
        ],
128
      ),
129
    ));
130

131
    semantics.dispose();
132 133
  });
}