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
// 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
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

10 11
import 'semantics_tester.dart';

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

    await tester.tap(find.byType(GestureDetector));
    expect(tapped, true);
  });
35 36

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

    await tester.pumpWidget(
51
      AbsorbPointer(
52
        absorbing: false,
53
        child: Semantics(
54 55 56 57 58 59 60
          label: 'test',
          textDirection: TextDirection.ltr,
        ),
      ),
    );

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