semantics_8_test.dart 2.45 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 8 - Merging with reset', (WidgetTester tester) async {
15
    final SemanticsTester semantics = SemanticsTester(tester);
16

17
    await tester.pumpWidget(
18 19
      MergeSemantics(
        child: Semantics(
20
          container: true,
21
          child: Semantics(
22
            container: true,
23
            child: Stack(
24
              textDirection: TextDirection.ltr,
25
              children: <Widget>[
26
                Semantics(
Ian Hickson's avatar
Ian Hickson committed
27
                  checked: true,
28
                ),
29
                Semantics(
Ian Hickson's avatar
Ian Hickson committed
30 31
                  label: 'label',
                  textDirection: TextDirection.ltr,
32 33 34 35 36
                ),
              ],
            ),
          ),
        ),
37
      ),
38
    );
39 40

    expect(semantics, hasSemantics(
41
      TestSemantics.root(
42
        children: <TestSemantics>[
43
          TestSemantics.rootChild(
44
            id: 1,
45
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
46 47 48
            label: 'label',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
49
          ),
50 51
        ],
      ),
52
    ));
53

54
    // switch the order of the inner Semantics node to trigger a reset
55
    await tester.pumpWidget(
56 57
      MergeSemantics(
        child: Semantics(
58
          container: true,
59
          child: Semantics(
60
            container: true,
61
            child: Stack(
62
              textDirection: TextDirection.ltr,
63
              children: <Widget>[
64
                Semantics(
Ian Hickson's avatar
Ian Hickson committed
65 66
                  label: 'label',
                  textDirection: TextDirection.ltr,
67
                ),
68
                Semantics(
69
                  checked: true
70 71 72 73 74
                ),
              ],
            ),
          ),
        ),
75
      ),
76
    );
77 78

    expect(semantics, hasSemantics(
79
      TestSemantics.root(
80
        children: <TestSemantics>[
81
          TestSemantics.rootChild(
82
            id: 1,
83
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
84 85 86
            label: 'label',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
87
          ),
88 89
        ],
      ),
90 91 92
    ));

    semantics.dispose();
93 94
  });
}