traversal_order_test.dart 3.29 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 11 12 13 14
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import '../widgets/semantics_tester.dart';

void main() {
  testWidgets('Traversal order handles touching elements', (WidgetTester tester) async {
15
    final SemanticsTester semantics = SemanticsTester(tester);
16
    await tester.pumpWidget(
17 18 19
      MaterialApp(
        home: Column(
          children: List<Widget>.generate(3, (int column) {
20 21 22 23 24 25 26 27 28 29 30 31 32
            return Row(
              children: List<Widget>.generate(3, (int row) {
                return Semantics(
                  child: SizedBox(
                    width: 50.0,
                    height: 50.0,
                    child: Text('$column - $row'),
                  ),
                );
              }),
            );
          }),
        ),
33
      ),
34
    );
35

36
    final TestSemantics expected = TestSemantics.root(
37
      children: <TestSemantics>[
38
        TestSemantics(
39 40 41
          id: 1,
          textDirection: TextDirection.ltr,
          children: <TestSemantics>[
42
            TestSemantics(
43 44
              id: 2,
              children: <TestSemantics>[
45
                TestSemantics(
46
                  id: 3,
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
                      id: 4,
                      label: '0 - 0',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 5,
                      label: '0 - 1',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 6,
                      label: '0 - 2',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 7,
                      label: '1 - 0',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 8,
                      label: '1 - 1',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 9,
                      label: '1 - 2',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 10,
                      label: '2 - 0',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 11,
                      label: '2 - 1',
                      textDirection: TextDirection.ltr,
                    ),
                    TestSemantics(
                      id: 12,
                      label: '2 - 2',
                      textDirection: TextDirection.ltr,
                    ),
                  ],
95 96 97 98 99 100 101 102 103 104 105
                ),
              ],
            ),
          ],
        ),
      ],
    );
    expect(semantics, hasSemantics(expected, ignoreRect: true, ignoreTransform: true));
    semantics.dispose();
  });
}