absorb_pointer_test.dart 1.73 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
7

8 9
import 'semantics_tester.dart';

10 11 12 13
void main() {
  testWidgets('AbsorbPointers do not block siblings', (WidgetTester tester) async {
    bool tapped = false;
    await tester.pumpWidget(
14
      Column(
15
        children: <Widget>[
16 17
          Expanded(
            child: GestureDetector(
18 19 20 21
              onTap: () => tapped = true,
            ),
          ),
          const Expanded(
22
            child: AbsorbPointer(),
23 24 25 26 27 28 29
          ),
        ],
      ),
    );
    await tester.tap(find.byType(GestureDetector));
    expect(tapped, true);
  });
30 31

  testWidgets('AbsorbPointers semantics', (WidgetTester tester) async {
32
    final SemanticsTester semantics = SemanticsTester(tester);
33
    await tester.pumpWidget(
34 35
      AbsorbPointer(
        child: Semantics(
36 37 38 39 40
          label: 'test',
          textDirection: TextDirection.ltr,
        ),
      ),
    );
41
    expect(semantics, hasSemantics(TestSemantics.root(), ignoreId: true, ignoreRect: true, ignoreTransform: true));
42 43

    await tester.pumpWidget(
44
      AbsorbPointer(
45
        absorbing: false,
46
        child: Semantics(
47 48 49 50 51 52 53
          label: 'test',
          textDirection: TextDirection.ltr,
        ),
      ),
    );

    expect(semantics, hasSemantics(
54
      TestSemantics.root(
55
        children: <TestSemantics>[
56
          TestSemantics.rootChild(
57 58 59 60 61
            label: 'test',
            textDirection: TextDirection.ltr,
          ),
        ],
      ),
62 63 64 65
      ignoreId: true,
      ignoreRect: true,
      ignoreTransform: true,
    ));
66 67 68
    semantics.dispose();
  });
}