traversal_order_test.dart 3.24 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 9 10 11
// 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_test/flutter_test.dart';

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

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

33
    final TestSemantics expected = TestSemantics.root(
34
      children: <TestSemantics>[
35
        TestSemantics(
36 37 38
          id: 1,
          textDirection: TextDirection.ltr,
          children: <TestSemantics>[
39
            TestSemantics(
40 41
              id: 2,
              children: <TestSemantics>[
42
                TestSemantics(
43
                  id: 3,
44 45 46 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
                  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,
                    ),
                  ],
92 93 94 95 96 97 98 99 100 101 102
                ),
              ],
            ),
          ],
        ),
      ],
    );
    expect(semantics, hasSemantics(expected, ignoreRect: true, ignoreTransform: true));
    semantics.dispose();
  });
}