simple_semantics_test.dart 2.6 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
import 'dart:ui';

9 10 11 12 13 14 15 16 17
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'semantics_tester.dart';

void main() {
  testWidgets('Simple tree is simple', (WidgetTester tester) async {
18
    final SemanticsTester semantics = SemanticsTester(tester);
19 20 21

    await tester.pumpWidget(
      const Center(
22
          child: Text('Hello!', textDirection: TextDirection.ltr),
23 24 25
      ),
    );

26
    expect(semantics, hasSemantics(TestSemantics.root(
27
      children: <TestSemantics>[
28
        TestSemantics.rootChild(
29 30 31
          id: 1,
          label: 'Hello!',
          textDirection: TextDirection.ltr,
Dan Field's avatar
Dan Field committed
32
          rect: const Rect.fromLTRB(0.0, 0.0, 84.0, 14.0),
33
          transform: Matrix4.translationValues(358.0, 293.0, 0.0),
34
        ),
35 36 37 38
      ],
    )));

    semantics.dispose();
39
  });
40 41

  testWidgets('Simple tree is simple - material', (WidgetTester tester) async {
42
    final SemanticsTester semantics = SemanticsTester(tester);
43 44

    // Not using Text widget because of https://github.com/flutter/flutter/issues/12357.
45 46 47
    await tester.pumpWidget(MaterialApp(
      home: Center(
        child: Semantics(
48
          label: 'Hello!',
49
          child: const SizedBox(
50 51 52 53 54 55 56
            width: 10.0,
            height: 10.0,
          ),
        ),
      ),
    ));

57
    expect(semantics, hasSemantics(TestSemantics.root(
58
      children: <TestSemantics>[
59
        TestSemantics.rootChild(
60
          id: 1,
Dan Field's avatar
Dan Field committed
61
          rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
62
          children: <TestSemantics>[
63
            TestSemantics(
64
              id: 2,
Dan Field's avatar
Dan Field committed
65
              rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
66
              children: <TestSemantics>[
67
                TestSemantics(
68
                  id: 3,
69 70 71 72 73 74 75 76 77 78 79
                  rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
                      id: 4,
                      label: 'Hello!',
                      textDirection: TextDirection.ltr,
                      rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
                      transform: Matrix4.translationValues(395.0, 295.0, 0.0),
                    ),
                  ],
80
                ),
81 82
              ],
            ),
83 84
          ],
        ),
85 86 87 88
      ],
    )));

    semantics.dispose();
89
  });
90
}