Add tests for material_state_mouse_cursor.0.dart API example. (#145987)

This PR contributes to https://github.com/flutter/flutter/issues/130459

### Description
- Updates `examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart` to allow enable/disable `ListTile` in tests;
- Adds tests for `examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart`.
This commit is contained in:
Kostia Sokolovskyi
2024-04-03 04:39:46 +02:00
committed by GitHub
parent 69db714fbb
commit e6f078fff5
3 changed files with 92 additions and 7 deletions

View File

@@ -0,0 +1,77 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_api_samples/material/material_state/material_state_mouse_cursor.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'MaterialStateMouseCursorExampleApp displays ListTile',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.MaterialStateMouseCursorExampleApp(),
);
expect(find.byType(ListTile), findsOneWidget);
expect(find.text('ListTile'), findsOneWidget);
},
);
testWidgets(
'ListTile displays correct mouse cursor when enabled',
(WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: example.MaterialStateMouseCursorExample(enabled: true),
),
),
);
final TestGesture gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse,
);
await gesture.addPointer(
location: tester.getCenter(find.byType(ListTile)),
);
addTearDown(gesture.removePointer);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.click,
);
},
);
testWidgets(
'ListTile displays correct mouse cursor when disabled',
(WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: example.MaterialStateMouseCursorExample(enabled: false),
),
),
);
final TestGesture gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse,
);
await gesture.addPointer(
location: tester.getCenter(find.byType(ListTile)),
);
addTearDown(gesture.removePointer);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.forbidden,
);
},
);
}