semantics_8_test.dart 2.43 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// 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';

9
import 'semantics_tester.dart';
10 11

void main() {
12
  testWidgets('Semantics 8 - Merging with reset', (WidgetTester tester) async {
13
    final SemanticsTester semantics = SemanticsTester(tester);
14

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

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

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

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

    semantics.dispose();
91 92
  });
}