semantics_8_test.dart 2.52 KB
Newer Older
1 2 3 4
// 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.

5
import 'dart:ui' show SemanticsFlag;
6

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 = new SemanticsTester(tester);
16

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

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

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

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