absorb_pointer_test.dart 1.8 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 30 31
              absorbing: true,
            ),
          ),
        ],
      ),
    );
    await tester.tap(find.byType(GestureDetector));
    expect(tapped, true);
  });
32 33

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

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

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