Skip to content

Commit 142e247

Browse files
authored
Add tests for gesture_detector.0.dart and gesture_detector.1.dart API examples. (#146724)
This PR contributes to flutter/flutter#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
1 parent 24def4d commit 142e247

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ final Set<String> _knownMissingTests = <String>{
453453
'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart',
454454
'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart',
455455
'examples/api/test/widgets/notification_listener/notification.0_test.dart',
456-
'examples/api/test/widgets/gesture_detector/gesture_detector.1_test.dart',
457-
'examples/api/test/widgets/gesture_detector/gesture_detector.0_test.dart',
458456
'examples/api/test/widgets/editable_text/text_editing_controller.0_test.dart',
459457
'examples/api/test/widgets/editable_text/editable_text.on_changed.0_test.dart',
460458
'examples/api/test/widgets/undo_history/undo_history_controller.0_test.dart',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.0.dart'
7+
as example;
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
testWidgets(
12+
'GestureDetector updates icon color and text on tap',
13+
(WidgetTester tester) async {
14+
await tester.pumpWidget(
15+
const example.GestureDetectorExampleApp(),
16+
);
17+
18+
Icon icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
19+
20+
expect(find.text('TURN LIGHT ON'), findsOneWidget);
21+
expect(icon.color, Colors.black);
22+
23+
await tester.tap(find.byType(GestureDetector));
24+
await tester.pump();
25+
26+
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
27+
28+
expect(find.text('TURN LIGHT OFF'), findsOneWidget);
29+
expect(icon.color, Colors.yellow.shade600);
30+
31+
await tester.tap(find.byType(GestureDetector));
32+
await tester.pump();
33+
34+
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
35+
36+
expect(find.text('TURN LIGHT ON'), findsOneWidget);
37+
expect(icon.color, Colors.black);
38+
},
39+
);
40+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.1.dart'
7+
as example;
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
testWidgets(
12+
'GestureDetector updates Container color on tap',
13+
(WidgetTester tester) async {
14+
await tester.pumpWidget(
15+
const example.GestureDetectorExampleApp(),
16+
);
17+
18+
Container container = tester.widget(
19+
find.ancestor(
20+
of: find.byType(GestureDetector),
21+
matching: find.byType(Container),
22+
),
23+
);
24+
25+
expect(container.color, Colors.white);
26+
27+
await tester.tap(find.byType(GestureDetector));
28+
await tester.pump();
29+
30+
container = tester.widget(
31+
find.ancestor(
32+
of: find.byType(GestureDetector),
33+
matching: find.byType(Container),
34+
),
35+
);
36+
37+
expect(container.color, Colors.yellow);
38+
39+
await tester.tap(find.byType(GestureDetector));
40+
await tester.pump();
41+
42+
container = tester.widget(
43+
find.ancestor(
44+
of: find.byType(GestureDetector),
45+
matching: find.byType(Container),
46+
),
47+
);
48+
49+
expect(container.color, Colors.white);
50+
},
51+
);
52+
}

0 commit comments

Comments
 (0)