semantics_8_test.dart 2.49 KB
Newer Older
1 2 3 4 5 6 7 8
// 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';

9
import 'semantics_tester.dart';
10 11

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

15
    await tester.pumpWidget(
16 17 18
      new MergeSemantics(
        child: new Semantics(
          container: true,
19 20
          child: new Semantics(
            container: true,
21
            child: new Stack(
22
              textDirection: TextDirection.ltr,
23
              children: <Widget>[
24
                new Semantics(
Ian Hickson's avatar
Ian Hickson committed
25
                  checked: true,
26
                ),
27
                new 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
      new TestSemantics.root(
40 41
        children: <TestSemantics>[
          new TestSemantics.rootChild(
42
            id: 1,
43
            flags: SemanticsFlag.hasCheckedState.index | SemanticsFlag.isChecked.index,
44 45 46 47 48
            label: 'label',
            textDirection: TextDirection.ltr,
            rect: TestSemantics.fullScreen,
          )
        ]
49 50
      )
    ));
51

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

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

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