Add tests for gesture_detector.0.dart and gesture_detector.1.dart API examples. (#146724)

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

### Description
- Adds `examples/api/test/widgets/gesture_detector/gesture_detector.0_test.dart` test
- Adds `examples/api/test/widgets/gesture_detector/gesture_detector.1_test.dart` test
This commit is contained in:
Kostia Sokolovskyi 2024-04-20 01:08:04 +02:00 committed by GitHub
parent 24def4d417
commit 142e247fab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 92 additions and 2 deletions

View file

@ -453,8 +453,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart',
'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart',
'examples/api/test/widgets/notification_listener/notification.0_test.dart',
'examples/api/test/widgets/gesture_detector/gesture_detector.1_test.dart',
'examples/api/test/widgets/gesture_detector/gesture_detector.0_test.dart',
'examples/api/test/widgets/editable_text/text_editing_controller.0_test.dart',
'examples/api/test/widgets/editable_text/editable_text.on_changed.0_test.dart',
'examples/api/test/widgets/undo_history/undo_history_controller.0_test.dart',

View file

@ -0,0 +1,40 @@
// 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 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'GestureDetector updates icon color and text on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.GestureDetectorExampleApp(),
);
Icon icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
expect(find.text('TURN LIGHT ON'), findsOneWidget);
expect(icon.color, Colors.black);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
expect(find.text('TURN LIGHT OFF'), findsOneWidget);
expect(icon.color, Colors.yellow.shade600);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
expect(find.text('TURN LIGHT ON'), findsOneWidget);
expect(icon.color, Colors.black);
},
);
}

View file

@ -0,0 +1,52 @@
// 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 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'GestureDetector updates Container color on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.GestureDetectorExampleApp(),
);
Container container = tester.widget(
find.ancestor(
of: find.byType(GestureDetector),
matching: find.byType(Container),
),
);
expect(container.color, Colors.white);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
container = tester.widget(
find.ancestor(
of: find.byType(GestureDetector),
matching: find.byType(Container),
),
);
expect(container.color, Colors.yellow);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
container = tester.widget(
find.ancestor(
of: find.byType(GestureDetector),
matching: find.byType(Container),
),
);
expect(container.color, Colors.white);
},
);
}